From 92f8878a35d141e907661a96baf771b845b31b57 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 2 Feb 2024 20:47:50 -0500 Subject: [PATCH] Revert "Ruff unnacceptable changes" Use `fmt: skip` comments --- src/AutoSplit.py | 18 ++++++++++--- .../DesktopDuplicationCaptureMethod.py | 4 ++- src/capture_method/ScrotCaptureMethod.py | 3 ++- .../VideoCaptureDeviceCaptureMethod.py | 3 ++- .../WindowsGraphicsCaptureMethod.py | 4 ++- src/capture_method/__init__.py | 8 ++++-- src/compare.py | 10 ++++++-- src/hotkeys.py | 25 +++++++++++++++---- src/split_parser.py | 14 ++++++++--- src/user_profile.py | 6 ++++- 10 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index 5643d40e..0dce8710 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -127,7 +127,8 @@ def _show_error_signal_slot(error_message_box: Callable[..., object]): self.setupUi(self) self.setWindowTitle( - f"AutoSplit v{AUTOSPLIT_VERSION}" + (" (externally controlled)" if self.is_auto_controlled else ""), + f"AutoSplit v{AUTOSPLIT_VERSION}" # fmt: skip + + (" (externally controlled)" if self.is_auto_controlled else ""), ) # Hotkeys need to be initialized to be passed as thread arguments in hotkeys.py @@ -440,7 +441,10 @@ def __check_fps(self): self.fps_value_label.setText(str(fps)) def __is_current_split_out_of_range(self): - return self.split_image_number < 0 or self.split_image_number > len(self.split_images_and_loop_number) - 1 + return ( + self.split_image_number < 0 # fmt: skip + or self.split_image_number > len(self.split_images_and_loop_number) - 1 + ) def undo_split(self, navigate_image_only: bool = False): """Undo Split" and "Prev. Img." buttons connect to here.""" @@ -504,7 +508,10 @@ def reset(self): # Functions for the hotkeys to return to the main thread from signals and start their corresponding functions def start_auto_splitter(self): # If the auto splitter is already running or the button is disabled, don't emit the signal to start it. - if self.is_running or (not self.start_auto_splitter_button.isEnabled() and not self.is_auto_controlled): + if ( + self.is_running # fmt: skip + or (not self.start_auto_splitter_button.isEnabled() and not self.is_auto_controlled) + ): return start_label = self.start_image_status_value_label.text() @@ -537,7 +544,10 @@ def __auto_splitter(self): # noqa: PLR0912,PLR0915 # Construct a list of images + loop count tuples. self.split_images_and_loop_number = list( - flatten(((split_image, i + 1) for i in range(split_image.loops)) for split_image in self.split_images), + flatten( + ((split_image, i + 1) for i in range(split_image.loops)) # fmt: skip + for split_image in self.split_images + ), ) # Construct groups of splits diff --git a/src/capture_method/DesktopDuplicationCaptureMethod.py b/src/capture_method/DesktopDuplicationCaptureMethod.py index 8a4bfc31..c3fb8f16 100644 --- a/src/capture_method/DesktopDuplicationCaptureMethod.py +++ b/src/capture_method/DesktopDuplicationCaptureMethod.py @@ -47,7 +47,9 @@ def get_frame(self): left_bounds, top_bounds, *_ = get_window_bounds(hwnd) self.desktop_duplication.display = next( - display for display in self.desktop_duplication.displays if display.hmonitor == hmonitor + display + for display in self.desktop_duplication.displays # fmt: skip + if display.hmonitor == hmonitor ) offset_x, offset_y, *_ = win32gui.GetWindowRect(hwnd) offset_x -= self.desktop_duplication.display.position["left"] diff --git a/src/capture_method/ScrotCaptureMethod.py b/src/capture_method/ScrotCaptureMethod.py index 9b95c79d..7041c7c1 100644 --- a/src/capture_method/ScrotCaptureMethod.py +++ b/src/capture_method/ScrotCaptureMethod.py @@ -19,7 +19,8 @@ class ScrotCaptureMethod(CaptureMethodBase): name = "Scrot" short_description = "very slow, may leave files" description = ( - "\nUses Scrot (SCReenshOT) to take screenshots. " + "\nLeaves behind a screenshot file if interrupted. " + "\nUses Scrot (SCReenshOT) to take screenshots. " # fmt: skip + + "\nLeaves behind a screenshot file if interrupted. " ) @override diff --git a/src/capture_method/VideoCaptureDeviceCaptureMethod.py b/src/capture_method/VideoCaptureDeviceCaptureMethod.py index b3198e92..764695d7 100644 --- a/src/capture_method/VideoCaptureDeviceCaptureMethod.py +++ b/src/capture_method/VideoCaptureDeviceCaptureMethod.py @@ -38,7 +38,8 @@ class VideoCaptureDeviceCaptureMethod(CaptureMethodBase): name = "Video Capture Device" short_description = "see below" description = ( - "\nUses a Video Capture Device, like a webcam, virtual cam, or capture card. " + "\nYou can select one below. " + "\nUses a Video Capture Device, like a webcam, virtual cam, or capture card. " # fmt: skip + + "\nYou can select one below. " ) capture_device: cv2.VideoCapture diff --git a/src/capture_method/WindowsGraphicsCaptureMethod.py b/src/capture_method/WindowsGraphicsCaptureMethod.py index caa93a04..79610c40 100644 --- a/src/capture_method/WindowsGraphicsCaptureMethod.py +++ b/src/capture_method/WindowsGraphicsCaptureMethod.py @@ -154,5 +154,7 @@ def recover_window(self, captured_window_title: str): @override def check_selected_region_exists(self): return bool( - is_valid_hwnd(self._autosplit_ref.hwnd) and self.frame_pool and self.session, + is_valid_hwnd(self._autosplit_ref.hwnd) # fmt: skip + and self.frame_pool + and self.session, ) diff --git a/src/capture_method/__init__.py b/src/capture_method/__init__.py index c8c7a6dd..a0740f10 100644 --- a/src/capture_method/__init__.py +++ b/src/capture_method/__init__.py @@ -241,10 +241,14 @@ async def get_camera_info(index: int, device_name: str): # video_capture.release() resolution = get_input_device_resolution(index) - return CameraInfo(index, device_name, False, backend, resolution) if resolution is not None else None + return ( + CameraInfo(index, device_name, False, backend, resolution) # fmt: skip + if resolution is not None + else None + ) return [ camera_info - for camera_info in await asyncio.gather(*starmap(get_camera_info, enumerate(named_video_inputs))) + for camera_info in await asyncio.gather(*starmap(get_camera_info, enumerate(named_video_inputs))) # fmt: skip if camera_info is not None ] diff --git a/src/compare.py b/src/compare.py index d79c6b41..26611805 100644 --- a/src/compare.py +++ b/src/compare.py @@ -45,7 +45,9 @@ def compare_l2_norm(source: MatLike, capture: MatLike, mask: MatLike | None = No # The L2 Error is summed across all pixels, so this normalizes max_error = ( - sqrt(source.size) * MAXBYTE if not is_valid_image(mask) else sqrt(cv2.countNonZero(mask) * MASK_SIZE_MULTIPLIER) + sqrt(source.size) * MAXBYTE # fmt: skip + if not is_valid_image(mask) + else sqrt(cv2.countNonZero(mask) * MASK_SIZE_MULTIPLIER) ) if not max_error: @@ -69,7 +71,11 @@ def compare_template(source: MatLike, capture: MatLike, mask: MatLike | None = N # matchTemplate returns the sum of square differences, this is the max # that the value can be. Used for normalizing from 0 to 1. - max_error = (source.size * MAXBYTE * MAXBYTE) if not is_valid_image(mask) else cv2.countNonZero(mask) + max_error = ( + source.size * MAXBYTE * MAXBYTE # fmt: skip + if not is_valid_image(mask) + else cv2.countNonZero(mask) + ) return 1 - (min_val / max_error) diff --git a/src/hotkeys.py b/src/hotkeys.py index c8892012..895ea398 100644 --- a/src/hotkeys.py +++ b/src/hotkeys.py @@ -100,7 +100,10 @@ def _send_hotkey(hotkey_or_scan_code: int | str | None): # Deal with regular inputs # If an int or does not contain the following strings - if isinstance(hotkey_or_scan_code, int) or not any(key in hotkey_or_scan_code for key in ("num ", "decimal", "+")): + if ( + isinstance(hotkey_or_scan_code, int) # fmt: skip + or not any(key in hotkey_or_scan_code for key in ("num ", "decimal", "+")) + ): keyboard.send(hotkey_or_scan_code) return @@ -109,7 +112,10 @@ def _send_hotkey(hotkey_or_scan_code: int | str | None): # keyboard also has issues with capitalization modifier (shift+A) # keyboard.send(keyboard.key_to_scan_codes(key_or_scan_code)[1]) pyautogui.hotkey( - *["+" if key == "plus" else key for key in hotkey_or_scan_code.replace(" ", "").split("+")], + *[ + "+" if key == "plus" else key # fmt: skip + for key in hotkey_or_scan_code.replace(" ", "").split("+") + ], ) @@ -132,7 +138,9 @@ def __validate_keypad(expected_key: str, keyboard_event: keyboard.KeyboardEvent) if keyboard_event.name and is_digit(keyboard_event.name[-1]): # Prevent "regular numbers" and "keypad numbers" from activating each other return bool( - keyboard_event.is_keypad if expected_key.startswith("num ") else not keyboard_event.is_keypad, + keyboard_event.is_keypad # fmt: skip + if expected_key.startswith("num ") + else not keyboard_event.is_keypad, ) # Prevent "keypad action keys" from triggering "regular numbers" and "keypad numbers" @@ -156,7 +164,11 @@ def __get_key_name(keyboard_event: keyboard.KeyboardEvent): # Normally this is done by keyboard.get_hotkey_name. But our code won't always get there. if event_name == "+": return "plus" - return f"num {keyboard_event.name}" if keyboard_event.is_keypad and is_digit(keyboard_event.name) else event_name + return ( + f"num {keyboard_event.name}" # fmt: skip + if keyboard_event.is_keypad and is_digit(keyboard_event.name) + else event_name + ) def __get_hotkey_name(names: list[str]): @@ -235,7 +247,10 @@ def toggle_auto_reset_image(): def is_valid_hotkey_name(hotkey_name: str): - return any(key and not keyboard.is_modifier(keyboard.key_to_scan_codes(key)[0]) for key in hotkey_name.split("+")) + return any( + key and not keyboard.is_modifier(keyboard.key_to_scan_codes(key)[0]) # fmt: skip + for key in hotkey_name.split("+") + ) # TODO: using getattr/setattr is NOT a good way to go about this. It was only temporarily done to diff --git a/src/split_parser.py b/src/split_parser.py index 87549881..09f6496e 100644 --- a/src/split_parser.py +++ b/src/split_parser.py @@ -175,7 +175,7 @@ def __pop_image_type(split_image: list[AutoSplitImage], image_type: ImageType): def parse_and_validate_images(autosplit: "AutoSplit"): # Get split images all_images = [ - AutoSplitImage(os.path.join(autosplit.settings_dict["split_image_directory"], image_name)) + AutoSplitImage(os.path.join(autosplit.settings_dict["split_image_directory"], image_name)) # fmt: skip for image_name in os.listdir(autosplit.settings_dict["split_image_directory"]) ] @@ -187,11 +187,19 @@ def parse_and_validate_images(autosplit: "AutoSplit"): error_message: Callable[[], object] | None = None # If there is no start hotkey set but a Start Image is present, and is not auto controlled, throw an error. - if start_image and not autosplit.settings_dict["split_hotkey"] and not autosplit.is_auto_controlled: + if ( + start_image # fmt: skip + and not autosplit.settings_dict["split_hotkey"] + and not autosplit.is_auto_controlled + ): error_message = error_messages.load_start_image # If there is no reset hotkey set but a Reset Image is present, and is not auto controlled, throw an error. - elif reset_image and not autosplit.settings_dict["reset_hotkey"] and not autosplit.is_auto_controlled: + elif ( + reset_image # fmt: skip + and not autosplit.settings_dict["reset_hotkey"] + and not autosplit.is_auto_controlled + ): error_message = error_messages.reset_hotkey # Make sure that each of the images follows the guidelines for correct format diff --git a/src/user_profile.py b/src/user_profile.py index 047161d8..2218f9d9 100644 --- a/src/user_profile.py +++ b/src/user_profile.py @@ -190,7 +190,11 @@ def load_settings(autosplit: "AutoSplit", from_path: str = ""): def load_settings_on_open(autosplit: "AutoSplit"): - settings_files = [file for file in os.listdir(auto_split_directory) if file.endswith(".toml")] + settings_files = [ + file # fmt: skip + for file in os.listdir(auto_split_directory) + if file.endswith(".toml") + ] # Find all .tomls in AutoSplit folder, error if there is not exactly 1 error = None