Skip to content

Commit 8c11c95

Browse files
authored
Merge pull request #111 from labscript-suite/pyside6
Make splash screen widget compatible with PySide6
2 parents 56fedba + fe2a120 commit 8c11c95

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

Diff for: labscript_utils/splash.py

+22-42
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,28 @@
1515
from labscript_utils import dedent
1616

1717
try:
18-
from qtutils.qt import QtWidgets, QtCore, QtGui
18+
from qtutils.qt import QtWidgets, QtCore, QtGui, QT_ENV
1919
except ImportError as e:
2020
if 'DLL load failed' in str(e):
2121
msg = """Failed to load Qt DLL. This can be caused by application shortcuts
2222
not being configured to activate conda environments. Try running the
2323
following from within the activated conda environment to fix the shortcuts:
2424
25-
python -m labscript_utils.winshell --fix-shortcuts."""
25+
desktop-app install blacs lyse runmanager runviewer"""
2626
raise ImportError(dedent(msg))
2727
raise
2828

2929
Qt = QtCore.Qt
3030

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)
3940

4041

4142
class Splash(QtWidgets.QFrame):
@@ -46,12 +47,13 @@ class Splash(QtWidgets.QFrame):
4647
alpha = 0.875
4748
icon_frac = 0.65
4849
BG = '#ffffff'
50+
FG = '#000000'
4951

5052
def __init__(self, imagepath):
5153
self.qapplication = QtWidgets.QApplication.instance()
5254
if self.qapplication is None:
5355
self.qapplication = QtWidgets.QApplication(sys.argv)
54-
QtWidgets.QFrame.__init__(self)
56+
super().__init__()
5557
self.icon = QtGui.QPixmap()
5658
self.icon.load(imagepath)
5759
if self.icon.isNull():
@@ -63,7 +65,7 @@ def __init__(self, imagepath):
6365
self.setWindowFlags(Qt.SplashScreen)
6466
self.setWindowOpacity(self.alpha)
6567
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")
6769
# Frame not necessary on macos, and looks ugly.
6870
if sys.platform != 'darwin':
6971
self.setFrameShape(QtWidgets.QFrame.StyledPanel)
@@ -79,46 +81,24 @@ def __init__(self, imagepath):
7981
layout.addWidget(image_label)
8082
layout.addWidget(self.label)
8183

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
8685

8786
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
93-
94-
def show(self):
95-
QtWidgets.QFrame.show(self)
96-
self.update_text(self.text)
87+
self._paint_pending = False
88+
return super().paintEvent(event)
9789

9890
def update_text(self, text):
9991
self.text = text
10092
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()
93+
self._paint_pending = True
94+
while self._paint_pending:
95+
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
96+
QtCore.QCoreApplication.sendPostedEvents()
10697

10798

10899
if __name__ == '__main__':
109100
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-
101+
icon = '../../runmanager/runmanager/runmanager.svg'
122102
splash = Splash(icon)
123103
splash.show()
124104
time.sleep(1)

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies = [
3535
"numpy>=1.15",
3636
"packaging>=20.4",
3737
"pyqtgraph>=0.11.0rc0",
38-
"qtutils>=2.2.3",
38+
"qtutils>=4.0",
3939
"scipy",
4040
"zprocess>=2.18.0",
4141
"setuptools_scm>=4.1.0",

0 commit comments

Comments
 (0)