How to use the uiautomation.GetRootControl function in uiautomation

To help you get started, we’ve selected a few uiautomation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_wireshark_qt5.py View on Github external
def walk():
    wiresharkWindow = None
    for win in auto.GetRootControl().GetChildren():
        if win.ClassName == 'MainWindow' and win.AutomationId == 'MainWindow':
            if win.ToolBarControl(AutomationId='MainWindow.displayFilterToolBar').Exists(0, 0):
                wiresharkWindow = win
                break
    if not wiresharkWindow:
        auto.Logger.WriteLine('Can not find Wireshark', auto.ConsoleColor.Yellow)
        return

    console = auto.GetConsoleWindow()
    if console:
        sx, sy = auto.GetScreenSize()
        tp = console.GetTransformPattern()
        tp.Resize(sx, sy // 4)
        tp.Move(0, sy - sy // 4 - 50)
        console.SetTopmost()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / uiautomation_in_thread.py View on Github external
def main():
    main = threading.currentThread()
    auto.Logger.WriteLine('This is running in main thread. {} {}'.format(main.ident, main.name), auto.ConsoleColor.Cyan)
    time.sleep(2)
    auto.GetConsoleWindow().CaptureToImage('console_mainthread.png')
    root = auto.GetRootControl()
    auto.EnumAndLogControl(root, 1)
    th = threading.Thread(target=threadFunc, args=(root, ))
    th.start()
    th.join()
    auto.Logger.WriteLine('\nMain thread exits. {} {}'.format(main.ident, main.name), auto.ConsoleColor.Cyan)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / capture_screen.py View on Github external
def main(args):
    if args.time > 0:
        time.sleep(args.time)
    start = time.time()
    if args.active:
        c = auto.GetForegroundControl()
        CaptureControl(c, args.path, args.up)
    elif args.cursor:
        c = auto.ControlFromCursor()
        CaptureControl(c, args.path, args.up)
    elif args.fullscreen:
        c = auto.GetRootControl()
        rects = auto.GetMonitorsRect()
        dot = args.path.rfind('.')
        for i, rect in enumerate(rects):
            path = args.path[:dot] + '_' * i + args.path[dot:]
            c.CaptureToImage(path, rect.left, rect.top, rect.width(), rect.height())
            auto.Logger.WriteLine('capture image: ' + path)
    auto.Logger.WriteLine('cost time: {:.3f} s'.format(time.time() - start))
github yinkaisheng / Python-UIAutomation-for-Windows / demos / capture_screen.py View on Github external
def CaptureControl(c, path, up = False):
    if c.CaptureToImage(path):
        auto.Logger.WriteLine('capture image: ' + path)
    else:
        auto.Logger.WriteLine('capture failed', auto.ConsoleColor.Yellow)
    if up:
        r = auto.GetRootControl()
        depth = 0
        name, ext = os.path.splitext(path)
        while True:
            c = c.GetParentControl()
            if not c or auto.ControlsAreSame(c, r):
                break
            depth += 1
            savePath = name + '_p' * depth + ext
            if c.CaptureToImage(savePath):
                auto.Logger.WriteLine('capture image: ' + savePath)
    subprocess.Popen(path, shell = True)
github yinkaisheng / Python-UIAutomation-for-Windows / scripts / automation.py View on Github external
elif o in ('-a', '-ancestor'):
            ancestor = True
            foreground = False
        elif o in ('-n', '-showAllName'):
            showAllName = True
        elif o in ('-d', '-depth'):
            depth = int(v)
        elif o in ('-t', '-time'):
            seconds = int(v)
    if seconds > 0:
        auto.Logger.Write('please wait for {0} seconds\n\n'.format(seconds), writeToFile=False)
        time.sleep(seconds)
    auto.Logger.Log('Starts, Current Cursor Position: {}'.format(auto.GetCursorPos()))
    control = None
    if root:
        control = auto.GetRootControl()
    if focus:
        control = auto.GetFocusedControl()
    if cursor:
        control = auto.ControlFromCursor()
        if depth < 0:
            while depth < 0 and control:
                control = control.GetParentControl()
                depth += 1
            depth = 0xFFFFFFFF
    if ancestor:
        control = auto.ControlFromCursor()
        if control:
            auto.EnumAndLogControlAncestors(control, showAllName)
        else:
            auto.Logger.Write('IUIAutomation returns null element under cursor\n', auto.ConsoleColor.Yellow)
    else: