Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 采用特殊处理获取重命名菜单
x, y = automation.Win32API.GetCursorPos()
menuItem = automation.ControlFromPoint(x + 2, y + 2)
if isinstance(menuItem, automation.MenuItemControl):
#鼠标右下方弹出菜单
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
else:
#鼠标右上方弹出菜单
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)
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
else:
#鼠标右上方弹出菜单
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)
time.sleep(0.1)
find = False
for i in range(3):
treeItem.RightClick(simulateMove = False, waitTime = 0.2)
# FoxitReader书签右键菜单(BCGPToolBar,非Windows菜单)弹出后,枚举不到菜单,但从屏幕点上ControlFromPoint能获取到菜单, todo
# 采用特殊处理获取重命名菜单
x, y = automation.Win32API.GetCursorPos()
menuItem = automation.ControlFromPoint(x + 2, y + 2)
if isinstance(menuItem, automation.MenuItemControl):
#鼠标右下方弹出菜单
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
else:
#鼠标右上方弹出菜单
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:
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:
bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
if bookmarkButton.Name == '书签':
bookmarkButton.Click(simulateMove= False)
tree = automation.TreeControl(searchFromControl= foxitWindow, ClassName= 'SysTreeView32')
childItems = tree.GetChildren()
bookMarks = []
depth = 1
for treeItem in childItems:
if treeItem.ControlType == automation.ControlType.TreeItemControl:
RenameTreeItem(tree, treeItem, bookMarks, depth)
fout = open('rename_pdf_bookmark.txt', 'wt', encoding= 'utf-8')
depth = 1
for bookMark in bookMarks:
DumpBookMark(fout, bookMark, depth)
fout.close()
if Renamed:
automation.Logger.Log('rename pdf: ' + foxitWindow.Name)
newName, alert = RenameFunction(name, removeChapter)
if newName.startswith('Appendix'):
removeChapter = False
bookMark = BookMark(name, newName)
bookMarks.append(bookMark)
if newName != name and depth not in TreeSkipDepthList:
global Renamed
Renamed = True
time.sleep(0.1)
find = False
for i in range(3):
treeItem.RightClick(simulateMove = False, waitTime = 0.2)
# FoxitReader书签右键菜单(BCGPToolBar,非Windows菜单)弹出后,枚举不到菜单,但从屏幕点上ControlFromPoint能获取到菜单, todo
# 采用特殊处理获取重命名菜单
x, y = automation.Win32API.GetCursorPos()
menuItem = automation.ControlFromPoint(x + 2, y + 2)
if isinstance(menuItem, automation.MenuItemControl):
#鼠标右下方弹出菜单
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
else:
#鼠标右上方弹出菜单
menuItem = automation.ControlFromPoint(x + 2, y - 2)
while 1:
if menuItem.Name == '重命名(R)' or menuItem.Name == 'Rename':
find = True
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:
bookmarkButton = automation.ControlFromPoint(l + 10, t + 40)
if bookmarkButton.Name == '书签':
bookmarkButton.Click(simulateMove= False)
tree = automation.TreeControl(searchFromControl= foxitWindow, ClassName= 'SysTreeView32')
childItems = tree.GetChildren()
bookMarks = []
depth = 1
for treeItem in childItems:
if treeItem.ControlType == automation.ControlType.TreeItemControl:
RenameTreeItem(tree, treeItem, bookMarks, depth)
fout = open('rename_pdf_bookmark.txt', 'wt', encoding= 'utf-8')
depth = 1
for bookMark in bookMarks: