Exemple #1
0
  def test_void(self):
    p = Params()
    exitparam = p.void('exit')
    self.assertEqual(exitparam.to_dict()['type'], 'v')

    exits = []
    exitparam.onchange(exits.append)
    self.assertEqual(len(exits), 0)
    exitparam.set(None)
    self.assertEqual(len(exits), 1)
    exitparam.set('foo')
    self.assertEqual(len(exits), 2)
    exitparam.trigger()
    self.assertEqual(len(exits), 3)
Exemple #2
0
  def test_void_argumentless_callback(self):
    p = Params()
    exitparam = p.void('exit')
    self.assertEqual(exitparam.to_dict()['type'], 'v')

    exits = []
    def func():
      print('func: {}'.format(len(exits)))
      exits.append('func')
    
    exitparam.ontrigger(func)
    self.assertEqual(len(exits), 0)
    exitparam.trigger()
    self.assertEqual(len(exits), 1)
    self.assertEqual(exits[-1], 'func')
Exemple #3
0
    async def main(self):
        # Params
        params = Params()
        self.imageParam = params.image('image')
        fps = params.float('fps', min=0.0, max=5.0)
        snap = params.void('snap')

        fps.set(0.0)
        snap.ontrigger(self.update)

        logger.info(f'Starting websocket server on port: {self.port}')
        wss = WebsocketServer(Server(params),
                              host=self.host,
                              port=self.port,
                              start=False)
        await wss.start_async()

        logger.info(f'Starting webcam')
        self.cap = cv2.VideoCapture(0)

        nextTime = time.time()
        try:
            while True:
                t = time.time()
                hz = fps.val()

                if t >= nextTime and hz > 0.00001:
                    self.update()
                    nextTime = t + 1.0 / hz

                await asyncio.sleep(0.05)

                key = cv2.waitKey(10) & 0xFF

                if key == 27 or key == ord('q'):  # escape or Q
                    break

                if key == ord('s'):
                    self.update()

        except KeyboardInterrupt:
            print("Received Ctrl+C... initiating exit")

        print('Stopping...')
        wss.stop()