Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'))
checkBox = optionTab.CheckBoxControl(AutomationId = '103')
if checkBox.GetTogglePattern().ToggleState != auto.ToggleState.On:
checkBox.Click()
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'))
def LongClick(self, x, y, duration, **kwargs):
self.JudgeSize()
Left = self.root.BoundingRectangle[0]
Top = self.root.BoundingRectangle[1]
Width = self.root.BoundingRectangle[2] - self.root.BoundingRectangle[0]
Height = self.root.BoundingRectangle[3] - self.root.BoundingRectangle[1]
x = Left + Width * x
y = Top + Height * y
UIAuto.MAX_MOVE_SECOND = duration * 10
UIAuto.DragDrop(int(x), int(y), int(x), int(y))
return True
def Swipe(self, x1, y1, x2, y2, duration, **kwargs):
self.JudgeSize()
Left = self.root.BoundingRectangle[0]
Top = self.root.BoundingRectangle[1]
Width = self.root.BoundingRectangle[2] - self.root.BoundingRectangle[0]
Height = self.root.BoundingRectangle[3] - self.root.BoundingRectangle[1]
x1 = int(Left + Width * x1) # 比例换算
y1 = int(Top + Height * y1)
x2 = int(Left + Width * x2)
y2 = int(Top + Height * y2)
UIAuto.MAX_MOVE_SECOND = duration * 10 # 同步到跟UIAutomation库的时间设定一样
UIAuto.DragDrop(int(x1), int(y1), int(x2), int(y2))
return True
cmdWindow.SetActive(waitTime = 1)
while True:
vPercent = treeScrollPattern.VerticalScrollPercent
vPercent2 = rangeValuePattern.Value
print('ScrollPattern.VerticalScrollPercent', vPercent)
print('ValuePattern.Value', vPercent2)
if vPercent2 < 100:
tree.WheelDown(waitTime = 0.05)
else:
break
if cmdWindow:
auto.Logger.ColorfullyWriteLine('Scroll by DragDrop')
cmdWindow.SetActive(waitTime=1)
mmcWindow.SetActive(waitTime = 1)
x, y = thumb.MoveCursorToMyCenter()
auto.DragDrop(x, y, x, vScrollBarRect.top, waitTime=1)
x, y = thumb.MoveCursorToMyCenter()
auto.DragDrop(x, y, x, vScrollBarRect.bottom)
mmcWindow.GetWindowPattern().Close()
vPercent = treeScrollPattern.VerticalScrollPercent
vPercent2 = rangeValuePattern.Value
print('ScrollPattern.VerticalScrollPercent', vPercent)
print('ValuePattern.Value', vPercent2)
if vPercent2 < 100:
tree.WheelDown(waitTime = 0.05)
else:
break
if cmdWindow:
auto.Logger.ColorfullyWriteLine('Scroll by DragDrop')
cmdWindow.SetActive(waitTime=1)
mmcWindow.SetActive(waitTime = 1)
x, y = thumb.MoveCursorToMyCenter()
auto.DragDrop(x, y, x, vScrollBarRect.top, waitTime=1)
x, y = thumb.MoveCursorToMyCenter()
auto.DragDrop(x, y, x, vScrollBarRect.bottom)
mmcWindow.GetWindowPattern().Close()