Skip to content

Commit

Permalink
add serialize_rect function
Browse files Browse the repository at this point in the history
  • Loading branch information
jesicasusanto committed Jun 9, 2023
1 parent d0a0800 commit b5d9d7e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions openadapt/window/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def get_active_window_state() -> dict:
logger.warning(e)
return {}
meta = get_active_window_meta(active_window)
rectangle_str = str(meta["rectangle"])
rectangle_dict = serialize_rect(meta["rectangle"])
data = get_descendants_info(active_window)
state = {
"title": meta["texts"][0],
"left": meta["rectangle"].left,
"top": meta["rectangle"].top,
"width": meta["rectangle"].width(),
"height": meta["rectangle"].height(),
"meta": {**meta, "rectangle": rectangle_str},
"meta": {**meta, "rectangle": rectangle_dict},
"data": data,
"window_id": meta["control_id"],
}
Expand Down Expand Up @@ -80,7 +80,7 @@ def get_active_element_state(x: int, y: int):
active_window = get_active_window()
active_element = active_window.from_point(x, y)
properties = active_element.get_properties()
properties["rectangle"] = str(properties["rectangle"])
properties["rectangle"] = serialize_rect(properties["rectangle"])
return properties


Expand Down Expand Up @@ -108,15 +108,25 @@ def get_descendants_info(window):
"""

result = window.get_properties()
result["rectangle"] = str(result["rectangle"])
result["rectangle"] = serialize_rect(result["rectangle"])
result["children"] = []
for child in window.descendants():
child_properties = child.get_properties()
child_properties["rectangle"] = str(child_properties["rectangle"])
child_properties["rectangle"] = serialize_rect(child_properties["rectangle"])
result["children"].append(child_properties)
return result


def serialize_rect(rect):
serialized = {
"left": rect.left,
"top": rect.top,
"right": rect.right,
"bottom": rect.bottom,
}
return serialized


def main():
import time

Expand Down

0 comments on commit b5d9d7e

Please sign in to comment.