From 0b947f5d51f22a3b0a52a598342d210a22fdd696 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 3 Sep 2022 15:29:22 -0400 Subject: [PATCH] Actions shortcut and prevent double open window Closes #154 --- res/design.ui | 67 ++++++++++++++++++++++++++++-------------------- src/AutoSplit.py | 42 ++++++++++++++++++------------ src/menu_bar.py | 17 +++++++++--- 3 files changed, 78 insertions(+), 48 deletions(-) diff --git a/res/design.ui b/res/design.ui index 361470c0..a34632df 100644 --- a/res/design.ui +++ b/res/design.ui @@ -941,7 +941,10 @@ + + + @@ -960,75 +963,83 @@ View Help + + F1 + - About + About AutoSplit - - - - Split Image Settings + + QAction::AboutRole Save Profile + + Ctrl+S + Load Profile + + Ctrl+O + Save Profile As... + + Ctrl+Shift+S + Check For Updates - + + + Settings + + + Ctrl+, + + + QAction::PreferencesRole + + + true true - - true - - - Check for Updates on Open - - - Check For Updates On Open - + - Dummy Splits When Undoing/Skipping + About Qt - - - - Settings + + QAction::AboutQtRole - - - true - - - true - + - Check For Updates On Open + About Qt for Python + + + QAction::AboutQtRole diff --git a/src/AutoSplit.py b/src/AutoSplit.py index ccd1ae80..949e7e8d 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -24,8 +24,8 @@ from capture_method import CaptureMethodEnum, CaptureMethodInterface from gen import about, design, settings, update_checker from hotkeys import HOTKEYS, after_setting_hotkey, send_command -from menu_bar import (check_for_updates, get_default_settings_from_ui, open_about, open_settings, open_update_checker, - view_help) +from menu_bar import (about_qt, about_qt_for_python, check_for_updates, get_default_settings_from_ui, open_about, + open_settings, open_update_checker, view_help) from region_selection import align_region, select_region, select_window, validate_before_parsing from split_parser import BELOW_FLAG, DUMMY_FLAG, PAUSE_FLAG, parse_and_validate_images from user_profile import DEFAULT_PROFILE @@ -127,21 +127,6 @@ def __init__(self, parent: QWidget | None = None): # pylint: disable=too-many-s self.settings_dict = get_default_settings_from_ui(self) user_profile.load_check_for_updates_on_open(self) - self.action_view_help.triggered.connect(view_help) - self.action_about.triggered.connect(lambda: open_about(self)) - self.action_check_for_updates.triggered.connect(lambda: check_for_updates(self)) - self.action_settings.triggered.connect(lambda: open_settings(self)) - self.action_save_profile.triggered.connect(lambda: user_profile.save_settings(self)) - self.action_save_profile_as.triggered.connect(lambda: user_profile.save_settings_as(self)) - self.action_load_profile.triggered.connect(lambda: user_profile.load_settings(self)) - - if self.SettingsWidget: - self.SettingsWidget.split_input.setEnabled(False) - self.SettingsWidget.reset_input.setEnabled(False) - self.SettingsWidget.skip_split_input.setEnabled(False) - self.SettingsWidget.undo_split_input.setEnabled(False) - self.SettingsWidget.pause_input.setEnabled(False) - if self.is_auto_controlled: self.start_auto_splitter_button.setEnabled(False) @@ -159,6 +144,25 @@ def __init__(self, parent: QWidget | None = None): # pylint: disable=too-many-s # split image folder line edit text self.split_image_folder_input.setText("No Folder Selected") + # Connecting menu actions + self.action_view_help.triggered.connect(view_help) + self.action_about.triggered.connect(lambda: open_about(self)) + self.action_about_qt.triggered.connect(lambda: about_qt) + self.action_about_qt_for_python.triggered.connect(lambda: about_qt_for_python) + self.action_check_for_updates.triggered.connect(lambda: check_for_updates(self)) + self.action_settings.triggered.connect(lambda: open_settings(self)) + self.action_save_profile.triggered.connect(lambda: user_profile.save_settings(self)) + self.action_save_profile_as.triggered.connect(lambda: user_profile.save_settings_as(self)) + self.action_load_profile.triggered.connect(lambda: user_profile.load_settings(self)) + + # Shortcut context can't be set through the designer because of a bug in pyuic6 that generates invalid code + # Email sent to pyqt@riverbankcomputing.com + self.action_view_help.setShortcutContext(QtCore.Qt.ShortcutContext.ApplicationShortcut) + self.action_settings.setShortcutContext(QtCore.Qt.ShortcutContext.ApplicationShortcut) + self.action_save_profile.setShortcutContext(QtCore.Qt.ShortcutContext.ApplicationShortcut) + self.action_save_profile_as.setShortcutContext(QtCore.Qt.ShortcutContext.ApplicationShortcut) + self.action_load_profile.setShortcutContext(QtCore.Qt.ShortcutContext.ApplicationShortcut) + # Connecting button clicks to functions self.browse_button.clicked.connect(self.__browse) self.select_region_button.clicked.connect(lambda: select_region(self)) @@ -696,6 +700,8 @@ def gui_changes_on_start(self): self.previous_image_button.setEnabled(True) self.next_image_button.setEnabled(True) + # TODO: Do we actually need to disable setting new hotkeys once started? + # What does this achieve? (See below TODO) if self.SettingsWidget: for hotkey in HOTKEYS: getattr(self.SettingsWidget, f"set_{hotkey}_hotkey_button").setEnabled(False) @@ -724,6 +730,8 @@ def gui_changes_on_reset(self, safe_to_reload_start_image: bool = False): self.previous_image_button.setEnabled(False) self.next_image_button.setEnabled(False) + # TODO: Do we actually need to disable setting new hotkeys once started? + # What does this achieve? (see above TODO) if self.SettingsWidget and not self.is_auto_controlled: for hotkey in HOTKEYS: getattr(self.SettingsWidget, f"set_{hotkey}_hotkey_button").setEnabled(True) diff --git a/src/menu_bar.py b/src/menu_bar.py index 8cad998c..98458605 100644 --- a/src/menu_bar.py +++ b/src/menu_bar.py @@ -35,7 +35,8 @@ def __init__(self): def open_about(autosplit: AutoSplit): - autosplit.AboutWidget = __AboutWidget() + if not autosplit.AboutWidget or cast(QtWidgets.QWidget, autosplit.AboutWidget).isHidden(): + autosplit.AboutWidget = __AboutWidget() class __UpdateCheckerWidget(QtWidgets.QWidget, update_checker.Ui_UpdateChecker): @@ -70,7 +71,8 @@ def do_not_ask_me_again_state_changed(self): def open_update_checker(autosplit: AutoSplit, latest_version: str, check_on_open: bool): - autosplit.UpdateCheckerWidget = __UpdateCheckerWidget(latest_version, autosplit, check_on_open) + if not autosplit.UpdateCheckerWidget or cast(QtWidgets.QWidget, autosplit.UpdateCheckerWidget).isHidden(): + autosplit.UpdateCheckerWidget = __UpdateCheckerWidget(latest_version, autosplit, check_on_open) def view_help(): @@ -93,6 +95,14 @@ def run(self): self.autosplit.show_error_signal.emit(error_messages.check_for_updates) +def about_qt(): + webbrowser.open("https://wiki.qt.io/About_Qt") + + +def about_qt_for_python(): + webbrowser.open("https://wiki.qt.io/Qt_for_Python") + + def check_for_updates(autosplit: AutoSplit, check_on_open: bool = False): autosplit.CheckForUpdatesThread = __CheckForUpdatesThread(autosplit, check_on_open) autosplit.CheckForUpdatesThread.start() @@ -278,7 +288,8 @@ def hotkey_connect(hotkey: Hotkeys): def open_settings(autosplit: AutoSplit): - autosplit.SettingsWidget = __SettingsWidget(autosplit) + if not autosplit.SettingsWidget or cast(QtWidgets.QDialog, autosplit.SettingsWidget).isHidden(): + autosplit.SettingsWidget = __SettingsWidget(autosplit) def get_default_settings_from_ui(autosplit: AutoSplit):