当用户单击并显示对话框或重新单击以在上一个暂停的行继续时,我想暂停脚本Pyautogui。
我尝试了其他测试,但没有成功通过测试。
当用户键入“ Space”时,我对Queue进行了主要测试,他暂停了脚本,但是他不适用于所使用的特定命令行。 我想用“点击”代替“空格”。
使用此命令行无法停止进程并继续:
a = pyautogui.typewrite('TEST', interval=0.15)
b = pyautogui.typewrite('TEST', interval=0.15)
c = pyautogui.typewrite('TEST', interval=0.15)
d = pyautogui.typewrite('TEST', interval=0.15)
myQueue.enqueue(a)
myQueue.enqueue(b)
myQueue.enqueue(c)
myQueue.enqueue(d)
但是使用此命令行可以停止进程并继续:
myQueue.enqueue(1)
myQueue.enqueue(2)
myQueue.enqueue(3)
myQueue.enqueue(4)
myQueue.enqueue(5)
myQueue.enqueue(6)
脚本:
# -*- coding: utf-8 -*-
import pyautogui
import time
import datetime
from datetime import date, timedelta
from Tkinter import *
screenWidth, screenHeight = pyautogui.size()
currentMouseX, currentMouseY = pyautogui.position()
yesterday = date.today() - timedelta(1)
three = date.today() - timedelta(3)
d = datetime.datetime.now()
monday = d.isoweekday() in range(1)
class MyLoop():
def __init__(self, root):
self.running = True
self.aboutToQuit = False
self.root = root
self.someVar = 0
self.root.bind("<space>", self.switch)
self.root.bind("<Escape>", self.exit)
while not self.aboutToQuit:
self.root.update() # always process new events
if self.running:
myQueue = Queue()
#Insert here specific command line
a = pyautogui.confirm('TEST')
b = pyautogui.typewrite('TEST', interval=0.15)
c = pyautogui.typewrite('TEST', interval=0.15)
d = pyautogui.typewrite('TEST', interval=0.15)
e = pyautogui.typewrite('TEST', interval=0.15)
myQueue.enqueue(a) #prints True
myQueue.enqueue(b) #prints True
myQueue.enqueue(c) #prints True
myQueue.enqueue(d) #prints False
myQueue.enqueue(e) #prints True
#Finish to insert
time.sleep(.1)
else: # If paused, don't do anything
time.sleep(.1)
def switch(self, event):
print(['Unpausing','Pausing'][self.running])
self.running = not(self.running)
def exit(self, event):
self.aboutToQuit = True
self.root.destroy()
class Queue:
#Constructor creates a list
def __init__(self):
self.queue = list()
#Adding elements to queue
def enqueue(self,data):
#Checking to avoid duplicate entry (not mandatory)
if data not in self.queue:
self.queue.insert(0,data)
return True
return False
#Removing the last element from the queue
def dequeue(self):
if len(self.queue)>0:
return self.queue.pop()
return ("Queue Empty!")
#Getting the size of the queue
def size(self):
return len(self.queue)
#printing the elements of the queue
def printQueue(self):
return self.queue
if __name__ == "__main__":
root = Tk()
root.withdraw() # don't show the tkinter window
MyLoop(root)
root.mainloop()