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_slowshot_timeout():
disp = SmartDisplay(visible=False)
py = Path(__file__).parent / ("slowgui.py")
proc = EasyProcess([python, py])
with disp:
with proc:
with pytest.raises(DisplayTimeoutError):
img = disp.waitgrab(timeout=1)
httpd_thread.daemon = True
httpd_thread.start()
# Start up a virtual display, useful for testing on headless servers.
# -----------------------------------------------------------------------------
VIRTUAL_SIZE = (1024, 2000)
# PhantomJS doesn't need a display
disp = None
if args.virtual and args.browser != "PhantomJS":
from pyvirtualdisplay.smartdisplay import SmartDisplay
try:
disp = SmartDisplay(
visible=0, bgcolor='black', size=VIRTUAL_SIZE).start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
raise
# Start up the web browser and run the tests.
# ----------------------------------------------------------------------------
from selenium import webdriver
from selenium.common import exceptions as selenium_exceptions
from selenium.webdriver.common.keys import Keys as selenium_keys
driver_arguments = {}
from pyvirtualdisplay.smartdisplay import SmartDisplay
logging.basicConfig(level=logging.DEBUG)
backend1 = "wx"
backend2 = "wx"
with SmartDisplay(visible=False, bgcolor="black") as disp:
disp.pyscreenshot_backend = backend1
with EasyProcess("xmessage test1"):
img1 = disp.waitgrab()
with SmartDisplay(visible=False, bgcolor="black") as disp:
disp.pyscreenshot_backend = backend2
with EasyProcess("xmessage test2"):
img2 = disp.waitgrab()
img1.show()
img2.show()
from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay
if __name__ == "__main__":
disp = SmartDisplay(visible=False, bgcolor="black").start()
xmessage = EasyProcess(["xmessage","hello"]).start()
img = disp.waitgrab()
xmessage.stop()
disp.stop()
img.show()
def screenshot(cmd, fname):
logging.info("%s %s", cmd, fname)
# fpath = "docs/_img/%s" % fname
# if os.path.exists(fpath):
# os.remove(fpath)
with SmartDisplay() as disp:
with EasyProcess(cmd):
img = disp.waitgrab()
img.save(fname)
from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay
disp = SmartDisplay(visible=0, bgcolor='black')
func = disp.wrap(EasyProcess('xmessage hello').wrap(disp.waitgrab))
img=func()
img.show()
# First, create the copy of the hard drive
if DEBUG:
print "creating the HD"
# kill any previous binaries
for proc in psutil.process_iter():
if proc.name() == "previous":
proc.kill()
tar = tarfile.open(PRISTINE_HARD_DISK, 'r:gz')
tar.extractall(ACTUAL_HARD_DISK_DIR)
if DEBUG:
print "done creating the HD"
with pyvirtualdisplay.smartdisplay.SmartDisplay(visible=0, size=(1300, 900)) as v_display:
if DEBUG:
print v_display
print v_display.display
with easyprocess.EasyProcess(PREVIOUS_BINARY) as previous:
time.sleep(.50)
xdo = Xdo()
done = False
while not done:
wins = xdo.search_windows('Previous')
# check if alive
if not previous.is_alive():
print "Error, couldn't boot emulator"
return
"""
using :keyword:`with` statement
"""
from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay
if __name__ == "__main__":
with SmartDisplay(visible=False, bgcolor="black") as disp:
with EasyProcess(["xmessage", "hello"]):
img = disp.waitgrab()
img.show()
def main():
pls = []
try:
os.chdir("gen")
for cmd, grab, bg in commands:
with SmartDisplay() as disp:
logging.info("======== cmd: %s", cmd)
fname_base = cmd.replace(" ", "_")
fname = fname_base + ".txt"
# logging.info("cmd: %s", cmd)
print("file name: %s" % fname)
with open(fname, "w") as f:
f.write("$ " + cmd)
if bg:
p = EasyProcess(cmd).start()
else:
p = EasyProcess(cmd).call()
f.write(p.stdout)
f.write(p.stderr)
pls += [p]
if grab:
png = fname_base + ".png"