-
Notifications
You must be signed in to change notification settings - Fork 67
Mac os icon #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Mac os icon #124
Changes from all commits
5725e3e
89fdbde
dcbe963
17e36cc
b8989e3
a95f883
f59d1ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| 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') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
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.