-
Notifications
You must be signed in to change notification settings - Fork 61
Add color theme toggle to pilot #788
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?
Changes from all commits
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,7 +39,12 @@ | |
| from . import airfoil | ||
|
|
||
| if _pcore.enable: | ||
| from PySide6.QtCore import Qt | ||
| from PySide6.QtGui import QAction | ||
| from PySide6.QtWidgets import (QApplication, QLabel, | ||
| QVBoxLayout, QHBoxLayout, | ||
| QGroupBox, QButtonGroup, QPushButton, | ||
| QRadioButton, QDialog) | ||
| from . import _mesh | ||
| from . import _euler1d | ||
| from . import _burgers1d | ||
|
|
@@ -67,6 +72,73 @@ def __call__(cls, *args, **kw): | |
| return cls._instances[cls] | ||
|
|
||
|
|
||
| class AppearanceDialog(QDialog): | ||
| """ | ||
| AppearanceDialog class for managing the general look | ||
| and feel of Qt widgets. | ||
|
|
||
| This class inherits from the QDialog class and provides radio buttons | ||
| for seleting color themes. | ||
| """ | ||
| def __init__(self, parent=None): | ||
| super().__init__(parent) | ||
| self.qApp = QApplication.instance() | ||
| self.init_ui() | ||
|
|
||
| def ok(self): | ||
| controller.on_close_appearance() | ||
|
|
||
| def on_click_light_mode(self): | ||
| self.qApp.styleHints().setColorScheme(Qt.ColorScheme.Light) | ||
|
|
||
| def on_click_dark_mode(self): | ||
| self.qApp.styleHints().setColorScheme(Qt.ColorScheme.Dark) | ||
|
|
||
| def on_click_system_mode(self): | ||
| self.qApp.styleHints().setColorScheme(Qt.ColorScheme.Unknown) | ||
|
|
||
| def init_ui(self): | ||
| self.setWindowTitle("Appearance") | ||
| layout = QVBoxLayout() | ||
|
|
||
| layout.addWidget(QLabel("Light/Dark Mode Toggle")) | ||
|
|
||
| light_mode_button = QRadioButton("Light") | ||
| dark_mode_button = QRadioButton("Dark") | ||
| system_mode_button = QRadioButton("System") | ||
| light_mode_button.clicked.connect(self.on_click_light_mode) | ||
| dark_mode_button.clicked.connect(self.on_click_dark_mode) | ||
| system_mode_button.clicked.connect(self.on_click_system_mode) | ||
| light_mode_button.setFocusPolicy(Qt.NoFocus) | ||
| dark_mode_button.setFocusPolicy(Qt.NoFocus) | ||
| system_mode_button.setFocusPolicy(Qt.NoFocus) | ||
|
|
||
| color_scheme_name = str(self.qApp.styleHints().colorScheme()) | ||
|
Member
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.
Code to compare the enum will be more robust: scheme = self.qapp.styleHints().colorScheme()
if scheme == Qt.ColorScheme.Light:
light_mode_button.setChecked(True)
elif scheme == Qt.ColorScheme.Dark:
dark_mode_button.setChecked(True)
else: # Qt.ColorScheme.Unknown -> "System"
system_mode_button.setChecked(True)You forgot We should also use balanced |
||
| if color_scheme_name == "ColorScheme.Light": | ||
| light_mode_button.setChecked(True) | ||
| if color_scheme_name == "ColorScheme.Dark": | ||
| dark_mode_button.setChecked(True) | ||
|
|
||
| button_group = QButtonGroup() | ||
|
Member
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. Keep |
||
| button_group.addButton(light_mode_button, 0) | ||
| button_group.addButton(dark_mode_button, 1) | ||
|
Member
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. A bug: Both dark and system are assigned number 1 and treat the same way. A fix is like: button_group.addButton(dark_mode_button, 1)
button_group.addButton(system_mode_button, 2) |
||
| button_group.addButton(system_mode_button, 1) | ||
|
|
||
| hbox_1 = QHBoxLayout() | ||
| hbox_1.addWidget(light_mode_button) | ||
| hbox_1.addWidget(dark_mode_button) | ||
| hbox_1.addWidget(system_mode_button) | ||
| group_box_1 = QGroupBox() | ||
| group_box_1.setLayout(hbox_1) | ||
| layout.addWidget(group_box_1) | ||
|
|
||
| ok_button = QPushButton("OK") | ||
| ok_button.clicked.connect(self.ok) | ||
| layout.addWidget(ok_button) | ||
|
|
||
| self.setLayout(layout) | ||
|
|
||
|
|
||
| class _Controller(metaclass=_Singleton): | ||
| def __init__(self): | ||
| # Do not construct any Qt member objects before calling launch(), or | ||
|
|
@@ -83,6 +155,18 @@ def __init__(self): | |
| self.canvas = None | ||
| self.openprofiledata = None | ||
| self.runprofiling = None | ||
| self.appearance_open = False | ||
|
Member
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.
|
||
|
|
||
| def on_close_appearance(self): | ||
| self.appearance_open = False | ||
| if self.appearance_dialog: | ||
| self.appearance_dialog.close() | ||
|
|
||
| def on_open_appearance(self): | ||
| self.appearance_open = True | ||
| if not self.appearance_dialog: | ||
| self.appearance_dialog = AppearanceDialog() | ||
|
Member
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.
|
||
| self.appearance_dialog.exec_() | ||
|
|
||
| def __getattr__(self, name): | ||
| return None if self._rmgr is None else getattr(self._rmgr, name) | ||
|
|
@@ -137,6 +221,8 @@ def _addAction(menu, text, tip, func, checkable=False, checked=False): | |
| self.openprofiledata.populate_menu() | ||
| self.runprofiling.populate_menu() | ||
|
|
||
| self.appearance_dialog = AppearanceDialog() | ||
|
Member
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. Why do you construct |
||
|
|
||
| if sys.platform != 'darwin': | ||
| _addAction( | ||
| menu=wm.fileMenu, | ||
|
|
@@ -145,6 +231,15 @@ def _addAction(menu, text, tip, func, checkable=False, checked=False): | |
| func=lambda: wm.quit(), | ||
| ) | ||
|
|
||
| _addAction( | ||
| menu=wm.windowMenu, | ||
| text="Appearance", | ||
| tip="Manage the app's look and feel", | ||
| func=controller.on_open_appearance, | ||
| checkable=False, | ||
| checked=False, | ||
| ) | ||
|
|
||
| _addAction( | ||
| menu=wm.windowMenu, | ||
| text="Console", | ||
|
|
||
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.
How about naming it
on_ok()like the rest of the functions?