ethercat-linux/uia_tree.py

30 lines
755 B
Python
Raw 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.*')
tree = win.descendants(control_type='Tree')[0]
def expand_and_print(item, depth=0, maxdepth=4):
try:
name = item.window_text()
except Exception:
name = '?'
print(' ' * depth + name)
if depth >= maxdepth:
return
try:
item.expand()
time.sleep(0.3)
except Exception:
pass
try:
for ch in item.children():
expand_and_print(ch, depth + 1, maxdepth)
except Exception:
pass
for root in tree.children():
expand_and_print(root)