Skip to content

Commit

Permalink
Ruff unnacceptable changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Feb 3, 2024
1 parent 03ff5ca commit 8325013
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 79 deletions.
19 changes: 4 additions & 15 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/capture_method/DesktopDuplicationCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 1 addition & 2 deletions src/capture_method/ScrotCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/capture_method/VideoCaptureDeviceCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/capture_method/WindowsGraphicsCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
9 changes: 2 additions & 7 deletions src/capture_method/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
10 changes: 2 additions & 8 deletions src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

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

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


Expand All @@ -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"
Expand All @@ -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]):
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 3 additions & 12 deletions src/split_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8325013

Please sign in to comment.