diff --git a/res/settings.ui b/res/settings.ui index c756e5ee..3ae4d2f3 100644 --- a/res/settings.ui +++ b/res/settings.ui @@ -7,20 +7,20 @@ 0 0 - 285 - 294 + 284 + 334 - 285 - 294 + 284 + 334 - 285 - 294 + 284 + 334 @@ -41,7 +41,7 @@ -3 -3 291 - 301 + 341 @@ -88,7 +88,7 @@ 10 40 - 141 + 261 24 @@ -107,7 +107,7 @@ 10 70 - 151 + 261 16 @@ -158,7 +158,7 @@ 10 120 - 151 + 261 16 @@ -210,7 +210,7 @@ 10 220 - 181 + 261 24 @@ -224,6 +224,102 @@ false + + + + 10 + 280 + 131 + 24 + + + + Screenshot on Split + + + false + + + + + + 10 + 240 + 131 + 24 + + + + Screenshot on Start + + + false + + + + + + 10 + 260 + 131 + 24 + + + + Screenshot on Reset + + + false + + + + + + 140 + 260 + 131 + 24 + + + + Screenshot on Skip + + + false + + + + + + 140 + 240 + 131 + 24 + + + + Screenshot on Undo + + + false + + + + + + 140 + 280 + 131 + 24 + + + + Screenshot on Pause + + + false + + diff --git a/src/AutoControlledThread.py b/src/AutoControlledThread.py index e61cb118..416d3529 100644 --- a/src/AutoControlledThread.py +++ b/src/AutoControlledThread.py @@ -24,6 +24,8 @@ def run(self): break except EOFError: continue + if line in self._autosplit_ref.settings_dict["screenshot_on"]: + self._autosplit_ref.screenshot_signal.emit() match line: # This is for use in a Development environment case "kill": diff --git a/src/AutoSplitImage.py b/src/AutoSplitImage.py index 8654fce7..b2b5e26b 100644 --- a/src/AutoSplitImage.py +++ b/src/AutoSplitImage.py @@ -215,7 +215,9 @@ def compare_with_capture(self, default: "AutoSplit | int", capture: MatLike | No if not is_valid_image(self.byte_array): return 0.0 - resized_capture = cv2.resize(capture, self.byte_array.shape[1::-1], interpolation=cv2.INTER_NEAREST) + resized_capture = cv2.resize( + capture, self.byte_array.shape[1::-1], interpolation=cv2.INTER_NEAREST + ) return get_comparison_method_by_index( self.__get_comparison_method_index(default), diff --git a/src/hotkeys.py b/src/hotkeys.py index cf433662..8280a57c 100644 --- a/src/hotkeys.py +++ b/src/hotkeys.py @@ -29,7 +29,7 @@ SET_HOTKEY_TEXT = "Set Hotkey" PRESS_A_KEY_TEXT = "Press a key..." -Commands = Literal["split", "start", "pause", "reset", "skip", "undo"] +CommandStr = Literal["split", "start", "pause", "reset", "skip", "undo"] Hotkey = Literal[ "split", "reset", @@ -80,16 +80,18 @@ def after_setting_hotkey(autosplit: "AutoSplit"): getattr(autosplit.SettingsWidget, f"set_{hotkey}_hotkey_button").setEnabled(True) -def send_command(autosplit: "AutoSplit", command: Commands): - # Note: Rather than having the start image able to also reset the timer, - # having the reset image check be active at all time would be a better, more organic solution, - # but that is dependent on migrating to an observer pattern (#219) and - # being able to reload all images. +def send_command(autosplit: "AutoSplit", command: CommandStr): + if command in autosplit.settings_dict["screenshot_on"]: + autosplit.screenshot_signal.emit() match command: case _ if autosplit.is_auto_controlled: if command == "start" and autosplit.settings_dict["start_also_resets"]: print("reset", flush=True) print(command, flush=True) + # Note: Rather than having the start image able to also reset the timer, having + # the reset image check be active at all time would be a better, more organic solution. + # But that is dependent on migrating to an observer pattern (#219) and + # being able to reload all images. case "start" if autosplit.settings_dict["start_also_resets"]: _send_hotkey(autosplit.settings_dict["reset_hotkey"]) case "reset": diff --git a/src/menu_bar.py b/src/menu_bar.py index 4c3e9f06..a655735a 100644 --- a/src/menu_bar.py +++ b/src/menu_bar.py @@ -2,7 +2,7 @@ import sys import webbrowser from functools import partial -from typing import TYPE_CHECKING, Any, cast +from typing import TYPE_CHECKING, Any, Literal, cast from urllib.error import URLError from urllib.request import urlopen @@ -23,7 +23,7 @@ get_all_video_capture_devices, ) from gen import about, design, settings as settings_ui, update_checker -from hotkeys import HOTKEYS, HOTKEYS_WHEN_AUTOCONTROLLED, set_hotkey +from hotkeys import HOTKEYS, HOTKEYS_WHEN_AUTOCONTROLLED, CommandStr, set_hotkey from utils import AUTOSPLIT_VERSION, GITHUB_REPOSITORY, ONE_SECOND, decimal, fire_and_forget if TYPE_CHECKING: @@ -38,6 +38,15 @@ + "\nRun: sudo apt-get install scrot" ) if sys.platform == "linux" else "" # fmt: skip +_DEBUG_SCREENSHOT_COMMANDS: tuple[CommandStr, ...] = ( + "split", + "start", + "reset", + "undo", + "skip", + "pause", +) + class __AboutWidget(QtWidgets.QWidget, about.Ui_AboutAutoSplitWidget): # noqa: N801 # Private class """About Window.""" @@ -326,7 +335,7 @@ def __select_screenshot_directory(self): ) def __setup_bindings(self): - """Hotkey initial values and bindings.""" + # Hotkey initial values and bindings for hotkey in HOTKEYS: hotkey_input: QtWidgets.QLineEdit = getattr(self, f"{hotkey}_input") set_hotkey_hotkey_button: QtWidgets.QPushButton = getattr( @@ -344,6 +353,21 @@ def __setup_bindings(self): partial(set_hotkey, self._autosplit_ref, hotkey=hotkey) ) + # Debug screenshot selection checkboxes initial values and bindings + _screenshot_on_setting = self._autosplit_ref.settings_dict["screenshot_on"] + for command in _DEBUG_SCREENSHOT_COMMANDS: + checkbox: QtWidgets.QCheckBox = getattr(self, f"screenshot_on_{command}_checkbox") + + checkbox.setChecked(command in _screenshot_on_setting) + + def add_or_del(checked: Literal[0, 2], command: CommandStr = command): + if checked: + _screenshot_on_setting.add(command) + else: + _screenshot_on_setting.remove(command) + + checkbox.stateChanged.connect(add_or_del) + # region Set initial values # Capture Settings self.fps_limit_spinbox.setValue(self._autosplit_ref.settings_dict["fps_limit"]) @@ -478,6 +502,10 @@ def get_default_settings_from_ui(autosplit: "AutoSplit"): "split_image_directory": autosplit.split_image_folder_input.text(), "screenshot_directory": default_settings_dialog.screenshot_directory_input.text(), "open_screenshot": default_settings_dialog.open_screenshot_checkbox.isChecked(), + "screenshot_on": { + getattr(default_settings_dialog, f"screenshot_on_{command}_checkbox").isChecked() + for command in _DEBUG_SCREENSHOT_COMMANDS + }, "captured_window_title": "", "capture_region": { "x": autosplit.x_spinbox.value(), diff --git a/src/user_profile.py b/src/user_profile.py index 723af2a1..fdf8d193 100644 --- a/src/user_profile.py +++ b/src/user_profile.py @@ -9,7 +9,7 @@ import error_messages from capture_method import CAPTURE_METHODS, CaptureMethodEnum, Region, change_capture_method from gen import design -from hotkeys import HOTKEYS, Hotkey, remove_all_hotkeys, set_hotkey +from hotkeys import HOTKEYS, CommandStr, Hotkey, remove_all_hotkeys, set_hotkey from menu_bar import open_settings from utils import auto_split_directory @@ -40,6 +40,7 @@ class UserProfileDict(TypedDict): split_image_directory: str screenshot_directory: str open_screenshot: bool + screenshot_on: set[CommandStr] captured_window_title: str capture_region: Region @@ -72,6 +73,7 @@ def copy(): split_image_directory="", screenshot_directory="", open_screenshot=True, + screenshot_on=set(), captured_window_title="", capture_region=Region(x=0, y=0, width=1, height=1), ) @@ -122,7 +124,7 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s autosplit.show_error_signal.emit(error_messages.old_version_settings_file) return False - # Allow seemlessly reloading the entire settings widget + # Allow seamlessly reloading the entire settings widget settings_widget_was_open = False settings_widget = cast(QtWidgets.QWidget | None, autosplit.SettingsWidget) if settings_widget: @@ -137,6 +139,7 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s loaded_settings = DEFAULT_PROFILE | cast(UserProfileDict, toml.load(file)) # TODO: Data Validation / fallbacks ? + loaded_settings["screenshot_on"] = set(loaded_settings["screenshot_on"]) autosplit.settings_dict = UserProfileDict(**loaded_settings) autosplit.last_saved_settings = deepcopy(autosplit.settings_dict)