CuraSplashScreen.py 4.1 KB

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