From f28e63432c54c6264d73b5d66b4352a1b037bdcf Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sun, 7 Jul 2024 20:51:09 -0500 Subject: [PATCH 1/5] Delay the showing of the main window until all themes are applied fully --- src/classes/app.py | 6 ++++++ src/windows/main_window.py | 7 ++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/classes/app.py b/src/classes/app.py index 59be7e294..5edae567c 100644 --- a/src/classes/app.py +++ b/src/classes/app.py @@ -273,6 +273,12 @@ def gui(self): # Connect our exit signals self.aboutToQuit.connect(self.cleanup) + # Process any queued events + QApplication.processEvents() + + # Show main window + self.window.show() + args = self.args if len(args) < 2: # Recover backup file (this can't happen until after the Main Window has completely loaded) diff --git a/src/windows/main_window.py b/src/windows/main_window.py index e368ad12a..44004647a 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -3482,21 +3482,18 @@ def __init__(self, *args): self.toolBar.topLevelChanged.connect( functools.partial(self.freezeMainToolBar, None)) - # Show window - self.show() - # Create tutorial manager self.tutorial_manager = TutorialManager(self) # Apply saved window geometry/state from settings if self.saved_geometry: try: - QTimer.singleShot(100, functools.partial(self.restoreGeometry, self.saved_geometry)) + QTimer.singleShot(0, functools.partial(self.restoreGeometry, self.saved_geometry)) except Exception as e: log.error(f"Error restoring window geometry: {e}") if self.saved_state: try: - QTimer.singleShot(100, functools.partial(self.restoreState, self.saved_state)) + QTimer.singleShot(0, functools.partial(self.restoreState, self.saved_state)) except Exception as e: log.error(f"Error restoring window state: {e}") From 2ebc773fceb1b5a9deca618355d8813a001fb6aa Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sun, 7 Jul 2024 22:00:37 -0500 Subject: [PATCH 2/5] Removing singleShot timers for window geometry and state restoring, and removing processEvents before window.show() --- src/classes/app.py | 3 --- src/windows/main_window.py | 10 ++-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/classes/app.py b/src/classes/app.py index 5edae567c..3162872db 100644 --- a/src/classes/app.py +++ b/src/classes/app.py @@ -273,9 +273,6 @@ def gui(self): # Connect our exit signals self.aboutToQuit.connect(self.cleanup) - # Process any queued events - QApplication.processEvents() - # Show main window self.window.show() diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 44004647a..7a4a70bbe 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -3487,15 +3487,9 @@ def __init__(self, *args): # Apply saved window geometry/state from settings if self.saved_geometry: - try: - QTimer.singleShot(0, functools.partial(self.restoreGeometry, self.saved_geometry)) - except Exception as e: - log.error(f"Error restoring window geometry: {e}") + self.restoreGeometry(self.saved_geometry) if self.saved_state: - try: - QTimer.singleShot(0, functools.partial(self.restoreState, self.saved_state)) - except Exception as e: - log.error(f"Error restoring window state: {e}") + self.restoreState(self.saved_state) # Save settings s.save() From 906bc930e7586e88efae389756ed6fc0b397aabc Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Mon, 8 Jul 2024 13:51:13 -0500 Subject: [PATCH 3/5] Move apply_theme to main_window, before restoring geometry and state --- src/classes/app.py | 7 ------- src/windows/main_window.py | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/classes/app.py b/src/classes/app.py index 3162872db..c29430d45 100644 --- a/src/classes/app.py +++ b/src/classes/app.py @@ -255,13 +255,6 @@ def gui(self): log.debug("Creating main interface window") self.window = MainWindow() - # Instantiate Theme Manager (Singleton) - theme_name = self.settings.get("theme") - theme = self.theme_manager.apply_theme(theme_name) - - # Update theme in settings - self.settings.set("theme", theme.name) - # Check for gui launch failures if self.mode == "quit": self.window.close() diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 7a4a70bbe..745f4f57a 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -3485,6 +3485,11 @@ def __init__(self, *args): # Create tutorial manager self.tutorial_manager = TutorialManager(self) + # Apply theme + theme_name = s.get("theme") + theme = get_app().theme_manager.apply_theme(theme_name) + s.set("theme", theme.name) + # Apply saved window geometry/state from settings if self.saved_geometry: self.restoreGeometry(self.saved_geometry) From 06f4591acbf83420c5704103a6f22c5d6448777c Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Mon, 8 Jul 2024 14:06:13 -0500 Subject: [PATCH 4/5] Restore widget state after window is shown, since doing this in the constructor does not seem to work on Windows 10/11 machines. --- src/windows/main_window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 745f4f57a..e0329b7be 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -3494,7 +3494,7 @@ def __init__(self, *args): if self.saved_geometry: self.restoreGeometry(self.saved_geometry) if self.saved_state: - self.restoreState(self.saved_state) + QTimer.singleShot(0, functools.partial(self.restoreState, self.saved_state)) # Save settings s.save() From 3b895a2c54b762bc6e16c2371ef6abe1e79c7220 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Mon, 8 Jul 2024 14:31:37 -0500 Subject: [PATCH 5/5] Theme manager: limit setContentsMargins to only "dock" + "Contents" named widgets (fixes tutorial when changing themes) --- src/themes/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/themes/base.py b/src/themes/base.py index 1d1259a5f..b814594fe 100755 --- a/src/themes/base.py +++ b/src/themes/base.py @@ -83,9 +83,9 @@ def set_dock_margins(self, content_margins=None, layout_margins=None, object_nam if child.objectName().startswith("dock") and child.objectName().endswith("Contents"): # Set content margins on QDock* widget child.setContentsMargins(*content_margins) - if child.layout() and layout_margins: - # Set content margins on the QDock Layout (which has additional margins) - child.layout().setContentsMargins(*layout_margins) + if child.layout() and layout_margins: + # Set content margins on the QDock Layout (which has additional margins) + child.layout().setContentsMargins(*layout_margins) def set_toolbar_buttons(self, toolbar, icon_size=24, settings=None): """Iterate through toolbar button settings, and apply them to each button.