Skip to content

Commit

Permalink
Merge branch 'dev' into cv2-phash
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Dec 19, 2023
2 parents a5d910f + 726adc1 commit 97d7267
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 34 deletions.
4 changes: 0 additions & 4 deletions PyInstaller/hooks/hook-requests.py

This file was deleted.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ reportMissingTypeStubs = "warning"
reportUnnecessaryComparison = "warning"
# Using Flake8/Ruff instead. Name is already grayed out and red squiggle looks like a mistyped import
reportUnusedImport = "none"
# pywin32 has way too many Unknown parameters left
reportUnknownMemberType = "none"

###
# Off by default even in strict mode
Expand Down
3 changes: 2 additions & 1 deletion scripts/compile_resources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pyside6-rcc './res/resources.qrc' -o './src/gen/resources_rc.py'
$files = Get-ChildItem ./src/gen/ *.py
foreach ($file in $files) {
(Get-Content $file.PSPath) |
ForEach-Object { $_ -replace 'import resources_rc', 'from . import resources_rc' } |
ForEach-Object { $_.replace('import resources_rc', 'from . import resources_rc') } |
ForEach-Object { $_ -replace 'def (\w+?)\(self, (\w+?)\):', 'def $1(self, $2: QWidget):' } |
Set-Content $file.PSPath
}
Write-Host 'Generated code from .ui files'
Expand Down
3 changes: 1 addition & 2 deletions scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ types-keyboard
types-psutil
types-PyAutoGUI
types-pyinstaller
types-pywin32 ; sys_platform == 'win32'
types-requests
types-pywin32>=306.0.0.8 ; sys_platform == 'win32'
types-toml
3 changes: 0 additions & 3 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Read /docs/build%20instructions.md for more information on how to install, run and build the python code.
#
# Dependencies:
certifi
git+https://github.com/boppreh/keyboard.git#egg=keyboard # Fix install on macos and linux-ci https://github.com/boppreh/keyboard/pull/568
numpy>=1.26 # Python 3.12 support
opencv-python-headless>=4.8.1.78 # Typing fixes
Expand All @@ -13,14 +12,12 @@ psutil>=5.9.6 # Python 3.12 fixes
PyWinCtl>=0.0.42 # py.typed
# When needed, dev builds can be found at https://download.qt.io/snapshots/ci/pyside/dev?C=M;O=D
PySide6-Essentials>=6.6.0 # Python 3.12 support
requests>=2.28.2 # charset_normalizer 3.x update
scipy>=1.11.2 # Python 3.12 support
toml
typing-extensions>=4.4.0 # @override decorator support
#
# Build and compile resources
pyinstaller>=5.13 # Python 3.12 support
pyinstaller-hooks-contrib>=2022.15 # charset-normalizer fix https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/534
#
# https://peps.python.org/pep-0508/#environment-markers
#
Expand Down
3 changes: 0 additions & 3 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from types import FunctionType
from typing import NoReturn

import certifi
import cv2
from cv2.typing import MatLike
from psutil import process_iter
Expand Down Expand Up @@ -52,8 +51,6 @@

CHECK_FPS_ITERATIONS = 10

# Needed when compiled, along with the custom hook-requests PyInstaller hook
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
myappid = f"Toufool.AutoSplit.v{AUTOSPLIT_VERSION}"
shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

Expand Down
9 changes: 5 additions & 4 deletions src/capture_method/BitBltCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class BitBltCaptureMethod(CaptureMethodBase):
@override
def get_frame(self) -> MatLike | None:
selection = self._autosplit_ref.settings_dict["capture_region"]
width = selection["width"]
height = selection["height"]
hwnd = self._autosplit_ref.hwnd
image: MatLike | None = None

if not self.check_selected_region_exists():
return None
Expand All @@ -57,11 +58,11 @@ def get_frame(self) -> MatLike | None:

