Skip to content

Add color theme toggle to pilot#788

Open
JunliXiao wants to merge 1 commit into
solvcon:masterfrom
JunliXiao:feat_color_toggle
Open

Add color theme toggle to pilot#788
JunliXiao wants to merge 1 commit into
solvcon:masterfrom
JunliXiao:feat_color_toggle

Conversation

@JunliXiao
Copy link
Copy Markdown

Ref issue #510
Last PR #678

After some cleaning in my fork, the last PR was force closed, so I created this new one.

It's the same function and usage as presented in the issue, while the codebase is up-to-date and the change has passed CI runs in my fork.

@JunliXiao
Copy link
Copy Markdown
Author

Hello @yungyuc , @c1ydehhx
Please review this one when you have time, thanks!

@yungyuc yungyuc added the pilot GUI and visualization label May 18, 2026
@yungyuc yungyuc moved this from Todo to In Progress in pilot general GUI May 18, 2026
Copy link
Copy Markdown
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

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

  • Use Qt.ColorScheme enum.
  • Balance if/elif/else.
  • Fix a bug: Both dark and system are assigned number 1 and treat the same way.
  • Keep button_group as a member data, otherwise it will be garbage collected after the end of init_ui() function.
  • _Controller.appearance_open is not used. Remove the dead code.
  • Discuss: Why duplicating construction of AppearanceDialog?
  • Rename AppearanceDialog.ok() to on_ok() like the other functions in the class.
  • Discuss: Is it intended to create AppearanceDialog without a parent?

@tigercosmos please help take a look.


Screenshots. Pretty nice.

image image

Comment thread modmesh/pilot/_gui.py
dark_mode_button.setFocusPolicy(Qt.NoFocus)
system_mode_button.setFocusPolicy(Qt.NoFocus)

color_scheme_name = str(self.qApp.styleHints().colorScheme())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

self.qApp.styleHints().colorScheme() already returns Qt.ColorScheme. See https://doc.qt.io/qt-6/qt.html#ColorScheme-enum , also available in PySide https://doc.qt.io/qtforpython-6/PySide6/QtCore/Qt.html#PySide6.QtCore.Qt.ColorScheme

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 Unknown (System). Please add it back.

We should also use balanced if/elif/else most of the time.

Comment thread modmesh/pilot/_gui.py

button_group = QButtonGroup()
button_group.addButton(light_mode_button, 0)
button_group.addButton(dark_mode_button, 1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread modmesh/pilot/_gui.py
if color_scheme_name == "ColorScheme.Dark":
dark_mode_button.setChecked(True)

button_group = QButtonGroup()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keep button_group as a member data, otherwise it will be garbage collected after the end of this init_ui() function (because it is not added to another widget to keep the live).

Comment thread modmesh/pilot/_gui.py
self.canvas = None
self.openprofiledata = None
self.runprofiling = None
self.appearance_open = False
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

appearance_open is not used. Remove the dead code.

Comment thread modmesh/pilot/_gui.py
self.openprofiledata.populate_menu()
self.runprofiling.populate_menu()

self.appearance_dialog = AppearanceDialog()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you construct AppearanceDialog at two places, here and at line 168?

Comment thread modmesh/pilot/_gui.py
self.qApp = QApplication.instance()
self.init_ui()

def ok(self):
Copy link
Copy Markdown
Member

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?

Comment thread modmesh/pilot/_gui.py
def on_open_appearance(self):
self.appearance_open = True
if not self.appearance_dialog:
self.appearance_dialog = AppearanceDialog()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AppearanceDialog is created without a parent, and won't be owned by the main window. Is it intented?

@yungyuc yungyuc requested a review from tigercosmos May 19, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pilot GUI and visualization

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants