-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathsplash_screen.py
84 lines (69 loc) · 2.73 KB
/
splash_screen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sys, threading
from PyQt5 import QtCore, QtGui, QtWidgets
import time
class SplashScreen(QtWidgets.QSplashScreen):
sigEnableHeartbeat = QtCore.pyqtSignal(bool)
def __init__(self, filename=None):
splashSize = QtCore.QSize(400, 400)
geometry = QtWidgets.QApplication.instance().primaryScreen().geometry()
if geometry != None:
splashSize = QtCore.QSize(int(geometry.width() / 4), int(geometry.height() / 4))
splashImage = QtGui.QPixmap(filename).scaled(splashSize, QtCore.Qt.KeepAspectRatio)
#self.splash = QtWidgets.QSplashScreen(splashImage, QtCore.Qt.WindowStaysOnTopHint)
QtWidgets.QSplashScreen.__init__(self, splashImage, QtCore.Qt.WindowStaysOnTopHint)
# Disable closing on mouse press
self.mousePressEvent = lambda e : None
# Signals
#self.sigEnableHeartbeat.connect(self.internalEnableHeartbeat)
#self.updateSplashMessage('')
self.show()
self.running = True
self.heartbeatAnimation = False
self.animationThread = threading.Thread(target=self.animation)
self.animationThread.start()
def __del__(self):
self.running = False
# self.animationThread.join()
def animation(self):
heartbeatCycle = 1.0
heartbeatCycleDelta = -0.02
while self.running is True:
if self.heartbeatAnimation:
heartbeatCycle = heartbeatCycle + heartbeatCycleDelta
if heartbeatCycle <= 0.7 or heartbeatCycle >= 1.0:
heartbeatCycleDelta = -heartbeatCycleDelta
self.setOpacity(heartbeatCycle)
# Process events and sleep
#self.processEvents()
time.sleep(0.1) # 10 FPS
# @QtCore.pyqtSlot(bool)
# def internalEnableHeartbeat(self, enable):
# #self.setOpacity(1.0)
# self.heartbeatAnimation = enable
def enableHeartbeat(self, enable):
self.setOpacity(1.0)
self.heartbeatAnimation = enable
#self.sigEnableHeartbeat.emit(enable)
@QtCore.pyqtSlot(float)
def setOpacity(self, opacity):
self.setWindowOpacity(opacity)
self.repaint()
@QtCore.pyqtSlot(str)
def updateSplashMessage(self, msg=''):
self.showMessage("%s" % msg.title(), QtCore.Qt.AlignBottom)
@QtCore.pyqtSlot()
def show(self):
super().show()
@QtCore.pyqtSlot()
def hide(self):
self.enableHeartbeat(False)
super().hide()
@QtCore.pyqtSlot()
def close(self):
super().close()
self.running = False
if __name__ == "__main__":
qApp = QtWidgets.QApplication(['DepthAI Launcher'])
splashImage = 'splash2.png'
splashScreen = SplashScreen(splashImage)
sys.exit(qApp.exec_())