Skip to content

Commit 3629100

Browse files
committed
Replace ctypes by existing pywin32 functions
1 parent cf2d63f commit 3629100

7 files changed

+16
-21
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,5 @@ reportFunctionMemberAccess = "none"
177177
reportUnnecessaryComparison = "warning"
178178
# Using Flake8/Ruff instead
179179
reportUnusedImport = "none"
180-
# numpy has way too many complex types that triggers this
180+
# pywin32 has way too many Unknown parameters left
181181
reportUnknownMemberType = "none"

src/AutoSplit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python3
2-
import ctypes
32
import os
43
import signal
54
import sys
@@ -17,6 +16,7 @@
1716
from PySide6.QtTest import QTest
1817
from PySide6.QtWidgets import QApplication, QFileDialog, QLabel, QMainWindow, QMessageBox
1918
from typing_extensions import override
19+
from win32comext.shell import shell as shell32
2020

2121
import error_messages
2222
import user_profile
@@ -55,7 +55,7 @@
5555
# Needed when compiled, along with the custom hook-requests PyInstaller hook
5656
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
5757
myappid = f"Toufool.AutoSplit.v{AUTOSPLIT_VERSION}"
58-
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
58+
shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
5959

6060

6161
class AutoSplit(QMainWindow, design.Ui_MainWindow):

src/capture_method/BitBltCaptureMethod.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import ctypes
2-
import ctypes.wintypes
32

43
import numpy as np
54
import pywintypes
65
import win32con
6+
import win32gui
77
import win32ui
88
from cv2.typing import MatLike
99
from typing_extensions import override
10-
from win32 import win32gui
1110

1211
from capture_method.CaptureMethodBase import CaptureMethodBase
1312
from utils import BGRA_CHANNEL_COUNT, get_window_bounds, is_valid_hwnd, try_delete_dc

src/capture_method/DesktopDuplicationCaptureMethod.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import ctypes
21
from typing import TYPE_CHECKING, cast
32

43
import cv2
54
import d3dshot
5+
import win32api
66
import win32con
7+
import win32gui
78
from cv2.typing import MatLike
89
from typing_extensions import override
9-
from win32 import win32gui
1010

1111
from capture_method.BitBltCaptureMethod import BitBltCaptureMethod
1212
from utils import GITHUB_REPOSITORY, get_window_bounds
@@ -37,7 +37,7 @@ def __init__(self, autosplit: "AutoSplit"):
3737
def get_frame(self):
3838
selection = self._autosplit_ref.settings_dict["capture_region"]
3939
hwnd = self._autosplit_ref.hwnd
40-
hmonitor = ctypes.windll.user32.MonitorFromWindow(hwnd, win32con.MONITOR_DEFAULTTONEAREST)
40+
hmonitor = win32api.MonitorFromWindow(hwnd, win32con.MONITOR_DEFAULTTONEAREST)
4141
if not hmonitor or not self.check_selected_region_exists():
4242
return None
4343

src/capture_method/WindowsGraphicsCaptureMethod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from typing import TYPE_CHECKING, cast
33

44
import numpy as np
5+
import win32gui
56
from cv2.typing import MatLike
67
from typing_extensions import override
7-
from win32 import win32gui
88
from winsdk.windows.graphics import SizeInt32
99
from winsdk.windows.graphics.capture import Direct3D11CaptureFramePool, GraphicsCaptureSession
1010
from winsdk.windows.graphics.capture.interop import create_for_window

src/region_selection.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import ctypes
2-
import ctypes.wintypes
31
import os
42
from math import ceil
5-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, cast
64

75
import cv2
86
import numpy as np
7+
import win32api
8+
import win32gui
99
from cv2.typing import MatLike
1010
from PySide6 import QtCore, QtGui, QtWidgets
1111
from PySide6.QtTest import QTest
1212
from pywinctl import getTopWindowAt
1313
from typing_extensions import override
14-
from win32 import win32gui
1514
from win32con import SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN
1615
from winsdk._winrt import initialize_with_window
1716
from winsdk.windows.foundation import AsyncStatus, IAsyncOperation
@@ -29,9 +28,6 @@
2928
is_valid_image,
3029
)
3130

32-
user32 = ctypes.windll.user32
33-
34-
3531
if TYPE_CHECKING:
3632
from AutoSplit import AutoSplit
3733

@@ -298,10 +294,10 @@ def __init__(self):
298294
super().__init__()
299295
# We need to pull the monitor information to correctly draw the geometry covering all portions
300296
# of the user's screen. These parameters create the bounding box with left, top, width, and height
301-
x = user32.GetSystemMetrics(SM_XVIRTUALSCREEN)
302-
y = user32.GetSystemMetrics(SM_YVIRTUALSCREEN)
303-
width = user32.GetSystemMetrics(SM_CXVIRTUALSCREEN)
304-
height = user32.GetSystemMetrics(SM_CYVIRTUALSCREEN)
297+
x = cast(int, win32api.GetSystemMetrics(SM_XVIRTUALSCREEN))
298+
y = cast(int, win32api.GetSystemMetrics(SM_YVIRTUALSCREEN))
299+
width = cast(int, win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN))
300+
height = cast(int, win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN))
305301
self.setGeometry(x, y, width, height)
306302
self.setFixedSize(width, height) # Prevent move/resizing on Linux
307303
self.setWindowTitle(type(self).__name__)

src/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from threading import Thread
1111
from typing import TYPE_CHECKING, Any, TypeGuard, TypeVar
1212

13+
import win32gui
1314
import win32ui
1415
from cv2.typing import MatLike
15-
from win32 import win32gui
1616
from winsdk.windows.ai.machinelearning import LearningModelDevice, LearningModelDeviceKind
1717
from winsdk.windows.media.capture import MediaCapture
1818

0 commit comments

Comments
 (0)