zhmiscellany 5.9.3__py3-none-any.whl → 5.9.5__py3-none-any.whl

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.
zhmiscellany/gui.py CHANGED
@@ -2,6 +2,7 @@ import tkinter as tk
2
2
  import threading
3
3
  import ctypes
4
4
  from ctypes import wintypes
5
+ import win32gui
5
6
 
6
7
 
7
8
  class StateIndicator:
@@ -176,4 +177,52 @@ class StateIndicator:
176
177
  if isinstance(xy_tuple, tuple) and len(xy_tuple) == 2 and all(isinstance(n, (int, float)) and n > 0 for n in xy_tuple):
177
178
  self._size = xy_tuple
178
179
  if self._root and self._root.winfo_exists():
179
- self._root.after(0, self._update_size_internal)
180
+ self._root.after(0, self._update_size_internal)
181
+
182
+ import ctypes
183
+ from ctypes import wintypes
184
+ user32 = ctypes.windll.user32
185
+
186
+ def get_focused_window():
187
+ """Return the window that currently has the keyboard focus."""
188
+ return user32.GetForegroundWindow()
189
+
190
+ def get_window_rect(hwnd):
191
+ """Return the bounding rectangle of a window."""
192
+ HWND = wintypes.HWND
193
+ RECT = wintypes.RECT
194
+ rect = RECT()
195
+ user32.GetWindowRect(hwnd, ctypes.byref(rect))
196
+ return rect
197
+
198
+ def set_window_pos(hwnd, x: int, y: int, w: int, h: int):
199
+ """Move (and optionally resize) a window."""
200
+ # 0x0040 == SWP_NOACTIVATE | 0x0020 == SWP_SHOWWINDOW
201
+ user32.SetWindowPos(hwnd, 0, x, y, w, h, 0x0040 | 0x0020)
202
+
203
+
204
+ def find_window_by_title_fuzzy(title_query, threshold=70):
205
+ from fuzzywuzzy import process
206
+ from fuzzywuzzy import fuzz
207
+ def enum_windows_callback(hwnd, windows):
208
+ if win32gui.IsWindowVisible(hwnd):
209
+ window_title = win32gui.GetWindowText(hwnd)
210
+ if window_title:
211
+ windows.append((hwnd, window_title))
212
+ return True
213
+
214
+ windows = []
215
+ win32gui.EnumWindows(enum_windows_callback, windows)
216
+
217
+ if not windows:
218
+ return None
219
+
220
+ titles = [title for hwnd, title in windows]
221
+ best_match = process.extractOne(title_query, titles, scorer=fuzz.token_set_ratio)
222
+
223
+ if best_match[1] >= threshold:
224
+ matched_title = best_match[0]
225
+ for hwnd, title in windows:
226
+ if title == matched_title:
227
+ return hwnd
228
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zhmiscellany
3
- Version: 5.9.3
3
+ Version: 5.9.5
4
4
  Summary: A collection of useful/interesting python libraries made by zh.
5
5
  Home-page: https://discord.gg/ThBBAuueVJ
6
6
  Author: zh
@@ -23,6 +23,7 @@ Requires-Dist: psutil>=0
23
23
  Requires-Dist: kthread>=0
24
24
  Requires-Dist: pydirectinput>=0
25
25
  Requires-Dist: pillow>=0
26
+ Requires-Dist: fuzzywuzzy>=0
26
27
 
27
28
  `zhmiscellany`,
28
29
  =
@@ -41,7 +42,7 @@ Introduction
41
42
 
42
43
  Can be installed with `pip install zhmiscellany`
43
44
 
44
- Currently, the package stands at 143 functions/classes/bindings across 15 modules.
45
+ Currently, the package stands at 147 functions/classes/bindings across 15 modules.
45
46
 
