Ejemplo n.º 1
0
def test_empty():
    disp = SmartDisplay(visible=False)
    proc = EasyProcess([python])
    with disp:
        with proc:
            with pytest.raises(Exception):
                disp.waitgrab()
Ejemplo n.º 2
0
def test_empty_nocrop():
    disp = SmartDisplay(visible=False)
    proc = EasyProcess([python])
    with disp:
        with proc:
            with pytest.raises(Exception):
                disp.waitgrab(autocrop=False, timeout=10)
Ejemplo n.º 3
0
 def test_empty(self):
     disp = SmartDisplay(visible=0)
     proc = EasyProcess(sys.executable)
     with disp:
         with proc:
             with self.assertRaises(Exception):
                 img = disp.waitgrab()
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
def test_slowshot_with():
    disp = SmartDisplay(visible=False)
    py = Path(__file__).parent / ("slowgui.py")
    proc = EasyProcess([python, py])
    with disp:
        with proc:
            img = disp.waitgrab()
    assert img is not None
Ejemplo n.º 7
0
def test_slowshot():
    disp = SmartDisplay(visible=False).start()
    py = Path(__file__).parent / ("slowgui.py")
    proc = EasyProcess([python, py]).start()
    img = disp.waitgrab()
    proc.stop()
    disp.stop()
    assert img is not None
Ejemplo n.º 8
0
 def test_slowshot_timeout(self):
     disp = SmartDisplay(visible=0)
     py = Path(__file__).parent / ("slowgui.py")
     proc = EasyProcess("python " + py)
     with disp:
         with proc:
             with self.assertRaises(DisplayTimeoutError):
                 img = disp.waitgrab(timeout=1)
Ejemplo n.º 9
0
 def test_slowshot_wrap(self):
     disp = SmartDisplay(visible=0)
     py = Path(__file__).parent / ("slowgui.py")
     proc = EasyProcess("python " + py)
     with disp:
         with proc:
             img = disp.waitgrab()
     eq_(img is not None, True)
Ejemplo n.º 10
0
def prog_shot(cmd, f, wait, timeout, screen_size, visible, bgcolor, backend):
    '''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 wait: int
    '''
    # disp = SmartDisplay(visible=visible, size=screen_size, bgcolor=bgcolor)
    #'xvfb', 'xvnc' or 'xephyr',
    disp = SmartDisplay(visible=visible,
                        backend=backend,
                        size=screen_size,
                        bgcolor=bgcolor)
    proc = EasyProcess(cmd)

    def cb_imgcheck(img):
        """accept img if height > minimum."""
        rec = get_black_box(img)
        if not rec:
            return False
        left, upper, right, lower = rec
        accept = lower - upper > 30  # pixel
        log.debug('cropped img size=' + str((left, upper, right, lower)) +
                  ' accepted=' + str(accept))
        return accept

    # def func():
    #     if wait:
    #         proc.sleep(wait)
    #     try:
    #         img = disp.waitgrab(timeout=timeout, cb_imgcheck=cb_imgcheck)
    #     except DisplayTimeoutError as e:
    #         raise DisplayTimeoutError(str(e) + ' ' + str(proc))
    #     return img

    with disp:
        with proc:
            try:
                if wait:
                    proc.sleep(wait)
                img = disp.waitgrab(timeout=timeout, cb_imgcheck=cb_imgcheck)
            except DisplayTimeoutError as e:
                raise DisplayTimeoutError(str(e) + ' ' + str(proc))

    # img = disp.wrap(proc.wrap(func))()
    if img:
        bbox = get_black_box(img)
        assert bbox
        # extend to the left side
        bbox = (0, bbox[1], bbox[2], bbox[3])
        img = img.crop(bbox)

        img.save(f)
    return (proc.stdout, proc.stderr)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay

disp = SmartDisplay(visible=0, bgcolor='black').start()
xmessage = EasyProcess('xmessage hello').start()
img = disp.waitgrab()
xmessage.stop()
disp.stop()
img.show()
Ejemplo n.º 13
0
class AppSession(ApplicationSession):

    log = Logger()
    events = ( uinput.KEY_E, uinput.KEY_H,  uinput.KEY_L, uinput.KEY_V, uinput.KEY_END,uinput.KEY_HOME, uinput.KEY_UP, uinput.KEY_DOWN )

    lastzValue = 0.0
    @inlineCallbacks
    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)
            #    self.log.info("mul2() called with result: {result}",
            #                  result=res)
            #except ApplicationError as e:
            #    # ignore errors due to the frontend not yet having
            #    # registered the procedure we would like to call
            #    if e.error != 'wamp.error.no_such_procedure':
            #        raise e
            #return #yield sleep(0)
#           self.keyb.emit_click(uinput.KEY_HOME)
            yield sleep(0)