Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
menuItem = automation.ControlFromPoint(x + 2, y - 2)
while 1:
if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
find = True
break
y -= 20
menuItem = automation.ControlFromPoint(x + 2, y)
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:
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()
if control:
auto.EnumAndLogControlAncestors(control, showAllName)
def BatchRename():
foxitWindow = automation.WindowControl(searchDepth= 1, ClassName= 'classFoxitReader')
foxitWindow.ShowWindow(automation.ShowWindow.ShowMaximized)
ret = foxitWindow.SetActive()
print('SetActive', ret)
automation.Logger.Log(foxitWindow.Name[:-len(' - Foxit Reader')] + '\n')
automation.SendKeys('{Ctrl}0')
for aid in ['59583', '60682', '60683']:
editToolBar = automation.ToolBarControl(searchFromControl= foxitWindow, AutomationId = aid, Name = 'Caption Bar')
if editToolBar.Exists(0, 0):
editToolBar.Click(-40, 0.5)
automation.SendKeys('{Alt}y')
paneWindow = automation.WindowControl(searchFromControl= foxitWindow, AutomationId = '65280')
bookmarkPane = automation.PaneControl(searchFromControl= paneWindow, searchDepth= 1, foundIndex= 1)
l, t, r, b = bookmarkPane.BoundingRectangle
#bookmarkButton = automation.ButtonControl(searchFromControl= bookmarkPane, Name = '书签') # can't find, but automation -a can find it, why
if bookmarkPane.Name == '书签':
if r - l < 40:
bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
if bookmarkButton.Name == '书签':
bookmarkButton.Click(simulateMove= False)
else:
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()
if control:
EnumAndLogControlAncestors(control, showAllName, showMore)
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')