46
47
  The git repository for this package can be found [here](https://github.com/zen-ham/zhmiscellany). The docs also look nicer on github.
47
48
 
@@ -1652,3 +1653,39 @@ Sends data to a named pipe asynchronously using a background thread.
1652
1653
  A lightweight Python class that displays a customizable, semi-transparent, click-through colored rectangle overlay on the screen for visual status indication, such as if you had a complex macro/automation script and wanted to be able to see what step it's currently on.
1653
1654
 
1654
1655
  #
1656
+
1657
+ `zhmiscellany.gui.get_focused_window()`
1658
+ ---
1659
+
1660
+ `zhmiscellany.gui.get_focused_window()`
1661
+
1662
+ Return the window that currently has the keyboard focus.
1663
+
1664
+ #
1665
+
1666
+ `zhmiscellany.gui.get_window_rect()`
1667
+ ---
1668
+
1669
+ `zhmiscellany.gui.get_window_rect(hwnd)`
1670
+
1671
+ Return the bounding rectangle of a window.
1672
+
1673
+ #
1674
+
1675
+ `zhmiscellany.gui.set_window_pos()`
1676
+ ---
1677
+
1678
+ `zhmiscellany.gui.set_window_pos(hwnd, x: int, y: int, w: int, h: int)`
1679
+
1680
+ Move (and optionally resize) a window.
1681
+
1682
+ #
1683
+
1684
+ `zhmiscellany.gui.find_window_by_title_fuzzy()`
1685
+ ---
1686
+
1687
+ `zhmiscellany.gui.find_window_by_title_fuzzy(title_query, threshold=70)`
1688
+
1689
+ Find a window HWND by rough name.
1690
+
1691
+ #
@@ -9,7 +9,7 @@ zhmiscellany/cpp.py,sha256=XEUEoIKCDCdY5VgwNWE5oXrGjtsmGdz_MnaVwQmi2dk,179
9
9
  zhmiscellany/dict.py,sha256=0BZJ5eK-MurAHYV1OPa0jdGTr-QEWos7ZM0npb-tN9I,81
10
10
  zhmiscellany/discord.py,sha256=bq4fBBIykQrwBKWeJ_Ia5ZtMjP9RfRheOa7fyWZBNjo,19338
11
11
  zhmiscellany/fileio.py,sha256=KmRnWWZJWBc5Or3_mKcRY2ehE_Fuk870iS-imtyERyg,18169
12
- zhmiscellany/gui.py,sha256=VgT5j5UIr-wWyL2P1qCHSNL7RrvZWDlm0TX00JGWmKo,7404
12
+ zhmiscellany/gui.py,sha256=w1b63jt4qtnnGLImhRXJA5xkjGsKNIT65z0CmwCJgtQ,8939
13
13
  zhmiscellany/image.py,sha256=qUjxiYpc2VVZp2vwr1vN36O2PVQ7YlMKzhegQ1u4c0M,8198
14
14
  zhmiscellany/list.py,sha256=S8Z85bLJEP9lk2JkGpzUcG6kpRB7a-NWDIHMPiF5bKo,1473
15
15
  zhmiscellany/macro.py,sha256=IHkIDUgRqciD9-p9vF0j_Qfzir0mIIueax8MwQIZmOY,25996
@@ -21,7 +21,7 @@ zhmiscellany/pipes.py,sha256=PxO4aykFzC60xbTQuc66KzZYIxiW0KPebXZbncD2HcU,3795
21
21
  zhmiscellany/processing.py,sha256=sDKIbzG9TNFyT6yJ4TJL59taG-59_v3CBLekVSLrwgE,10899
22
22
  zhmiscellany/rust.py,sha256=znN6DYNoa_p-braTuDZKvUnXX8reWLFu_dG4fv2vLR0,442
23
23
  zhmiscellany/string.py,sha256=xyqE6V5YF2nieZDcg5ZrXTIrH2D9oDRbZ5vQGz8rPys,4787
24
- zhmiscellany-5.9.3.dist-info/METADATA,sha256=4QHsCH3gk8pXLyULv-PWo0ogsNiX7tbR1DkKC9nu0Sk,42655
25
- zhmiscellany-5.9.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
26
- zhmiscellany-5.9.3.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
27
- zhmiscellany-5.9.3.dist-info/RECORD,,
24
+ zhmiscellany-5.9.5.dist-info/METADATA,sha256=Vb4YxYLHU2q0X3Q6CuJv2DLANV950gIt0AQdDcDydiE,43321
25
+ zhmiscellany-5.9.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
26
+ zhmiscellany-5.9.5.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
27
+ zhmiscellany-5.9.5.dist-info/RECORD,,