From 832501326d4455248a14a47ffa95b1e224f50e41 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 2 Feb 2024 19:44:19 -0500 Subject: [PATCH] Ruff unnacceptable changes --- src/AutoSplit.py | 19 +++---------- .../DesktopDuplicationCaptureMethod.py | 4 +-- src/capture_method/ScrotCaptureMethod.py | 3 +- .../VideoCaptureDeviceCaptureMethod.py | 3 +- .../WindowsGraphicsCaptureMethod.py | 4 +-- src/capture_method/__init__.py | 9 ++---- src/compare.py | 10 ++----- src/hotkeys.py | 28 ++++--------------- src/split_parser.py | 15 ++-------- src/user_profile.py | 6 +--- 10 files changed, 22 insertions(+), 79 deletions(-) diff --git a/src/AutoSplit.py b/src/AutoSplit.py index c3a98e48..5643d40e 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -127,8 +127,7 @@ 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}" + (" (externally controlled)" if self.is_auto_controlled else ""), ) # Hotkeys need to be initialized to be passed as thread arguments in hotkeys.py @@ -441,10 +440,7 @@ 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 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.""" @@ -508,10 +504,7 @@ 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 or (not self.start_auto_splitter_button.isEnabled() and not self.is_auto_controlled): return start_label = self.start_image_status_value_label.text() @@ -544,11 +537,7 @@ 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)) 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 de57f13d..8a4bfc31 100644 --- a/src/capture_method/DesktopDuplicationCaptureMethod.py +++ b/src/capture_method/DesktopDuplicationCaptureMethod.py @@ -47,9 +47,7 @@ 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 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 20ed9375..9b95c79d 100644 --- a/src/capture_method/ScrotCaptureMethod.py +++ b/src/capture_method/ScrotCaptureMethod.py @@ -19,8 +19,7 @@ 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. " + "\nLeaves behind a screenshot file if interrupted. " ) @override diff --git a/src/capture_method/VideoCaptureDeviceCaptureMethod.py b/src/capture_method/VideoCaptureDeviceCaptureMethod.py index 1b11d2e3..b3198e92 100644 --- a/src/capture_method/VideoCaptureDeviceCaptureMethod.py +++ b/src/capture_method/VideoCaptureDeviceCaptureMethod.py @@ -38,8 +38,7 @@ 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. " + "\nYou can select one below. " ) capture_device: cv2.VideoCapture diff --git a/src/capture_method/WindowsGraphicsCaptureMethod.py b/src/capture_method/WindowsGraphicsCaptureMethod.py index 3ef3b984..caa93a04 100644 --- a/src/capture_method/WindowsGraphicsCaptureMethod.py +++ b/src/capture_method/WindowsGraphicsCaptureMethod.py @@ -154,7 +154,5 @@ 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) and self.frame_pool and self.session, ) diff --git a/src/capture_method/__init__.py b/src/capture_method/__init__.py index 8569a197..c8c7a6dd 100644 --- a/src/capture_method/__init__.py +++ b/src/capture_method/__init__.py @@ -241,15 +241,10 @@ 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) 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))) if camera_info is not None ] diff --git a/src/compare.py b/src/compare.py index 49bec7e6..d79c6b41 100644 --- a/src/compare.py +++ b/src/compare.py @@ -45,9 +45,7 @@ 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 if not is_valid_image(mask) else sqrt(cv2.countNonZero(mask) * MASK_SIZE_MULTIPLIER) ) if not max_error: @@ -71,11 +69,7 @@ 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) 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 e803e4db..c8892012 100644 --- a/src/hotkeys.py +++ b/src/hotkeys.py @@ -100,10 +100,7 @@ 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) or not any(key in hotkey_or_scan_code for key in ("num ", "decimal", "+")): keyboard.send(hotkey_or_scan_code) return @@ -112,11 +109,7 @@ 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 for key in hotkey_or_scan_code.replace(" ", "").split("+")], ) @@ -139,9 +132,7 @@ 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 if expected_key.startswith("num ") else not keyboard_event.is_keypad, ) # Prevent "keypad action keys" from triggering "regular numbers" and "keypad numbers" @@ -165,11 +156,7 @@ 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}" if keyboard_event.is_keypad and is_digit(keyboard_event.name) else event_name def __get_hotkey_name(names: list[str]): @@ -248,11 +235,8 @@ 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]) 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 # reduce duplicated code. We should use a dictionary of hotkey class or something. diff --git a/src/split_parser.py b/src/split_parser.py index acdf6dd7..87549881 100644 --- a/src/split_parser.py +++ b/src/split_parser.py @@ -176,8 +176,7 @@ def parse_and_validate_images(autosplit: "AutoSplit"): # Get split images all_images = [ AutoSplitImage(os.path.join(autosplit.settings_dict["split_image_directory"], image_name)) - for image_name - in os.listdir(autosplit.settings_dict["split_image_directory"]) + for image_name in os.listdir(autosplit.settings_dict["split_image_directory"]) ] # Find non-split images and then remove them from the list @@ -188,19 +187,11 @@ 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 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 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 3780e18e..047161d8 100644 --- a/src/user_profile.py +++ b/src/user_profile.py @@ -190,11 +190,7 @@ 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 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