compatible_dc = dc_object.CreateCompatibleDC()
bitmap = win32ui.CreateBitmap()
bitmap.CreateCompatibleBitmap(dc_object, selection["width"], selection["height"])
bitmap.CreateCompatibleBitmap(dc_object, width, height)
compatible_dc.SelectObject(bitmap)
compatible_dc.BitBlt(
(0, 0),
(selection["width"], selection["height"]),
(width, height),
dc_object,
(selection["x"] + left_bounds, selection["y"] + top_bounds),
win32con.SRCCOPY,
Expand All @@ -74,7 +75,7 @@ def get_frame(self) -> MatLike | None:
if is_blank(image):
image = None
else:
image.shape = (selection["height"], selection["width"], BGRA_CHANNEL_COUNT)
image.shape = (height, width, BGRA_CHANNEL_COUNT)

# Cleanup DC and handle
try_delete_dc(dc_object)
Expand Down
8 changes: 4 additions & 4 deletions src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def compare_phash(source: MatLike, capture: MatLike, mask: MatLike | None = None
return 1 - (hash_diff / 64.0)


def __compare_dummy(*_: object):
return 0.0


def get_comparison_method_by_index(comparison_method_index: int):
match comparison_method_index:
case 0:
Expand All @@ -140,10 +144,6 @@ def get_comparison_method_by_index(comparison_method_index: int):
return __compare_dummy


def __compare_dummy(*_: object):
return 0.0


def check_if_image_has_transparency(image: MatLike):
# Check if there's a transparency channel (4th channel) and if at least one pixel is transparent (< 255)
if image.shape[ImageShape.Channels] != BGRA_CHANNEL_COUNT:
Expand Down
12 changes: 7 additions & 5 deletions src/menu_bar.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import asyncio
import json
import webbrowser
from typing import TYPE_CHECKING, Any, cast
from urllib.error import URLError
from urllib.request import urlopen

import requests
from packaging.version import parse as version_parse
from PySide6 import QtCore, QtWidgets
from PySide6.QtCore import Qt
from PySide6.QtGui import QBrush, QPalette
from PySide6.QtWidgets import QFileDialog
from requests.exceptions import RequestException
from typing_extensions import override

import error_messages
Expand Down Expand Up @@ -97,10 +98,11 @@ def __init__(self, autosplit: "AutoSplit", check_on_open: bool):
@override
def run(self):
try:
response = requests.get(f"https://api.github.com/repos/{GITHUB_REPOSITORY}/releases/latest", timeout=30)
latest_version = str(response.json()["name"]).split("v")[1]
with urlopen(f"https://api.github.com/repos/{GITHUB_REPOSITORY}/releases/latest", timeout=30) as response: # noqa: S310
json_response: dict[str, str] = json.loads(response.read())
latest_version = json_response["name"].split("v")[1]
self._autosplit_ref.update_checker_widget_signal.emit(latest_version, self.check_on_open)
except (RequestException, KeyError):
except (URLError, KeyError):
if not self.check_on_open:
self._autosplit_ref.show_error_signal.emit(error_messages.check_for_updates)

Expand Down
10 changes: 5 additions & 5 deletions src/region_selection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from math import ceil
from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING

import cv2
import numpy as np
Expand Down Expand Up @@ -294,10 +294,10 @@ def __init__(self):
super().__init__()
# We need to pull the monitor information to correctly draw the geometry covering all portions
# of the user's screen. These parameters create the bounding box with left, top, width, and height
x = cast(int, win32api.GetSystemMetrics(SM_XVIRTUALSCREEN))
y = cast(int, win32api.GetSystemMetrics(SM_YVIRTUALSCREEN))
width = cast(int, win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN))
height = cast(int, win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN))
x = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)
y = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)
width = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)
height = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)
self.setGeometry(x, y, width, height)
self.setFixedSize(width, height) # Prevent move/resizing on Linux
self.setWindowTitle(type(self).__name__)
Expand Down
3 changes: 2 additions & 1 deletion src/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class UserProfileDict(TypedDict):

@override # pyright: ignore
@deprecated("Use `copy.deepcopy` instead")
def copy(): return super().copy()
def copy():
return super().copy()


DEFAULT_PROFILE = UserProfileDict(
Expand Down

0 comments on commit 97d7267

Please sign in to comment.