Skip to content

Commit

Permalink
Update reload_start_image functions names
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Dec 23, 2023
1 parent 8e75919 commit 6aa4da7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
39 changes: 25 additions & 14 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AutoSplit(QMainWindow, design.Ui_MainWindow):
screenshot_signal = QtCore.Signal()
after_setting_hotkey_signal = QtCore.Signal()
update_checker_widget_signal = QtCore.Signal(str, bool)
load_start_image_signal = QtCore.Signal(bool, bool)
reload_start_image_signal = QtCore.Signal(bool, bool)
# Use this signal when trying to show an error from outside the main thread
show_error_signal = QtCore.Signal(FunctionType)

Expand Down Expand Up @@ -174,7 +174,7 @@ def _show_error_signal_slot(error_message_box: Callable[..., object]):
self.previous_image_button.clicked.connect(lambda: self.undo_split(True))
self.align_region_button.clicked.connect(lambda: align_region(self))
self.select_window_button.clicked.connect(lambda: select_window(self))
self.reload_start_image_button.clicked.connect(lambda: self.__load_start_image(True, True))
self.reload_start_image_button.clicked.connect(lambda: self.__reload_start_image(True, True))
self.action_check_for_updates_on_open.changed.connect(
lambda: user_profile.set_check_for_updates_on_open(self, self.action_check_for_updates_on_open.isChecked()),
)
Expand All @@ -193,8 +193,7 @@ def _update_checker_widget_signal_slot(latest_version: str, check_on_open: bool)
return open_update_checker(self, latest_version, check_on_open)

self.update_checker_widget_signal.connect(_update_checker_widget_signal_slot)

self.load_start_image_signal.connect(self.__load_start_image)
self.reload_start_image_signal.connect(self.__reload_start_image)
self.reset_signal.connect(self.reset)
self.skip_split_signal.connect(self.skip_split)
self.undo_split_signal.connect(self.undo_split)
Expand All @@ -206,7 +205,7 @@ def _update_checker_widget_signal_slot(latest_version: str, check_on_open: bool)
self.timer_live_image.start(int(ONE_SECOND / self.settings_dict["fps_limit"]))

# Automatic timer start
self.timer_start_image.timeout.connect(self.__start_image_function)
self.timer_start_image.timeout.connect(self.__compare_capture_for_auto_start)

self.show()

Expand Down Expand Up @@ -239,7 +238,7 @@ def __browse(self):
# set the split image folder line to the directory text
self.settings_dict["split_image_directory"] = new_split_image_directory
self.split_image_folder_input.setText(f"{new_split_image_directory}/")
self.load_start_image_signal.emit(False, True)
self.reload_start_image_signal.emit(False, True)

def __update_live_image_details(self, capture: MatLike | None, called_from_timer: bool = False):
# HACK: Since this is also called in __get_capture_for_comparison,
Expand All @@ -264,8 +263,21 @@ def __update_live_image_details(self, capture: MatLike | None, called_from_timer
else:
set_preview_image(self.live_image, capture)

def __load_start_image(self, started_by_button: bool = False, wait_for_delay: bool = True):
"""Not thread safe (if triggered by LiveSplit for example). Use `load_start_image_signal.emit` instead."""
def __reload_start_image(self, started_by_button: bool = False, wait_for_delay: bool = True):
"""
Not thread safe (if triggered by LiveSplit for example). Use `reload_start_image_signal.emit` instead.
1. Stops the automated start check and clear the current Split Image.
2. Reloads the Start Image from disk and validate.
3. If validation passed:
-
- Updates the shown Split Image and Start Image text
- Reinitialise values
- Restart the automated start check
"""
if self.is_running:
raise RuntimeError("Start Image should never be reloaded whilst running!")

self.timer_start_image.stop()
self.current_image_file_label.setText("-")
self.start_image_status_value_label.setText("not found")
Expand All @@ -281,8 +293,6 @@ def __load_start_image(self, started_by_button: bool = False, wait_for_delay: bo
QApplication.processEvents()
return

self.split_image_number = 0

if not wait_for_delay and self.start_image.get_pause_time(self) > 0:
self.start_image_status_value_label.setText("paused")
self.table_current_image_highest_label.setText("-")
Expand All @@ -291,16 +301,17 @@ def __load_start_image(self, started_by_button: bool = False, wait_for_delay: bo
self.start_image_status_value_label.setText("ready")
self.__update_split_image(self.start_image)

self.split_image_number = 0
self.highest_similarity = 0.0
self.reset_highest_similarity = 0.0
self.split_below_threshold = False
self.timer_start_image.start(int(ONE_SECOND / self.settings_dict["fps_limit"]))

QApplication.processEvents()

def __start_image_function(self):
def __compare_capture_for_auto_start(self):
if not self.start_image:
return
raise ValueError("There are no Start Image. How did we even get here?")

self.start_image_status_value_label.setText("ready")
self.__update_split_image(self.start_image)
Expand Down Expand Up @@ -523,7 +534,7 @@ def __auto_splitter(self): # noqa: PLR0912,PLR0915
self.run_start_time = time()

if not (validate_before_parsing(self) and parse_and_validate_images(self)):
# `safe_to_reload_start_image: bool = False` because __load_start_image also does this check,
# `safe_to_reload_start_image: bool = False` because __reload_start_image also does this check,
# we don't want to double a Start/Reset Image error message
self.gui_changes_on_reset(False)
return
Expand Down Expand Up @@ -782,7 +793,7 @@ def gui_changes_on_reset(self, safe_to_reload_start_image: bool = False):

QApplication.processEvents()
if safe_to_reload_start_image:
self.load_start_image_signal.emit(False, False)
self.reload_start_image_signal.emit(False, False)

def __get_capture_for_comparison(self):
"""Grab capture region and resize for comparison."""
Expand Down
4 changes: 2 additions & 2 deletions src/capture_method/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Region(TypedDict):
height: int


class CaptureMethodMeta(EnumMeta):
class CaptureMethodEnumMeta(EnumMeta):
# Allow checking if simple string is enum
@override
def __contains__(self, other: object):
Expand All @@ -41,7 +41,7 @@ def __contains__(self, other: object):

@unique
# TODO: Try StrEnum in Python 3.11
class CaptureMethodEnum(Enum, metaclass=CaptureMethodMeta):
class CaptureMethodEnum(Enum, metaclass=CaptureMethodEnumMeta):
# Allow TOML to save as a simple string
@override
def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def load_settings(autosplit: "AutoSplit", from_path: str = ""):
autosplit.last_successfully_loaded_settings_file_path = load_settings_file_path
# TODO: Should this check be in `__load_start_image` ?
if not autosplit.is_running:
autosplit.load_start_image_signal.emit(False, True)
autosplit.reload_start_image_signal.emit(False, True)


def load_settings_on_open(autosplit: "AutoSplit"):
Expand Down

0 comments on commit 6aa4da7

Please sign in to comment.