Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recording not working because of bug in read window data #913

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions openadapt/window/_windows.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pprint import pprint
from typing import TYPE_CHECKING
import pickle
import time

import pywinauto
if TYPE_CHECKING:
import pywinauto

from openadapt.custom_logger import logger

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


def get_active_window_meta(
active_window: pywinauto.application.WindowSpecification,
active_window: "pywinauto.application.WindowSpecification",
) -> dict:
"""Get the meta information of the active window.

Expand Down Expand Up @@ -88,18 +90,22 @@ def get_active_element_state(x: int, y: int) -> dict:
return properties


def get_active_window() -> pywinauto.application.WindowSpecification:
def get_active_window() -> "pywinauto.application.WindowSpecification":
"""Get the active window object.

Returns:
pywinauto.application.WindowSpecification: The active window object.
"""
import pywinauto

app = pywinauto.application.Application(backend="uia").connect(active_only=True)
window = app.top_window()
return window.wrapper_object()


def get_element_properties(element: pywinauto.application.WindowSpecification) -> dict:
def get_element_properties(
element: "pywinauto.application.WindowSpecification",
) -> dict:
"""Recursively retrieves the properties of each element and its children.

Args:
Expand Down Expand Up @@ -132,7 +138,7 @@ def get_element_properties(element: pywinauto.application.WindowSpecification) -
return properties


def dictify_rect(rect: pywinauto.win32structures.RECT) -> dict:
def dictify_rect(rect: "pywinauto.win32structures.RECT") -> dict:
"""Convert a rectangle object to a dictionary.

Args:
Expand All @@ -150,7 +156,7 @@ def dictify_rect(rect: pywinauto.win32structures.RECT) -> dict:
return rect_dict


def get_properties(element: pywinauto.application.WindowSpecification) -> dict:
def get_properties(element: "pywinauto.application.WindowSpecification") -> dict:
"""Retrieves specific writable properties of an element.

This function retrieves a dictionary of writable properties for a given element.
Expand All @@ -168,6 +174,7 @@ class of the element may have a `get_properties()` function that raises errors.

"""
_element_class = element.__class__
import pywinauto

class TempElement(element.__class__):
writable_props = pywinauto.base_wrapper.BaseWrapper.writable_props
Expand Down
Loading