CuraSplashScreen.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Uranium is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import Qt, QCoreApplication, QTimer
  4. from PyQt5.QtGui import QPixmap, QColor, QFont, QPen, QPainter
  5. from PyQt5.QtWidgets import QSplashScreen
  6. from UM.Resources import Resources
  7. from UM.Application import Application
  8. class CuraSplashScreen(QSplashScreen):
  9. def __init__(self):
  10. super().__init__()
  11. self._scale = 0.7
  12. splash_image = QPixmap(Resources.getPath(Resources.Images, "cura.png"))
  13. self.setPixmap(splash_image)
  14. self._current_message = ""
  15. self._loading_image_rotation_angle = 0
  16. self._to_stop = False
  17. self._change_timer = QTimer()
  18. self._change_timer.setInterval(50)
  19. self._change_timer.setSingleShot(False)
  20. self._change_timer.timeout.connect(self.updateLoadingImage)
  21. def show(self):
  22. super().show()
  23. self._change_timer.start()
  24. def updateLoadingImage(self):
  25. if self._to_stop:
  26. return
  27. self._loading_image_rotation_angle -= 10
  28. self.repaint()
  29. # Override the mousePressEvent so the splashscreen doesn't disappear when clicked
  30. def mousePressEvent(self, mouse_event):
  31. pass
  32. def drawContents(self, painter):
  33. if self._to_stop:
  34. return
  35. painter.save()
  36. painter.setPen(QColor(255, 255, 255, 255))
  37. painter.setRenderHint(QPainter.Antialiasing)
  38. painter.setRenderHint(QPainter.Antialiasing, True)
  39. version = Application.getInstance().getVersion().split("-")
  40. buildtype = Application.getInstance().getBuildType()
  41. if buildtype:
  42. version[0] += " (%s)" % buildtype
  43. # draw version text
  44. font = QFont() # Using system-default font here
  45. font.setPixelSize(37)
  46. painter.setFont(font)
  47. painter.drawText(215, 66, 330 * self._scale, 230 * self._scale, Qt.AlignLeft | Qt.AlignTop, version[0])
  48. if len(version) > 1:
  49. font.setPixelSize(16)
  50. painter.setFont(font)
  51. painter.setPen(QColor(200, 200, 200, 255))
  52. painter.drawText(247, 105, 330 * self._scale, 255 * self._scale, Qt.AlignLeft | Qt.AlignTop, version[1])
  53. painter.setPen(QColor(255, 255, 255, 255))
  54. # draw the loading image
  55. pen = QPen()
  56. pen.setWidth(6 * self._scale)
  57. pen.setColor(QColor(32, 166, 219, 255))
  58. painter.setPen(pen)
  59. painter.drawArc(60, 150, 32 * self._scale, 32 * self._scale, self._loading_image_rotation_angle * 16, 300 * 16)
  60. # draw message text
  61. if self._current_message:
  62. font = QFont() # Using system-default font here
  63. font.setPixelSize(13)
  64. pen = QPen()
  65. pen.setColor(QColor(255, 255, 255, 255))
  66. painter.setPen(pen)
  67. painter.setFont(font)
  68. painter.drawText(100, 128, 170, 64,
  69. Qt.AlignLeft | Qt.AlignVCenter | Qt.TextWordWrap,
  70. self._current_message)
  71. painter.restore()
  72. super().drawContents(painter)
  73. def showMessage(self, message, *args, **kwargs):
  74. if self._to_stop:
  75. return
  76. self._current_message = message
  77. self.messageChanged.emit(message)
  78. QCoreApplication.flush()
  79. self.repaint()
  80. def close(self):
  81. # set stop flags
  82. self._to_stop = True
  83. self._change_timer.stop()
  84. super().close()