Skip to content

Commit

Permalink
Revert "Ruff unnacceptable changes"
Browse files Browse the repository at this point in the history
Use `fmt: skip` comments
  • Loading branch information
Avasam committed Feb 3, 2024
1 parent 8325013 commit 92f8878
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 21 deletions.
18 changes: 14 additions & 4 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/capture_method/DesktopDuplicationCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 2 additions & 1 deletion src/capture_method/ScrotCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/capture_method/VideoCaptureDeviceCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/capture_method/WindowsGraphicsCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
8 changes: 6 additions & 2 deletions src/capture_method/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
10 changes: 8 additions & 2 deletions src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
25 changes: 20 additions & 5 deletions src/hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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("+")
],
)


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

Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92f8878

Please sign in to comment.