15
15
from labscript_utils import dedent
16
16
17
17
try :
18
- from qtutils .qt import QtWidgets , QtCore , QtGui
18
+ from qtutils .qt import QtWidgets , QtCore , QtGui , QT_ENV
19
19
except ImportError as e :
20
20
if 'DLL load failed' in str (e ):
21
21
msg = """Failed to load Qt DLL. This can be caused by application shortcuts
22
22
not being configured to activate conda environments. Try running the
23
23
following from within the activated conda environment to fix the shortcuts:
24
24
25
- python -m labscript_utils.winshell --fix-shortcuts. """
25
+ desktop-app install blacs lyse runmanager runviewer """
26
26
raise ImportError (dedent (msg ))
27
27
raise
28
28
29
29
Qt = QtCore .Qt
30
30
31
-
32
- # Set auto high-DPI scaling - this ensures pixel metrics are scaled
33
- # appropriately so that we don't get a weird mix of large fonts and small
34
- # everything else on High DPI displays:
35
- QtWidgets .QApplication .setAttribute (Qt .AA_EnableHighDpiScaling , True )
36
- # Use high res pixmaps if available, instead of rendering at low resolution and
37
- # upscaling:
38
- QtWidgets .QApplication .setAttribute (Qt .AA_UseHighDpiPixmaps , True )
31
+ # These are default in Qt6 and print a warning if set
32
+ if QT_ENV == 'PyQt5' :
33
+ # Set auto high-DPI scaling - this ensures pixel metrics are scaled
34
+ # appropriately so that we don't get a weird mix of large fonts and small
35
+ # everything else on High DPI displays:
36
+ QtWidgets .QApplication .setAttribute (Qt .AA_EnableHighDpiScaling , True )
37
+ # Use high res pixmaps if available, instead of rendering at low resolution and
38
+ # upscaling:
39
+ QtWidgets .QApplication .setAttribute (Qt .AA_UseHighDpiPixmaps , True )
39
40
40
41
41
42
class Splash (QtWidgets .QFrame ):
@@ -46,12 +47,13 @@ class Splash(QtWidgets.QFrame):
46
47
alpha = 0.875
47
48
icon_frac = 0.65
48
49
BG = '#ffffff'
50
+ FG = '#000000'
49
51
50
52
def __init__ (self , imagepath ):
51
53
self .qapplication = QtWidgets .QApplication .instance ()
52
54
if self .qapplication is None :
53
55
self .qapplication = QtWidgets .QApplication (sys .argv )
54
- QtWidgets . QFrame . __init__ (self )
56
+ super (). __init__ ()
55
57
self .icon = QtGui .QPixmap ()
56
58
self .icon .load (imagepath )
57
59
if self .icon .isNull ():
@@ -63,7 +65,7 @@ def __init__(self, imagepath):
63
65
self .setWindowFlags (Qt .SplashScreen )
64
66
self .setWindowOpacity (self .alpha )
65
67
self .label = QtWidgets .QLabel (self .text )
66
- self .setStyleSheet (" background-color: %s ; font-size: 10pt" % self . BG )
68
+ self .setStyleSheet (f"color: { self . FG } ; background-color: { self . BG } ; font-size: 10pt" )
67
69
# Frame not necessary on macos, and looks ugly.
68
70
if sys .platform != 'darwin' :
69
71
self .setFrameShape (QtWidgets .QFrame .StyledPanel )
@@ -79,17 +81,11 @@ def __init__(self, imagepath):
79
81
layout .addWidget (image_label )
80
82
layout .addWidget (self .label )
81
83
82
- center_point = QtWidgets .QDesktopWidget ().availableGeometry ().center ()
83
- x0 , y0 = center_point .x (), center_point .y ()
84
- self .move (x0 - self .w // 2 , y0 - self .h // 2 )
85
- self ._first_paint_complete = False
84
+ self ._paint_pending = False
86
85
87
86
def paintEvent (self , event ):
88
- result = QtWidgets .QFrame .paintEvent (self , event )
89
- if not self ._first_paint_complete :
90
- self ._first_paint_complete = True
91
- self .qapplication .quit ()
92
- return result
87
+ self ._paint_pending = False
88
+ return super ().paintEvent (event )
93
89
94
90
def show (self ):
95
91
QtWidgets .QFrame .show (self )
@@ -98,27 +94,15 @@ def show(self):
98
94
def update_text (self , text ):
99
95
self .text = text
100
96
self .label .setText (text )
101
- # If we are not visible yet, exec until we are painted.
102
- if not self ._first_paint_complete :
103
- self .qapplication .exec_ ()
104
- else :
105
- self .repaint ()
97
+ self ._paint_pending = True
98
+ while self ._paint_pending :
99
+ QtCore .QCoreApplication .processEvents (QtCore .QEventLoop .AllEvents )
100
+ QtCore .QCoreApplication .sendPostedEvents ()
106
101
107
102
108
103
if __name__ == '__main__' :
109
104
import time
110
-
111
- MACOS = sys .platform == 'darwin'
112
- WINDOWS = sys .platform == 'win32'
113
- LINUX = sys .platform .startswith ('linux' )
114
-
115
- if MACOS :
116
- icon = '/Users/bilbo/tmp/runmanager/runmanager.svg'
117
- elif LINUX :
118
- icon = '/home/bilbo/labscript_suite/runmanager/runmanager.svg'
119
- elif WINDOWS :
120
- icon = R'C:\labscript_suite\runmanager\runmanager.svg'
121
-
105
+ icon = '../../runmanager/runmanager/runmanager.svg'
122
106
splash = Splash (icon )
123
107
splash .show ()
124
108
time .sleep (1 )
0 commit comments