Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions labscript_utils/splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@
QtWidgets.QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)


def configure_qapplication(qapplication):
"""Apply labscript-wide QApplication configuration."""
qapplication.setAttribute(Qt.AA_DontShowIconsInMenus, False)
if sys.platform == 'darwin':
icon_path = qapplication.property('_labscript_icon_path')
if icon_path:
icon = QtGui.QIcon(icon_path)
if not icon.isNull():
qapplication.setWindowIcon(icon)
Comment on lines +46 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit to being surprised that this is the actual method that has to be used on Mac OS. Wild. I don't have a mac to test on, but I'll take your word for it that it works.

if qapplication.property('_labscript_qapplication_configured'):
return qapplication
# Native macOS widget styling makes many Qt controls look inconsistent
# with the rest of the suite. Use Qt's own style, but preserve the
# current palette so dark/light appearance still follows the active
# theme.
palette = QtGui.QPalette(qapplication.palette())
style = QtWidgets.QStyleFactory.create('Fusion')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I did the PyQt6 port, I remember briefly looking at moving everything to Fusion and finding it a pretty serious downgrade. Could you share a couple screenshots, since I don't have an easy way to see for myself?

if style is not None:
qapplication.setStyle(style)
qapplication.setPalette(palette)
Comment on lines +53 to +61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be done here? I'd prefer to keep all the style and theming local to each application if at all possible. I realize that makes more distributed work, but the fact styling/palette controls were scattered to the winds is the main reason porting to PyQt6 took so long. I really don't want to let the entropy back in just after it (somewhat) got tamed.

elif qapplication.property('_labscript_qapplication_configured'):
return qapplication
qapplication.setProperty('_labscript_qapplication_configured', True)
return qapplication

class Splash(QtWidgets.QFrame):
w = 250
h = 230
Expand All @@ -49,15 +74,21 @@ class Splash(QtWidgets.QFrame):
BG = '#ffffff'
FG = '#000000'

def __init__(self, imagepath):
def __init__(self, icon_path, application_name=None):
self.qapplication = QtWidgets.QApplication.instance()
if self.qapplication is None:
self.qapplication = QtWidgets.QApplication(sys.argv)
argv = sys.argv
if application_name is not None:
# Create a new argv so QApplication can alter it without mutating sys.argv.
argv = [application_name] + argv[1:]
self.qapplication = QtWidgets.QApplication(argv)
self.qapplication.setProperty('_labscript_icon_path', icon_path)
configure_qapplication(self.qapplication)
super().__init__()
self.icon = QtGui.QPixmap()
self.icon.load(imagepath)
self.icon.load(icon_path)
if self.icon.isNull():
raise ValueError("Invalid image file: {}.\n".format(imagepath))
raise ValueError("Invalid image file: {}.\n".format(icon_path))
self.icon = self.icon.scaled(
self.imwidth, self.imheight, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation
)
Expand Down