williampy 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MrCoolGuy640
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # Include necessary files
2
+ include README.md
3
+ include LICENSE
4
+ recursive-include william *.py
5
+
6
+ # Exclude development/test files
7
+ recursive-exclude tests *
8
+ recursive-exclude examples *
9
+ recursive-exclude william __pycache__
10
+ recursive-exclude william *.pyc
11
+ recursive-exclude william *.pyo
12
+ recursive-exclude william *.pyd
13
+
14
+ # Exclude environment/config files
15
+ exclude .env
16
+ exclude .env.*
17
+ exclude *.env
18
+ exclude .private
19
+ exclude .private/*
20
+ exclude *.private
21
+ exclude .secrets
22
+ exclude .secrets/*
23
+ exclude .git*
24
+ exclude .vscode
25
+ exclude .idea
26
+ exclude build.bat
27
+ exclude upload_to_pypi.bat
28
+ exclude upload_to_pypi.py
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: williampy
3
+ Version: 0.0.1
4
+ Summary: neat python package to do many miscellaneous but helpful things
5
+ Author: MrCoolGuy640
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # William
13
+ ![PyPI](https://img.shields.io/pypi/v/williampy)
14
+
@@ -0,0 +1,3 @@
1
+ # William
2
+ ![PyPI](https://img.shields.io/pypi/v/williampy)
3
+
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "williampy"
7
+ version = "0.0.1"
8
+ description = "neat python package to do many miscellaneous but helpful things"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ { name = "MrCoolGuy640" }
14
+ ]
15
+
16
+ # No runtime dependencies
17
+ dependencies = []
18
+
19
+ [tool.setuptools]
20
+ packages = ["william"]
21
+ include-package-data = true
22
+
23
+ [tool.setuptools.package-data]
24
+ "*" = ["*.txt", "*.md"]
25
+
26
+ [tool.pytest.ini_options]
27
+ testpaths = ["tests"]
28
+ python_files = ["test_*.py"]
29
+ python_classes = ["Test*"]
30
+ python_functions = ["test_*"]
31
+
32
+ [tool.black]
33
+ line-length = 100
34
+ target-version = ['py38']
35
+
36
+ [tool.flake8]
37
+ max-line-length = 100
38
+ exclude = [".git", "__pycache__", "venv", "build", "dist", ".env", "upload_to_pypi.bat", "upload_to_pypi.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
@@ -0,0 +1,3 @@
1
+ from .image import Image
2
+
3
+ __all__ = ["Image"]
@@ -0,0 +1,67 @@
1
+ from pathlib import Path
2
+ import numpy as np
3
+ import cv2
4
+
5
+
6
+ class Image:
7
+ def __init__(self, data: np.ndarray):
8
+ self.data = data
9
+
10
+ @classmethod
11
+ def from_file(cls, path) -> "Image":
12
+ """
13
+ Load image from file.
14
+ Supports str, Path, or any path-like object.
15
+ """
16
+
17
+ path = Path(path) # supports path or str
18
+
19
+ data = cv2.imread(str(path), cv2.IMREAD_COLOR)
20
+
21
+ if data is None:
22
+ raise ValueError(f"Failed to load image: {path}")
23
+
24
+ return cls(data)
25
+
26
+ @classmethod
27
+ def from_array(cls, array: np.ndarray) -> "Image":
28
+ """
29
+ Wrap existing numpy image.
30
+ """
31
+ return cls(array)
32
+
33
+ def copy(self):
34
+ return Image(self.data.copy())
35
+
36
+ def gray(self):
37
+ """Return grayscale numpy array."""
38
+ return cv2.cvtColor(self.data, cv2.COLOR_BGR2GRAY)
39
+
40
+ def crop(self, top_ratio=0, bottom_ratio=1, left_ratio=0, right_ratio=1):
41
+ h, w = self.data.shape[:2]
42
+
43
+ y1 = int(h * top_ratio)
44
+ y2 = int(h * bottom_ratio)
45
+ x1 = int(w * left_ratio)
46
+ x2 = int(w * right_ratio)
47
+
48
+ return Image(self.data[y1:y2, x1:x2])
49
+
50
+ def compare(self, template: "Image") -> float:
51
+ """
52
+ Returns similarity score (0-1) using OpenCV matchTemplate.
53
+ """
54
+
55
+ img_gray = self.gray()
56
+ tpl_gray = template.gray()
57
+
58
+ res = cv2.matchTemplate(
59
+ img_gray,
60
+ tpl_gray,
61
+ cv2.TM_CCOEFF_NORMED
62
+ )
63
+
64
+ return float(np.max(res))
65
+
66
+ def matches(self, other: "Image", threshold=0.8) -> bool:
67
+ return self.compare(other) >= threshold
File without changes
File without changes
@@ -0,0 +1,65 @@
1
+ import win32gui
2
+ import win32ui
3
+ import numpy as np
4
+ from ctypes import windll
5
+
6
+ from william.image import Image
7
+
8
+ class Window:
9
+ """
10
+ Represents a window on the system, given its title.
11
+ Provides methods to interact with it, including capturing its contents.
12
+ """
13
+
14
+ def __init__(self, title: str):
15
+ self.title = title
16
+ self.hwnd = win32gui.FindWindow(None, title)
17
+ if not self.hwnd:
18
+ raise ValueError(f"Window with title '{title}' not found.")
19
+
20
+ def capture(self) -> np.ndarray | None:
21
+ """
22
+ Capture the window's current content as a numpy array (BGR format).
23
+ Returns None if the capture fails.
24
+ """
25
+ left, top, right, bottom = win32gui.GetWindowRect(self.hwnd)
26
+ width = right - left
27
+ height = bottom - top
28
+
29
+ hwndDC = win32gui.GetWindowDC(self.hwnd)
30
+ mfcDC = win32ui.CreateDCFromHandle(hwndDC)
31
+ saveDC = mfcDC.CreateCompatibleDC()
32
+
33
+ saveBitMap = win32ui.CreateBitmap()
34
+ saveBitMap.CreateCompatibleBitmap(mfcDC, width, height)
35
+ saveDC.SelectObject(saveBitMap)
36
+
37
+ result = windll.user32.PrintWindow(self.hwnd, saveDC.GetSafeHdc(), 2)
38
+ if result != 1:
39
+ # Cleanup resources
40
+ win32gui.DeleteObject(saveBitMap.GetHandle())
41
+ saveDC.DeleteDC()
42
+ mfcDC.DeleteDC()
43
+ win32gui.ReleaseDC(self.hwnd, hwndDC)
44
+ return None
45
+
46
+ bmpinfo = saveBitMap.GetInfo()
47
+ bmpstr = saveBitMap.GetBitmapBits(True)
48
+ img = np.frombuffer(bmpstr, dtype=np.uint8).reshape((bmpinfo['bmHeight'], bmpinfo['bmWidth'], 4))
49
+ img = img[:, :, :3] # BGRA -> BGR
50
+
51
+ # Cleanup resources
52
+ win32gui.DeleteObject(saveBitMap.GetHandle())
53
+ saveDC.DeleteDC()
54
+ mfcDC.DeleteDC()
55
+ win32gui.ReleaseDC(self.hwnd, hwndDC)
56
+
57
+ return Image(img)
58
+
59
+ def exists(self) -> bool:
60
+ """Check if the window still exists."""
61
+ return bool(win32gui.IsWindow(self.hwnd))
62
+
63
+ def get_rect(self) -> tuple[int, int, int, int]:
64
+ """Return (left, top, right, bottom) of the window."""
65
+ return win32gui.GetWindowRect(self.hwnd)
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: williampy
3
+ Version: 0.0.1
4
+ Summary: neat python package to do many miscellaneous but helpful things
5
+ Author: MrCoolGuy640
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # William
13
+ ![PyPI](https://img.shields.io/pypi/v/williampy)
14
+
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ william/__init__.py
6
+ william/image/__init__.py
7
+ william/image/image.py
8
+ william/logging/__init__.py
9
+ william/windows/__init__.py
10
+ william/windows/window.py
11
+ williampy.egg-info/PKG-INFO
12
+ williampy.egg-info/SOURCES.txt
13
+ williampy.egg-info/dependency_links.txt
14
+ williampy.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ william