-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ec8b1f
commit 97a9eba
Showing
2 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,75 @@ | ||
from loguru import logger | ||
import pygetwindow as pgw | ||
|
||
|
||
import pywinauto | ||
from pywinauto import Desktop | ||
import time | ||
from pprint import pprint | ||
def get_active_window_state(): | ||
meta = get_active_window_meta() | ||
title = meta.title | ||
geometry = meta.box | ||
left, top, width, height = geometry | ||
active_window = get_active_window() | ||
meta = get_active_window_meta(active_window) | ||
data = get_window_data(active_window) | ||
state = { | ||
"title": title, | ||
"left": left, | ||
"top": top, | ||
"width": width, | ||
"height": height, | ||
"title": meta['texts'][0], | ||
"left": meta['rectangle'].left, | ||
"top": meta['rectangle'].top, | ||
"width": meta['rectangle'].width(), | ||
"height": meta['rectangle'].height(), | ||
# TODO: get window state; see: | ||
# https://github.com/MLDSAI/OpenAdapt/issues/75#issuecomment-1536762953 | ||
"meta": None, | ||
"meta": meta, | ||
"data": None, | ||
"window_id": None, | ||
"window_id": meta['control_id'], | ||
} | ||
return state | ||
|
||
def get_active_window_meta() : | ||
window = pgw.getActiveWindow() | ||
if not window: | ||
logger.warning(f"{window=}") | ||
def get_active_window_meta(active_window) : | ||
if not active_window: | ||
logger.warning(f"{active_window=}") | ||
return None | ||
return window | ||
logger.info(f"{active_window.get_properties()}=") | ||
return active_window.get_properties() | ||
|
||
def get_element_at_position(x, y): | ||
# TODO | ||
return None | ||
|
||
def get_active_window(): | ||
app = pywinauto.application.Application(backend="uia").connect(active_only=True) | ||
window = app.active() | ||
logger.info(f"{window=}") | ||
return window | ||
|
||
|
||
def get_window_data(active_window): | ||
state = get_descendants_info(active_window) | ||
logger.info(f"{state=}") | ||
#state = window.dump_window() | ||
return state | ||
|
||
def get_descendants_info(window): | ||
result = [] | ||
for child in window.descendants(): | ||
properties = child.get_properties() | ||
info = { | ||
'friendly classname': properties.get('friendly classname'), | ||
'texts': properties.get('texts'), | ||
'rectangle': properties.get('rectangle') | ||
} | ||
descendants = get_descendants_info(child) # Recursively get descendants of the current child | ||
if descendants: | ||
info['descendants'] = descendants | ||
result.append(info) | ||
return result | ||
|
||
def main(): | ||
import pickle | ||
import time | ||
time.sleep(1) | ||
|
||
state = get_active_window_state() | ||
pprint(state) | ||
pickle.dumps(state) | ||
import ipdb; ipdb.set_trace() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |