Skip to content

Commit

Permalink
Update preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 18, 2024
1 parent aa05e2f commit 1750b3a
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ repos:
rev: v0.6.1 # Must match requirements-dev.txt
hooks:
- id: ruff
- id: ruff-format
args: [--fix]
- id: ruff-format

ci:
autoupdate_branch: dev
Expand Down
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"charliermarsh.ruff",
"davidanson.vscode-markdownlint",
"eamodio.gitlens",
"emeraldwalk.runonsave",
"github.vscode-github-actions",
"ms-python.python",
"ms-python.vscode-pylance",
Expand Down
3 changes: 2 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ignore = [
###
"COM812", # missing-trailing-comma
"ISC001", # single-line-implicit-string-concatenation
"RUF028", # invalid-formatter-suppression-comment, Is meant for the formatter, but false-positives

###
# Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407
Expand All @@ -80,7 +81,7 @@ ignore = [
###
# Specific to this project
###
"D205", # Not all docstrings have a short description + desrciption
"D205", # Not all docstrings have a short description + description
# TODO: Consider for more complete doc
"DOC201", # docstring-extraneous-returns
"DOC501", # docstring-missing-exception
Expand Down
12 changes: 8 additions & 4 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,9 @@ def skip_split(self, *, navigate_image_only: bool = False):
not self.is_running
or "Delayed Split" in self.current_split_image.text()
or not (
self.skip_split_button.isEnabled() or self.is_auto_controlled or navigate_image_only
self.skip_split_button.isEnabled() # fmt: skip
or self.is_auto_controlled
or navigate_image_only
)
or self.__is_current_split_out_of_range()
):
Expand Down Expand Up @@ -582,8 +584,9 @@ def reset(self):
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 ( # fmt: skip
self.is_running
or (not self.start_auto_splitter_button.isEnabled() and not self.is_auto_controlled)
):
return

Expand Down Expand Up @@ -957,7 +960,8 @@ def __update_split_image(self, specific_image: AutoSplitImage | None = None):

# Get split image
self.split_image = (
specific_image or self.split_images_and_loop_number[0 + self.split_image_number][0]
specific_image # fmt: skip
or self.split_images_and_loop_number[0 + self.split_image_number][0]
)
if self.split_image.is_ocr:
# TODO: test if setText clears a set image
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 @@ -46,7 +46,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
if display.hmonitor == hmonitor # fmt: skip
)
offset_x, offset_y, *_ = win32gui.GetWindowRect(hwnd)
offset_x -= self.desktop_duplication.display.position["left"]
Expand Down
6 changes: 5 additions & 1 deletion src/capture_method/WindowsGraphicsCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,8 @@ 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)
return bool(
is_valid_hwnd(self._autosplit_ref.hwnd) # fmt: skip
and self.frame_pool
and self.session
)
4 changes: 3 additions & 1 deletion src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ 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)
source.size * MAXBYTE * MAXBYTE # fmt: skip
if not is_valid_image(mask)
else cv2.countNonZero(mask)
)

return 1 - (min_val / max_error)
Expand Down
8 changes: 5 additions & 3 deletions src/hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ 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 ( # fmt: skip
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 @@ -133,7 +134,8 @@ 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 Down
35 changes: 16 additions & 19 deletions src/menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@

HALF_BRIGHTNESS = 128
LINUX_SCREENSHOT_SUPPORT = (
(
"\n\n----------------------------------------------------\n\n"
+ error_messages.WAYLAND_WARNING
# Keep in sync with README.md#Capture_Method_Linux
+ '\n"scrot" must be installed to use SCReenshOT. '
+ "\nRun: sudo apt-get install scrot"
)
if sys.platform == "linux"
else ""
)
"\n\n----------------------------------------------------\n\n"
+ error_messages.WAYLAND_WARNING
# Keep in sync with README.md#Capture_Method_Linux
+ '\n"scrot" must be installed to use SCReenshOT. '
+ "\nRun: sudo apt-get install scrot"
) if sys.platform == "linux" else "" # fmt: skip


class __AboutWidget(QtWidgets.QWidget, about.Ui_AboutAutoSplitWidget): # noqa: N801 # Private class
Expand Down Expand Up @@ -182,7 +178,8 @@ def __init__(self, autosplit: "AutoSplit"):
# Don't autofocus any particular field
self.setFocus()

# region Build the Capture method combobox
# region Build the Capture method combobox # fmt: skip

capture_method_values = CAPTURE_METHODS.values()
self.__set_all_capture_devices()

Expand All @@ -199,9 +196,9 @@ def __init__(self, autosplit: "AutoSplit"):
f"- {method.name} ({method.short_description})" for method in capture_method_values
])
self.capture_method_combobox.setToolTip(
"\n\n".join([
"\n\n".join(
f"{method.name} :\n{method.description}" for method in capture_method_values
])
)
+ LINUX_SCREENSHOT_SUPPORT
)
# endregion
Expand Down Expand Up @@ -229,9 +226,10 @@ def __set_value(self, key: str, value: Any):
def get_capture_device_index(self, capture_device_id: int):
"""Returns 0 if the capture_device_id is invalid."""
try:
return [device.device_id for device in self.__video_capture_devices].index(
capture_device_id
)
return [
device.device_id # fmt: skip
for device in self.__video_capture_devices
].index(capture_device_id)
except ValueError:
return 0

Expand Down Expand Up @@ -385,6 +383,7 @@ def __setup_bindings(self):
self._autosplit_ref.settings_dict["enable_auto_reset"]
)
# endregion

# region Binding
# Capture Settings
self.fps_limit_spinbox.valueChanged.connect(self.__fps_limit_changed)
Expand Down Expand Up @@ -436,9 +435,7 @@ def __setup_bindings(self):
self.enable_auto_reset_image_checkbox.isChecked(),
)
)


# endregion
# endregion


def open_settings(autosplit: "AutoSplit"):
Expand Down
6 changes: 3 additions & 3 deletions src/region_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
"""https://docs.opencv.org/4.8.0/d4/da8/group__imgcodecs.html#imread"""
IMREAD_EXT_FILTER = (
"All Files ("
+ " ".join([f"{extensions}" for _, extensions in SUPPORTED_IMREAD_FORMATS])
+ " ".join(f"{extensions}" for _, extensions in SUPPORTED_IMREAD_FORMATS)
+ ");;"
+ ";;".join([
+ ";;".join(
f"{imread_format} ({extensions})" for imread_format, extensions in SUPPORTED_IMREAD_FORMATS
])
)
)


Expand Down
9 changes: 7 additions & 2 deletions src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def load_settings(autosplit: "AutoSplit", from_path: str = ""):
)[0]
)
if not (
load_settings_file_path and __load_settings_from_file(autosplit, load_settings_file_path)
load_settings_file_path # fmt: skip
and __load_settings_from_file(autosplit, load_settings_file_path)
):
return

Expand All @@ -198,7 +199,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
4 changes: 3 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ def run_tesseract(png: bytes):
@return: The recognized output string from tesseract.
"""
return (
subprocess.Popen(TESSERACT_CMD, **subprocess_kwargs()) # noqa: S603 # Only using known literal strings
subprocess.Popen( # noqa: S603 # Only using known literal strings
TESSERACT_CMD, **subprocess_kwargs()
)
.communicate(input=png)[0]
.decode()
)
Expand Down

0 comments on commit 1750b3a

Please sign in to comment.