CuraSplashScreen.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright (c) 2020 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. from cura import ApplicationMetadata
  9. import time
  10. class CuraSplashScreen(QSplashScreen):
  11. def __init__(self):
  12. super().__init__()
  13. self._scale = 0.7
  14. self._version_y_offset = 0 # when extra visual elements are in the background image, move version text down
  15. if ApplicationMetadata.IsAlternateVersion:
  16. splash_image = QPixmap(Resources.getPath(Resources.Images, "cura_wip.png"))
  17. elif ApplicationMetadata.IsEnterpriseVersion:
  18. splash_image = QPixmap(Resources.getPath(Resources.Images, "cura_enterprise.png"))
  19. self._version_y_offset = 26
  20. else:
  21. splash_image = QPixmap(Resources.getPath(Resources.Images, "cura.png"))
  22. self.setPixmap(splash_image)
  23. self._current_message = ""
  24. self._loading_image_rotation_angle = 0
  25. self._to_stop = False
  26. self._change_timer = QTimer()
  27. self._change_timer.setInterval(50)
  28. self._change_timer.setSingleShot(False)
  29. self._change_timer.timeout.connect(self.updateLoadingImage)
  30. self._last_update_time = None
  31. def show(self):
  32. super().show()
  33. self._last_update_time = time.time()
  34. self._change_timer.start()
  35. def updateLoadingImage(self):
  36. if self._to_stop:
  37. return
  38. time_since_last_update = time.time() - self._last_update_time
  39. self._last_update_time = time.time()
  40. # Since we don't know how much time actually passed, check how many intervals of 50 we had.
  41. self._loading_image_rotation_angle -= 10 * (time_since_last_update * 1000 / 50)
  42. self.repaint()
  43. # Override the mousePressEvent so the splashscreen doesn't disappear when clicked
  44. def mousePressEvent(self, mouse_event):
  45. pass
  46. def drawContents(self, painter):
  47. if self._to_stop:
  48. return
  49. painter.save()
  50. painter.setPen(QColor(255, 255, 255, 255))
  51. painter.setRenderHint(QPainter.Antialiasing)
  52. painter.setRenderHint(QPainter.Antialiasing, True)
  53. version = Application.getInstance().getVersion().split("-")
  54. # Draw version text
  55. font = QFont() # Using system-default font here
  56. font.setPixelSize(18)
  57. painter.setFont(font)
  58. painter.drawText(60, 70 + self._version_y_offset, round(330 * self._scale), round(230 * self._scale), Qt.AlignLeft | Qt.AlignTop, version[0] if not ApplicationMetadata.IsAlternateVersion else ApplicationMetadata.CuraBuildType)
  59. if len(version) > 1:
  60. font.setPixelSize(16)
  61. painter.setFont(font)
  62. painter.setPen(QColor(200, 200, 200, 255))
  63. painter.drawText(247, 105 + self._version_y_offset, round(330 * self._scale), round(255 * self._scale), Qt.AlignLeft | Qt.AlignTop, version[1])
  64. painter.setPen(QColor(255, 255, 255, 255))
  65. # Draw the loading image
  66. pen = QPen()
  67. pen.setWidthF(6 * self._scale)
  68. pen.setColor(QColor(32, 166, 219, 255))
  69. painter.setPen(pen)
  70. painter.drawArc(60, 150, round(32 * self._scale), round(32 * self._scale), round(self._loading_image_rotation_angle * 16), 300 * 16)
  71. # Draw message text
  72. if self._current_message:
  73. font = QFont() # Using system-default font here
  74. font.setPixelSize(13)
  75. pen = QPen()
  76. pen.setColor(QColor(255, 255, 255, 255))
  77. painter.setPen(pen)
  78. painter.setFont(font)
  79. painter.drawText(100, 128, 170, 64,
  80. Qt.AlignLeft | Qt.AlignVCenter | Qt.TextWordWrap,
  81. self._current_message)
  82. painter.restore()
  83. super().drawContents(painter)
  84. def showMessage(self, message, *args, **kwargs):
  85. if self._to_stop:
  86. return
  87. self._current_message = message
  88. self.messageChanged.emit(message)
  89. QCoreApplication.flush()
  90. self.repaint()
  91. def close(self):
  92. # set stop flags
  93. self._to_stop = True
  94. self._change_timer.stop()
  95. super().close()