Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def main():
import getopt
auto.Logger.Write('UIAutomation {} (Python {}.{}.{}, {} bit)\n'.format(auto.VERSION, sys.version_info.major, sys.version_info.minor, sys.version_info.micro, 64 if sys.maxsize > 0xFFFFFFFF else 32))
options, args = getopt.getopt(sys.argv[1:], 'hrfcand:t:',
['help', 'root', 'focus', 'cursor', 'ancestor', 'showAllName', 'depth=',
'time='])
root = False
focus = False
cursor = False
ancestor = False
foreground = True
showAllName = False
depth = 0xFFFFFFFF
seconds = 3
for (o, v) in options:
if o in ('-h', '-help'):
usage()
exit(0)
elif o in ('-r', '-root'):
Calc(calcWindow, char2Button, '2*3.14159*10')
calcWindow.CaptureToImage('calc.png', 7, 0, -14, -7) # on windows 10, 7 pixels of windows border are transparent
calcWindow.Disappears(1)
calcWindow.GetWindowPattern().Close()
calcWindow.Exists(1)
if __name__ == '__main__':
osVersion = os.sys.getwindowsversion().major
if osVersion < 6:
CalcOnXP()
elif osVersion == 6:
CalcOnWindows7And8()
elif osVersion >= 10:
CalcOnWindows10()
auto.Logger.Write('\nPress any key to exit', auto.ConsoleColor.Cyan)
import msvcrt
while not msvcrt.kbhit():
pass
def Calc(window, btns, expression):
expression = ''.join(expression.split())
if not expression.endswith('='):
expression += '='
for char in expression:
auto.Logger.Write(char, writeToFile = False)
btns[char].Click(waitTime=0.05)
time.sleep(0.1)
window.SendKeys('{Ctrl}c', waitTime = 0.1)
result = auto.GetClipboardText()
auto.Logger.WriteLine(result, auto.ConsoleColor.Cyan, writeToFile = False)
time.sleep(1)
remain[depth] = remainCount
isDir = os.path.isdir(it)
prefixPrint = ''.join(['│ ' if remain[i + 1] else ' ' for i in range(depth - 1)])
prefixLog = ''.join(['│ ' if remain[i + 1] else ' ' for i in range(depth - 1)])
if depth > 0:
if remain[depth] > 0:
prefixPrint += '├─→' if isDir else '├──'
prefixLog += '├─→ ' if isDir else '├── '
else:
prefixPrint += '└─→' if isDir else '└──'
prefixLog += '└─→ ' if isDir else '└── '
file = os.path.basename(it)
texts.append(prefixLog)
texts.append(file)
texts.append('\n')
auto.Logger.Write(prefixPrint, writeToFile=False)
auto.Logger.WriteLine(file, auto.ConsoleColor.Cyan if isDir else auto.ConsoleColor.Default, writeToFile=False)
allText = ''.join(texts)
auto.Logger.WriteLine(allText, printToStdout=False)
ret = input('\npress Y to save dir tree to clipboard, press other keys to exit')
if ret.lower() == 'y':
auto.SetClipboardText(allText)
elif o in ('-f', '-focus'):
focus = True
elif o in ('-c', '-cursor'):
cursor = True
elif o in ('-a', '-ancestor'):
ancestor = True
elif o in ('-n', '-showAllName'):
showAllName = True
elif o in ('-m', '-showMore'):
showMore = True
elif o in ('-d', '-depth'):
depth = int(v)
elif o in ('-t', '-time'):
seconds = int(v)
if seconds > 0:
Logger.Write('please wait for {0} seconds\n\n'.format(seconds), writeToFile=False)
time.sleep(seconds)
Logger.Log('Starts, Current Cursor Position: {}'.format(Win32API.GetCursorPos()))
control = None
if root:
control = GetRootControl()
if focus:
control = GetFocusedControl()
if cursor:
control = ControlFromCursor()
if depth < 0:
while depth < 0:
control = control.GetParentControl()
depth += 1
depth = 0xFFFFFFFF
if ancestor:
control = ControlFromCursor()
focus = True
foreground = False
elif o in ('-c', '-cursor'):
cursor = True
foreground = False
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()
control = GetRootControl()
if focus:
control = GetFocusedControl()
if cursor:
control = ControlFromCursor()
if depth < 0:
while depth < 0:
control = control.GetParentControl()
depth += 1
depth = 0xFFFFFFFF
if ancestor:
control = ControlFromCursor()
if control:
EnumAndLogControlAncestors(control, showAllName, showMore)
else:
Logger.Write('IUIAutomation return null element under cursor\n', ConsoleColor.Yellow)
else:
if not control:
control = GetFocusedControl()
controlList = []
while control:
controlList.insert(0, control)
control = control.GetParentControl()
if len(controlList) == 1:
control = controlList[0]
else:
control = controlList[1]
EnumAndLogControl(control, depth, showAllName, showMore)
Logger.Log('Ends\n')