ethercat-linux/uia_explore.py

36 lines
1.1 KiB
Python
Raw Permalink Normal View History

import sys, time
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
from pywinauto import Application
app = Application(backend='uia').connect(process=1456, timeout=10)
win = app.window(title_re='.*TcXaeShell.*')
win.set_focus()
print('window:', win.window_text())
def dump(el, depth=0, maxdepth=4):
if depth > maxdepth:
return
try:
ct = el.friendly_class_name()
nm = el.window_text()
if nm or ct in ('TreeView', 'TreeItem', 'ComboBox', 'Edit', 'Button', 'Tab', 'TabItem', 'DataGrid', 'ListItem', 'ListView', 'Document'):
# print everything actually, tree is big; filter noise
pass
print(' ' * depth + f"[{ct}] '{nm}'")
except Exception:
return
try:
for ch in el.children():
dump(ch, depth + 1, maxdepth)
except Exception:
pass
# find all TreeViews in the window
trees = win.descendants(control_type='Tree')
print(f'found {len(trees)} tree controls')
for t in trees:
try:
print('tree:', t.friendly_class_name(), '| items:', [i.window_text() for i in t.children()][:10])
except Exception as e:
print('tree err:', e)