How to use the uiautomation.ConsoleColor 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_devicemanager.py View on Github external
cmdTransformPattern = cmdWindow.GetTransformPattern()
    cmdTransformPattern.Move(sw // 2, 0)
    cmdTransformPattern.Resize(sw // 2, sh * 3 // 4)
    subprocess.Popen('mmc.exe devmgmt.msc')
    mmcWindow = auto.WindowControl(searchDepth = 1, ClassName = 'MMCMainFrame')
    mmcTransformPattern = mmcWindow.GetTransformPattern()
    mmcTransformPattern.Move(0, 0)
    mmcTransformPattern.Resize(sw // 2, sh * 3 // 4)
    tree = mmcWindow.TreeControl()
    for item, depth in auto.WalkControl(tree, includeTop=True):
        if isinstance(item, auto.TreeItemControl):  #or item.ControlType == auto.ControlType.TreeItemControl
            item.GetSelectionItemPattern().Select(waitTime=0.05)
            pattern = item.GetExpandCollapsePattern()
            if pattern.ExpandCollapseState == auto.ExpandCollapseState.Collapsed:
                pattern.Expand(waitTime=0.05)
            auto.Logger.WriteLine(' ' * (depth - 1) * 4 + item.Name, auto.ConsoleColor.Green)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll by SetScrollPercent')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime=1)
    treeScrollPattern = tree.GetScrollPattern()
    treeScrollPattern.SetScrollPercent(auto.ScrollPattern.NoScrollValue, 0)
    treeScrollPattern.SetScrollPercent(auto.ScrollPattern.NoScrollValue, 100)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to top by SendKeys Ctrl+Home')
        cmdWindow.SetActive(waitTime=1)
    mmcWindow.SetActive(waitTime = 1)
    tree.SendKeys('{Ctrl}{Home}', waitTime = 1)
    if cmdWindow:
        auto.Logger.ColorfullyWriteLine('Scroll to bottom by SendKeys Ctrl+End')
        cmdWindow.SetActive(waitTime = 1)
    mmcWindow.SetActive(waitTime = 1)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / hide_window_with_hotkey.py View on Github external
def HotKeyFunc(stopEvent: 'Event', argv: list):
    args = [sys.executable, __file__] + argv
    cmd = ' '.join('"{}"'.format(arg) for arg in args)
    auto.Logger.WriteLine('call {}'.format(cmd))
    p = subprocess.Popen(cmd)
    while True:
        if None != p.poll():
            break
        if stopEvent.is_set():
            childProcesses = [pro for pro in psutil.process_iter() if pro.ppid == p.pid or pro.pid == p.pid]
            for pro in childProcesses:
                auto.Logger.WriteLine('kill process: {}, {}'.format(pro.pid, pro.cmdline()), auto.ConsoleColor.Yellow)
                p.kill()
            break
        stopEvent.wait(0.01)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / rename_pdf_bookmark.py View on Github external
if not isinstance(menuItem, automation.MenuItemControl):
                        break
            if find:
                break
            else:
                automation.SendKeys('{Esc}')
                time.sleep(0.5)
        if not find:
            automation.Logger.Log('this pdf not support editing')
            exit(0)
        menuItem.Click(simulateMove = False, waitTime = 0.2)
        edit = automation.EditControl(searchFromControl= tree, searchDepth= 1)
        edit.SetValue(newName, waitTime = 0.05)
        automation.SendKeys('{Enter}', waitTime = 0.05)
        automation.Logger.Write('rename: ')
        automation.Logger.WriteLine(name, automation.ConsoleColor.Green)
        automation.Logger.Write('    @@to : ' if alert else '    to: ')
        automation.Logger.WriteLine(newName, automation.ConsoleColor.Yellow if alert else automation.ConsoleColor.Green)
    if depth + 1 > TreeDepth:
        return
    if automation.ExpandCollapseState.Collapsed == treeItem.CurrentExpandCollapseState():
        treeItem.Expand(0.1)
    childItems = treeItem.GetChildren()
    if childItems:
        for child in childItems:
            RenameTreeItem(tree, child, bookMark.children, depth + 1, removeChapter)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_notepad.py View on Github external
edit.SendKeys('Image Notepad.png was captured, you will see it later.', 0.05)
    #查找菜单
    window.MenuItemControl(Name = '格式(O)').Click()
    window.MenuItemControl(Name = '字体(F)...').Click()
    windowFont = window.WindowControl(Name='字体')
    listItem = windowFont.ListControl(searchDepth=2, AutomationId='1000').ListItemControl(Name='微软雅黑')
    if listItem.Exists(2):
        listItem.GetScrollItemPattern().ScrollIntoView()
        listItem.Click()
    windowFont.ComboBoxControl(AutomationId = '1140').Select('中文 GB2312')
    windowFont.ButtonControl(Name = '确定').Click()
    window.GetWindowPattern().Close()
    if auto.WaitForDisappear(window, 3):
        auto.Logger.WriteLine("Notepad closed")
    else:
        auto.Logger.WriteLine("Notepad still exists after 3 seconds", auto.ConsoleColor.Yellow)

    # buttonNotSave = ButtonControl(searchFromControl = window, SubName = '不保存')
    # buttonNotSave.Click()
    # or send alt+n to not save and quit
    # auto.SendKeys('{Alt}n')
    # 使用另一种查找方法
    buttonNotSave = window.ButtonControl(Compare=lambda control, depth: '不保存' in control.Name or '否' in control.Name)
    buttonNotSave.Click()
    subprocess.Popen('Notepad.png', shell = True)
    time.sleep(2)
    consoleWindow.SetActive()
    auto.Logger.WriteLine('script exits', auto.ConsoleColor.Cyan)
    time.sleep(2)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / get_qq_group_members.py View on Github external
list.SendKeys('{Home}', waitTime = 1)
        for listItem in allListItems:
            if listItem.ControlType == automation.ControlType.ListItemControl:
                if automation.Win32API.IsKeyPressed(automation.Keys.VK_F10):
                    if consoleWindow:
                        consoleWindow.SetActive()
                    input('\n您暂停了脚本,按Enter继续\n')
                    qqWindow.SetActive()
                listItem.RightClick()
                menu = automation.MenuControl(searchDepth= 1, ClassName = 'TXGuiFoundation')
                menuItems = menu.GetChildren()
                for menuItem in menuItems:
                    if menuItem.Name == '查看资料':
                        menuItem.Click()
                        break
                automation.Logger.WriteLine(listItem.Name, automation.ConsoleColor.Green)
                automation.Logger.WriteLine(GetPersonDetail())
                listItem.Click()
                automation.SendKeys('{Down}')
github yinkaisheng / Python-UIAutomation-for-Windows / demos / uiautomation_in_thread.py View on Github external
If you want to use functionalities related to Controls and Patterns in a new thread.
    You must call InitializeUIAutomationInCurrentThread first in the thread
        and call UninitializeUIAutomationInCurrentThread when the thread exits.
    But you can't use use a Control or a Pattern created in a different thread.
    So you can't create a Control or a Pattern in main thread and then pass it to a new thread and use it.
    """
    #print(root)# you cannot use root because it is root control created in main thread
    th = threading.currentThread()
    auto.Logger.WriteLine('\nThis is running in a new thread. {} {}'.format(th.ident, th.name), auto.ConsoleColor.Cyan)
    time.sleep(2)
    auto.InitializeUIAutomationInCurrentThread()
    auto.GetConsoleWindow().CaptureToImage('console_newthread.png')
    newRoot = auto.GetRootControl()    #ok, root control created in new thread
    auto.EnumAndLogControl(newRoot, 1)
    auto.UninitializeUIAutomationInCurrentThread()
    auto.Logger.WriteLine('\nThread exits. {} {}'.format(th.ident, th.name), auto.ConsoleColor.Cyan)