Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
Actions shortcut and prevent double open window
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Sep 3, 2022
1 parent ff94263 commit 0b947f5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 48 deletions.
67 changes: 39 additions & 28 deletions res/design.ui
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,10 @@
<addaction name="action_view_help"/>
<addaction name="action_check_for_updates"/>
<addaction name="action_check_for_updates_on_open"/>
<addaction name="separator"/>
<addaction name="action_about"/>
<addaction name="action_about_qt"/>
<addaction name="action_about_qt_for_python"/>
</widget>
<widget class="QMenu" name="menu_file">
<property name="title">
Expand All @@ -960,75 +963,83 @@
<property name="text">
<string>View Help</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
<action name="action_about">
<property name="text">
<string>About</string>
<string>About AutoSplit</string>
</property>
</action>
<action name="actionSplit_Settings">
<property name="text">
<string>Split Image Settings</string>
<property name="menuRole">
<enum>QAction::AboutRole</enum>
</property>
</action>
<action name="action_save_profile">
<property name="text">
<string>Save Profile</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="action_load_profile">
<property name="text">
<string>Load Profile</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="action_save_profile_as">
<property name="text">
<string>Save Profile As...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+S</string>
</property>
</action>
<action name="action_check_for_updates">
<property name="text">
<string>Check For Updates</string>
</property>
</action>
<action name="actionCheck_for_Updates_on_Open">
<action name="action_settings">
<property name="text">
<string>Settings</string>
</property>
<property name="shortcut">
<string>Ctrl+,</string>
</property>
<property name="menuRole">
<enum>QAction::PreferencesRole</enum>
</property>
</action>
<action name="action_check_for_updates_on_open">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Check for Updates on Open</string>
</property>
</action>
<action name="actionAuto_Start_On_Reset">
<property name="text">
<string>Check For Updates On Open</string>
</property>
</action>
<action name="actionGroup_dummy_splits_when_undoing_skipping">
<action name="action_about_qt">
<property name="text">
<string>Dummy Splits When Undoing/Skipping</string>
<string>About Qt</string>
</property>
</action>
<action name="action_settings">
<property name="text">
<string>Settings</string>
<property name="menuRole">
<enum>QAction::AboutQtRole</enum>
</property>
</action>
<action name="action_check_for_updates_on_open">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<action name="action_about_qt_for_python">
<property name="text">
<string>Check For Updates On Open</string>
<string>About Qt for Python</string>
</property>
<property name="menuRole">
<enum>QAction::AboutQtRole</enum>
</property>
</action>
</widget>
Expand Down
42 changes: 25 additions & 17 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions src/menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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():
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0b947f5

Please sign in to comment.