Skip to content

Commit 4955237

Browse files
authored
fix(recording): specify pywinauto types as strings (#913)
1 parent 140e82e commit 4955237

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

openadapt/window/_windows.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from pprint import pprint
2+
from typing import TYPE_CHECKING
23
import pickle
34
import time
45

5-
import pywinauto
6+
if TYPE_CHECKING:
7+
import pywinauto
68

79
from openadapt.custom_logger import logger
810

@@ -53,7 +55,7 @@ def get_active_window_state(read_window_data: bool) -> dict:
5355

5456

5557
def get_active_window_meta(
56-
active_window: pywinauto.application.WindowSpecification,
58+
active_window: "pywinauto.application.WindowSpecification",
5759
) -> dict:
5860
"""Get the meta information of the active window.
5961
@@ -88,18 +90,22 @@ def get_active_element_state(x: int, y: int) -> dict:
8890
return properties
8991

9092

91-
def get_active_window() -> pywinauto.application.WindowSpecification:
93+
def get_active_window() -> "pywinauto.application.WindowSpecification":
9294
"""Get the active window object.
9395
9496
Returns:
9597
pywinauto.application.WindowSpecification: The active window object.
9698
"""
99+
import pywinauto
100+
97101
app = pywinauto.application.Application(backend="uia").connect(active_only=True)
98102
window = app.top_window()
99103
return window.wrapper_object()
100104

101105

102-
def get_element_properties(element: pywinauto.application.WindowSpecification) -> dict:
106+
def get_element_properties(
107+
element: "pywinauto.application.WindowSpecification",
108+
) -> dict:
103109
"""Recursively retrieves the properties of each element and its children.
104110
105111
Args:
@@ -132,7 +138,7 @@ def get_element_properties(element: pywinauto.application.WindowSpecification) -
132138
return properties
133139

134140

135-
def dictify_rect(rect: pywinauto.win32structures.RECT) -> dict:
141+
def dictify_rect(rect: "pywinauto.win32structures.RECT") -> dict:
136142
"""Convert a rectangle object to a dictionary.
137143
138144
Args:
@@ -150,7 +156,7 @@ def dictify_rect(rect: pywinauto.win32structures.RECT) -> dict:
150156
return rect_dict
151157

152158

153-
def get_properties(element: pywinauto.application.WindowSpecification) -> dict:
159+
def get_properties(element: "pywinauto.application.WindowSpecification") -> dict:
154160
"""Retrieves specific writable properties of an element.
155161
156162
This function retrieves a dictionary of writable properties for a given element.
@@ -168,6 +174,7 @@ class of the element may have a `get_properties()` function that raises errors.
168174
169175
"""
170176
_element_class = element.__class__
177+
import pywinauto
171178

172179
class TempElement(element.__class__):
173180
writable_props = pywinauto.base_wrapper.BaseWrapper.writable_props

0 commit comments

Comments
 (0)