How to use the uiautomation.Logger.ColorfullyWrite 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_help_demo.py View on Github external
def DemoEN():
    """for other language"""
    thisWindow = auto.GetConsoleWindow()
    auto.Logger.ColorfullyWrite('I will run cmd\n\n')
    time.sleep(3)

    auto.SendKeys('{Win}r')
    while not isinstance(auto.GetFocusedControl(), auto.EditControl):
        time.sleep(1)
    auto.SendKeys('cmd{Enter}')
    cmdWindow = auto.WindowControl(SubName = 'cmd.exe')
    rect = cmdWindow.BoundingRectangle
    auto.DragDrop(rect.left + 50, rect.top + 10, 50, 10)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('I will run Notepad and type Hello!!!\n\n')
    time.sleep(3)

    subprocess.Popen('notepad')
    notepadWindow = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad')
    cx, cy = auto.GetScreenSize()
    notepadWindow.MoveWindow(cx // 2, 20, cx // 2, cy // 2)
    time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)

    dir = os.path.dirname(__file__)
    scriptPath = os.path.abspath(os.path.join(dir, '..\\automation.py'))

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -h" to display the help\n\n')
    time.sleep(3)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
auto.Logger.ColorfullyWrite('I will run Notepad and type Hello!!!\n\n')
    time.sleep(3)

    subprocess.Popen('notepad')
    notepadWindow = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad')
    cx, cy = auto.GetScreenSize()
    notepadWindow.MoveWindow(cx // 2, 20, cx // 2, cy // 2)
    time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)

    dir = os.path.dirname(__file__)
    scriptPath = os.path.abspath(os.path.join(dir, '..\\automation.py'))

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -h" to display the help\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -h'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -r -d1" to display the top level windows, desktop\'s children\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -r -d1 -t0'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -c" to display the control under mouse cursor\n\n')
    time.sleep(3)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
checkBox = optionTab.CheckBoxControl(AutomationId = '104')
    if checkBox.GetTogglePattern().ToggleState != auto.ToggleState.On:
        checkBox.Click()
    optionWindow.TabItemControl(SubName = '布局').Click()
    layoutTab = optionWindow.PaneControl(SubName = '布局')
    layoutTab.EditControl(AutomationId='301').GetValuePattern().SetValue('300')
    layoutTab.EditControl(AutomationId='303').GetValuePattern().SetValue('3000')
    layoutTab.EditControl(AutomationId='305').GetValuePattern().SetValue('140')
    layoutTab.EditControl(AutomationId='307').GetValuePattern().SetValue('30')
    optionWindow.ButtonControl(AutomationId = '1').Click()
    cmdWindow.SetActive()
    rect = cmdWindow.BoundingRectangle
    auto.DragDrop(rect.left + 50, rect.top + 10, 50, 30)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('我将运行记事本并输入Hello!!!\n\n')
    time.sleep(3)

    subprocess.Popen('notepad')
    notepadWindow = auto.WindowControl(searchDepth = 1, ClassName = 'Notepad')
    cx, cy = auto.GetScreenSize()
    notepadWindow.MoveWindow(cx // 2, 20, cx // 2, cy // 2)
    time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)

    dir = os.path.dirname(__file__)
    scriptPath = os.path.abspath(os.path.join(dir, '..\\automation.py'))

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('运行"automation.py -h"显示帮助\n\n')
    time.sleep(3)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
time.sleep(0.5)
    notepadWindow.EditControl().SendKeys('Hello!!!', 0.05)
    time.sleep(1)

    dir = os.path.dirname(__file__)
    scriptPath = os.path.abspath(os.path.join(dir, '..\\automation.py'))

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -h" to display the help\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -h'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -r -d1" to display the top level windows, desktop\'s children\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -r -d1 -t0'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -c" to display the control under mouse cursor\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -c -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)
    cmdWindow.SetActive(waitTime = 2)

    thisWindow.SetActive()
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
def DemoCN():
    """for Chinese language"""
    thisWindow = auto.GetConsoleWindow()
    auto.Logger.ColorfullyWrite('我将运行cmd并设置它的屏幕缓冲区使cmd一行能容纳很多字符\n\n')
    time.sleep(3)

    auto.SendKeys('{Win}r')
    while not isinstance(auto.GetFocusedControl(), auto.EditControl):
        time.sleep(1)
    auto.SendKeys('cmd{Enter}')
    cmdWindow = auto.WindowControl(RegexName = '.+cmd.exe')
    cmdWindow.TitleBarControl().RightClick()
    auto.SendKey(auto.Keys.VK_P)
    optionWindow = cmdWindow.WindowControl(SubName = '属性')
    optionWindow.TabItemControl(SubName = '选项').Click()
    optionTab = optionWindow.PaneControl(SubName = '选项')
    checkBox = optionTab.CheckBoxControl(AutomationId = '103')
    if checkBox.GetTogglePattern().ToggleState != auto.ToggleState.On:
        checkBox.Click()
    checkBox = optionTab.CheckBoxControl(AutomationId = '104')
github yinkaisheng / Python-UIAutomation-for-Windows / scripts / automation.py View on Github external
def usage():
    auto.Logger.ColorfullyWrite("""usage
-h      show command help
-t      delay time, default 3 seconds, begin to enumerate after Value seconds, this must be an integer
        you can delay a few seconds and make a window active so automation can enumerate the active window
-d      enumerate tree depth, this must be an integer, if it is null, enumerate the whole tree
-r      enumerate from root:Desktop window, if it is null, enumerate from foreground window
-f      enumerate from focused control, if it is null, enumerate from foreground window
-c      enumerate the control under cursor, if depth is < 0, enumerate from its ancestor up to depth
-a      show ancestors of the control under cursor
-n      show control full name, if it is null, show first 30 characters of control's name in console,
        always show full name in log file @AutomationLog.txt

if UnicodeError or LookupError occurred when printing,
try to change the active code page of console window by using chcp or see the log file @AutomationLog.txt
chcp, get current active code page
chcp 936, set active code page to gbk
chcp 65001, set active code page to utf-8
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
cmdWindow.SendKeys('"{}" -r -d1 -t0'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('运行"automation.py -c"显示鼠标光标下的控件\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -c -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)
    cmdWindow.SetActive(waitTime = 2)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('运行"automation.py -a"显示鼠标光标下的控件和它的所有父控件\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -a -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)
    cmdWindow.SetActive(waitTime = 2)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('运行"automation.py"显示当前激活窗口和它的所有子控件\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.EditControl().Click()
    time.sleep(3)
github yinkaisheng / Python-UIAutomation-for-Windows / demos / automation_help_demo.py View on Github external
thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -h" to display the help\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -h'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -r -d1" to display the top level windows, desktop\'s children\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -r -d1 -t0'.format(scriptPath) + '{Enter}', 0.05)
    time.sleep(3)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -c" to display the control under mouse cursor\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -c -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)
    cmdWindow.SetActive(waitTime = 2)

    thisWindow.SetActive()
    auto.Logger.ColorfullyWrite('run "automation.py -a" to display the control under mouse cursor and its ancestors\n\n')
    time.sleep(3)

    cmdWindow.SendKeys('"{}" -a -t3'.format(scriptPath) + '{Enter}', 0.05)
    notepadWindow.SetActive()
    notepadWindow.MoveCursorToMyCenter()
    time.sleep(3)