本文整理汇总了Python中pyvirtualdisplay.smartdisplay.SmartDisplay类的典型用法代码示例。如果您正苦于以下问题:Python SmartDisplay类的具体用法?Python SmartDisplay怎么用?Python SmartDisplay使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmartDisplay类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: prog_shot
def prog_shot(cmd, f, wait, timeout, screen_size, visible, bgcolor, cwd=None):
'''start process in headless X and create screenshot after 'wait' sec.
Repeats screenshot until it is not empty if 'repeat_if_empty'=True.
wait: wait at least N seconds after first window is displayed,
it can be used to skip splash screen
:param enable_crop: True -> crop screenshot
:param wait: int
'''
disp = SmartDisplay(visible=visible, size=screen_size, bgcolor=bgcolor)
disp.pyscreenshot_backend = None
disp.pyscreenshot_childprocess = True
proc = EasyProcess(cmd, cwd=cwd)
def func():
try:
img = disp.waitgrab(timeout=timeout)
except DisplayTimeoutError as e:
raise DisplayTimeoutError(str(e) + ' ' + str(proc))
if wait:
proc.sleep(wait)
img = disp.grab()
return img
img = disp.wrap(proc.wrap(func))()
if img:
img.save(f)
return (proc.stdout, proc.stderr)
开发者ID:ponty,项目名称:sphinxcontrib-programscreenshot,代码行数:29,代码来源:programscreenshot.py
示例2: Test
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
def tearDown(self):
self.p.stop()
self.screen.stop()
# def test_empty(self):
# self.p = EasyProcess('zenity --warning').start()
# wnd is not ready
# time.sleep(0.2)
# self.assertRaises(EmptyScreenException, active_rectangles)
def test_zenity(self):
self.p = EasyProcess('zenity --warning').start()
self.wait()
ls = active_rectangles()
self.assertEquals(len(ls), 1)
def test_notab(self):
self.p = EasyProcess('xmessage -buttons x,y,z hi').start()
self.wait()
ls = active_rectangles(grid=10)
self.assertEquals(len(ls), 3)
def test_gmessage(self):
self.p = EasyProcess('gmessage -buttons x,y,z hi').start()
self.wait()
ls = active_rectangles()
self.assertEquals(len(ls), 3)
开发者ID:ponty,项目名称:discogui,代码行数:35,代码来源:test_hover.py
示例3: Test
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
self.p = None
def tearDown(self):
self.p.stop()
self.screen.stop()
# def test_empty(self):
# self.p = EasyProcess('zenity --warning').start()
# wnd is not ready
# self.assertRaises(EmptyScreenException, tab_rectangles)
# def test_zenity(self):
# self.p = EasyProcess('zenity --warning').start()
# self.wait()
# ls = tab_rectangles()
# self.assertEquals(len(ls), 2)
def test_notab(self):
self.p = EasyProcess('xmessage hi').start()
self.wait()
ls = tab_rectangles()
self.assertEquals(len(ls), 0)
def test_gmessage(self):
self.p = EasyProcess('gmessage -buttons x,y,z hi').start()
self.wait()
ls = tab_rectangles()
self.assertEquals(len(ls), 4)
开发者ID:ponty,项目名称:discogui,代码行数:35,代码来源:test_taborder.py
示例4: test_slowshot_wrap
def test_slowshot_wrap(self):
disp = SmartDisplay(visible=0)
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py)
f = disp.wrap(proc.wrap(disp.waitgrab))
img = f()
eq_(img is not None, True)
开发者ID:AvdN,项目名称:PyVirtualDisplay,代码行数:7,代码来源:test_smart.py
示例5: test_slowshot
def test_slowshot(self):
disp = SmartDisplay(visible=0).start()
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py).start()
img = disp.waitgrab()
proc.stop()
disp.stop()
eq_(img is not None, True)
开发者ID:AvdN,项目名称:PyVirtualDisplay,代码行数:8,代码来源:test_smart.py
示例6: cli_parse
def cli_parse():
'''Parse command-line arguments'''
options = {'title': None, 'desc': None, 'date': None,
'time': None, 'id': None}
parser = argparse.ArgumentParser()
parser.add_argument("action", help='''use "create" to create a new event\n
"update" to update an event\n"details" to get event info''') # noqa
parser.add_argument("--title", help="event title")
parser.add_argument("--date", help="event date")
parser.add_argument("--id", help="event id")
parser.add_argument("--desc", help="event description")
parser.add_argument("--filedesc", help="path to txt file w/ event description", # noqa
type=argparse.FileType('r'))
parser.add_argument("--otp", help="2-step verification code")
parser.add_argument("--show", help="1 to display the browser, 0 for invisible virtual display", # noqa
default=0, type=int)
try:
args = parser.parse_args()
except:
parser.print_help()
exit(1)
disp = None
if not args.show: # set up invisible virtual display
from pyvirtualdisplay.smartdisplay import SmartDisplay
try:
disp = SmartDisplay(visible=0, bgcolor='black').start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
raise
if args.title:
options['title'] = args.title
if args.desc:
options['desc'] = args.desc
elif args.filedesc:
options['desc'] = args.filedesc.read()
if args.date:
options['date'] = dtparser.parse(args.date).strftime('%Y-%m-%d')
options['time'] = dtparser.parse(args.date).strftime('%I:%M %p')
if args.id:
options['id'] = args.id
if args.otp:
options['otp'] = args.otp
options['action'] = args.action
return options
开发者ID:events-everywhere,项目名称:google-plus,代码行数:56,代码来源:gplus_event.py
示例7: test_disp
def test_disp(self):
vd = SmartDisplay().start()
d = SmartDisplay(visible=1).start().sleep(2).stop()
self.assertEquals(d.return_code, 0)
d = SmartDisplay(visible=0).start().stop()
self.assertEquals(d.return_code, 0)
vd.stop()
开发者ID:AvdN,项目名称:PyVirtualDisplay,代码行数:10,代码来源:test_smart.py
示例8: CuiJsTestCase
class CuiJsTestCase(LiveServerTestCase):
def setUp(self):
# See https://code.djangoproject.com/ticket/10827
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)
def tearDown(self):
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()
def wait_until_expr(self, expr, timeout=60):
WebDriverWait(self.driver, timeout).until(
lambda driver: driver.execute_script('return (%s)' % expr))
def test(self):
sys.stderr.write('\n\nRunning candidate UI unit tests...\n')
sys.stderr.flush()
tests_url = self.live_server_url + reverse('cui_test')
jasmine_spec = os.environ.get('JASMINE_SPEC')
if jasmine_spec:
tests_url += "?spec={}".format(urlquote(jasmine_spec))
self.driver.get(tests_url)
self.wait_until_expr('window.seleniumReporter')
runner = SeleniumRunner(self.driver, sys.stderr)
success = runner.run()
self.assertTrue(success, 'JS tests failed. See full report on stderr')
开发者ID:KushalVenkatesh,项目名称:cui,代码行数:49,代码来源:tests.py
示例9: __init__
def __init__(self, browser="chrome", executable_path=None):
"""
Initialization does two things:
1. Makes sure that there is active X session.
2. Starts browser.
On initialization it stats X session if can't find 'DISPLAY' in
os.environ. For this purposes used *pyvirtualdisplay* package.
For handling browser used seleniumwrapper library.
"""
# lets start display in case if no is available
self.hangout_id = None
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {}
if browser == "chrome":
kwargs['executable_path'] = executable_path or CHROMEDRV_PATH
self.browser = selwrap.create(browser, **kwargs)
self.video = VideoSettings(self)
self.microphone = MicrophoneSettings(self)
self.audio = AudioSettings(self)
self.bandwidth = BandwidthSettings(self)
开发者ID:mithro,项目名称:hangout_api,代码行数:29,代码来源:base.py
示例10: Test
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay(visible=VISIBLE)
self.screen.start()
self.p = None
def tearDown(self):
self.p.stop()
self.screen.stop()
def test_zenity(self):
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key('\n')
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key_list(['\n'])
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key(' ')
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key('x')
self.assertTrue(getbbox(grab()))
def test_gcalctool1(self):
self.p = EasyProcess('gnome-calculator').start()
self.wait()
focus_wnd()
send_key('ctrl+q')
time.sleep(1)
# img_debug(grab(), 'ctrl+q')
self.assertFalse(getbbox(grab()))
开发者ID:ponty,项目名称:discogui,代码行数:42,代码来源:test_sendkeys.py
示例11: RealBrowser
class RealBrowser(webdriver.Firefox):
def __init__(self, timeout=30):
self._abstract_display = SmartDisplay(visible=0)
self._abstract_display.start()
super(RealBrowser, self).__init__()
self.implicitly_wait(timeout)
def quit(self):
super(RealBrowser, self).quit()
self._abstract_display.stop()
@timeout(REQUEST_TIMEOUT)
def _open(self, url):
self.get(url)
def open(self, url):
try:
self._open(url)
return True
except Exception, e:
logger.error('network error for %s: %s', url, str(e))
开发者ID:jererc,项目名称:mediacore-py,代码行数:23,代码来源:__init__.py
示例12: CuiJsTestCase
class CuiJsTestCase(LiveServerTestCase):
def setUp(self):
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
self.driver = webdriver.Firefox()
def tearDown(self):
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()
def wait_until_expr(self, expr, timeout=60):
WebDriverWait(self.driver, timeout).until(
lambda driver: driver.execute_script('return (%s)' % expr))
def test(self):
sys.stderr.write('\n\nRunning candidate UI unit tests...\n')
sys.stderr.flush()
self.driver.get(self.live_server_url+reverse('cui_test'))
self.wait_until_expr('window.jsApiReporter !== undefined && window.jsApiReporter.finished')
specs = self.driver.execute_script('return window.jsApiReporter.specs()')
self.assertTrue(len(specs) > 0, 'No test results found! The tests probably contain syntax errors.')
passed = True
for spec in specs:
sys.stderr.write(' %s ... %s\n' % (spec['fullName'], spec['status']))
if spec['status'] != 'passed':
passed = False
for exp in spec['failedExpectations']:
sys.stderr.write(' %s\n' % exp['message'])
sys.stderr.write('Access full report at %s\n\n' % reverse('cui_test'))
sys.stderr.flush()
self.assertTrue(passed, 'JS tests failed. See full report on stderr')
开发者ID:117111302,项目名称:cui,代码行数:37,代码来源:tests.py
示例13: setUp
def setUp(self):
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)
开发者ID:debmalya,项目名称:cui,代码行数:18,代码来源:tests.py
示例14: __init__
def __init__(self, executable_path=None, chrome_options=None):
self.hangout_id = None
self.on_air = None
# lets start display in case if no is available
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {'executable_path': executable_path or CHROMEDRV_PATH}
if chrome_options is not None:
kwargs['chrome_options'] = chrome_options
self.browser = selwrap.create('chrome', **kwargs)
self.utils = Utils(self.browser)
for name, instance in getUtilitiesFor(IModule):
setattr(self, name, instance(self.utils))
开发者ID:enkidulan,项目名称:hangout_api,代码行数:19,代码来源:base.py
示例15: setUp
def setUp(self):
# See https://code.djangoproject.com/ticket/10827
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)
开发者ID:KushalVenkatesh,项目名称:cui,代码行数:22,代码来源:tests.py
示例16: SmartDisplay
port = httpd.socket.getsockname()[-1]
# Start up a virtual display, useful for testing on headless servers.
# -----------------------------------------------------------------------------
if args.virtual:
try:
from pyvirtualdisplay.smartdisplay import SmartDisplay
except ImportError:
print "Please install the Python pyvirtualdisplay module."
print " sudo pip install pyvirtualdisplay"
sys.exit(-1)
disp = None
try:
disp = SmartDisplay(visible=0, bgcolor='black').start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
# Start up the web browser and run the tests.
# ----------------------------------------------------------------------------
try:
from selenium import webdriver
except ImportError:
print "Please install the Python selenium module."
print " sudo pip install selenium"
sys.exit(-1)
开发者ID:rbtcollins,项目名称:web-animations-js,代码行数:31,代码来源:run-tests.py
示例17: Hangouts
class Hangouts(object):
"""
Main class for controlling hangout calls.
Initialization does two things:
1. Makes sure that there is active X session.
2. Starts the browser.
If 'DISPLAY' can't be found in os.environ than new X session starts.
Starting new session handels `PyVirtualDisplay`_.
.. _PyVirtualDisplay: http://ponty.github.io/PyVirtualDisplay/
For handling browser used seleniumwrapper library.
.. testsetup:: HangoutsBase
import os
os.environ['DISPLAY'] = '1'
from hangout_api import Hangouts
from hangout_api.tests.doctests_utils import DummySelenium
import seleniumwrapper
def get_attribute(self, name):
if name == 'aria-label':
return ' John Doe '
elif name == 'data-userid':
return '108775712935'
else:
return 'hello'
DummySelenium.get_attribute = get_attribute
seleniumwrapper.create = DummySelenium
.. testsetup:: HangoutsBase2
import os
os.environ['DISPLAY'] = '1'
from hangout_api import Hangouts
from hangout_api.tests.doctests_utils import DummySelenium
import seleniumwrapper
DummySelenium.location = {'x': 1}
seleniumwrapper.create = DummySelenium
hangout = Hangouts()
.. doctest:: HangoutsBase
>>> hangout = Hangouts()
"""
def __init__(self, executable_path=None, chrome_options=None):
self.hangout_id = None
self.on_air = None
# lets start display in case if no is available
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {'executable_path': executable_path or CHROMEDRV_PATH}
if chrome_options is not None:
kwargs['chrome_options'] = chrome_options
self.browser = selwrap.create('chrome', **kwargs)
self.utils = Utils(self.browser)
for name, instance in getUtilitiesFor(IModule):
setattr(self, name, instance(self.utils))
def start(self, on_air=None):
"""
Start a new hangout.
After new hangout is created its id is stored in 'hangout_id' attribure
.. doctest:: HangoutsBase
>>> hangout.start()
>>> hangout.hangout_id
'gs4pp6g62w65moctfqsvihzq2qa'
To start OnAir just pass on_air argument to 'start' method.
.. doctest:: HangoutsBase
>>> hangout.start(
... on_air={'name':'My OnAir', 'attendees':['Friends']})
>>> hangout.start(on_air='https://plus.google.com/events/df34...')
"""
# onair
if on_air is not None:
self.on_air = on_air
#.........这里部分代码省略.........
开发者ID:enkidulan,项目名称:hangout_api,代码行数:101,代码来源:base.py
示例18: setUp
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
self.p = None
开发者ID:ponty,项目名称:discogui,代码行数:4,代码来源:test_taborder.py
示例19: onJoin
def onJoin(self, details):
# SUBSCRIBE to a topic and receive events
#
self.zstoreFlag = 1
self.lastzValue = 0.0
self.zCounter = 0
self.ystoreFlag = 1
self.lastyValue = 0.0
def y_direction(IMUTable):
if self.ystoreFlag == 1:
self.lastyValue = abs( IMUTable['y'])
self.ystoreFlag = 0
return
curryValue = abs(IMUTable['y'])
ydiff = self.lastyValue - curryValue
gammaValue = IMUTable['gamma']
if abs(gammaValue) > 66:
print "Z Stable"
if ( curryValue > 1.5) and (abs(ydiff) > 0.4):
print "Right"
self.keyb.emit_click(uinput.KEY_V)
if ( curryValue < 1.5) and (abs(ydiff) > 0.4):
print "Left"
self.keyb.emit_click(uinput.KEY_END)
self.lastyValue = curryValue
print "The diff is ",ydiff, abs(ydiff)
def z_direction(IMUTable):
if self.zstoreFlag == 1:
self.lastzValue = IMUTable['z']
self.zstoreFlag = 0
return
currzValue = IMUTable['z']
zdiff = self.lastzValue - currzValue
gammaValue = IMUTable['gamma']
if abs(gammaValue) > 66:
print "Z Stable"
if ( currzValue > 1.5) and (abs(zdiff) > 0.4):
print "Forward"
self.keyb.emit_click(uinput.KEY_UP)
if ( currzValue < 1.5) and (abs(zdiff) > 0.4):
print "Backward"
self.keyb.emit_click(uinput.KEY_DOWN)
self.lastzValue = currzValue
print "The diff is ",zdiff, abs(zdiff)
def on_event(i):
print("Got event: {}".format(i))
IMUTab = json.loads(i);
print IMUTab['z']
z_direction(IMUTab)
y_direction(IMUTab)
#if self.storeFlag == 1:
# self.lastzValue = IMUTab['z']
# self.storeFlag = 0
# return
#currzValue = IMUTab['z']
#zdiff = self.lastzValue - currzValue
yield self.subscribe(on_event, 'com.myapp.topic1')
self.log.info("subscribed to topic 'onhello'")
# REGISTER a procedure for remote calling
#
def add2(x, y):
self.log.info("add2() called with {x} and {y}", x=x, y=y)
return x + y
yield self.register(add2, 'com.example.add2')
self.log.info("procedure add2() registered")
self.keyb = uinput.Device(self.events)
self.disp = SmartDisplay(visible=1, size=(800,600)).start()
# self.disp = SmartDisplay(visible=1, size=(640, 480) ).start()
# self.command = EasyProcess('celestia -s -f').start()
# self.command = EasyProcess('lightdm --test-mode').start()
self.p = Popen(['celestia'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
# self.p = Popen(['xterm'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
# PUBLISH and CALL every second .. forever
#
counter = 0
sleep(10)
while True:
# stdout_data = p.communicate(input="\x1B[C")[0]
# print stdout_data
self.buffer = cStringIO.StringIO()
#self.img = self.disp.wait()
self.img = self.disp.waitgrab(timeout=0.1, autocrop=False)
self.img.save(self.buffer, "JPEG")
self.imgStr = base64.b64encode(self.buffer.getvalue())
yield self.publish('com.example.image', self.imgStr)
# CALL a remote procedure
#
#try:
# res = yield self.call('com.example.mul2', counter, 3)
#.........这里部分代码省略.........
开发者ID:sehrgutlab,项目名称:WebVRApp,代码行数:101,代码来源:hello.py
示例20: test_slowshot_timeout
def test_slowshot_timeout(self):
disp = SmartDisplay(visible=0)
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py)
f = disp.wrap(proc.wrap(lambda: disp.waitgrab(timeout=1)))
self.assertRaises(DisplayTimeoutError, f)
开发者ID:AvdN,项目名称:PyVirtualDisplay,代码行数:6,代码来源:test_smart.py
注:本文中的pyvirtualdisplay.smartdisplay.SmartDisplay类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论