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: windows.get_active_window() #333

Merged
11 changes: 7 additions & 4 deletions openadapt/window/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from pprint import pprint
import pickle

import comtypes

def get_active_window_state() -> dict:
"""
Expand All @@ -28,7 +28,6 @@ def get_active_window_state() -> dict:
try:
active_window = get_active_window()
except RuntimeError as e:
logger.warning(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jesicasusanto !

Can you please clarify why this was removed?

return {}
meta = get_active_window_meta(active_window)
rectangle_dict = dictify_rect(meta["rectangle"])
Expand Down Expand Up @@ -95,7 +94,7 @@ def get_active_window(depth=10, max_width=10, filename=None) -> Desktop:
Desktop: The active window object.
"""
app = pywinauto.application.Application(backend="uia").connect(active_only=True)
window = app.active()
window = app.top_window()
return window


Expand All @@ -121,7 +120,11 @@ def get_element_properties(element):
'children': []}]}
"""

properties = element.get_properties()
try:
properties = element.get_properties()
except comtypes.COMError:
logger.warning(f"COMError occurred: {com_err}")
return {}
children = element.children()

if children:
Expand Down