Ejemplo n.º 1
0
 def test_group_autoconnect(self):
     """EmitterGroup auto-connect"""
     class Source:
         def on_em1(self, ev):
             self.result = 1
         def em2_event(self, ev):
             self.result = 2
         def em3_event(self, ev):
             self.result = 3
     src = Source()
     grp = EmitterGroup(source=src, em1=Event, auto_connect=False)
     src.result = None
     grp.em1()
     assert src.result is None
     
     grp = EmitterGroup(source=src, em1=Event, auto_connect=True)
     src.result = None
     grp.em1()
     assert src.result == 1
     
     grp.auto_connect_format = "%s_event"
     grp.add(em2=Event)
     src.result = None
     grp.em2()
     assert src.result == 2
     
     grp.add(em3=Event, auto_connect=False)
     src.result = None
     grp.em3()
     assert src.result is None
Ejemplo n.º 2
0
 def test_group_add_emitter(self):
     """EmitterGroup.add"""
     grp = EmitterGroup(em1=Event)
     grp.em1.connect(self.record_event)
     self.result = None
     ev = grp.em1()
     self.assert_result(event=ev, type='em1')
     
     grp.add(em2=BasicEvent)
     grp.em2.connect(self.record_event)
     ev = grp.em2()
     self.assert_result(event=ev, type='em2', event_class=BasicEvent)
     
     grp.add(em3=TypedEvent)
     grp.em3.connect(self.record_event)
     ev = grp.em3(test_key=2)
     self.assert_result(event=ev, type='typed_event', event_class=TypedEvent, test_key=2)
     
     try:
         grp.add(em3=Event)
         assert False, "Double-added emitter"
     except ValueError:
         pass
     
     try:
         grp.add(add=Event)
         assert False, "Added event with invalid name"
     except ValueError:
         pass
Ejemplo n.º 3
0
 def test_group_disconnect(self):
     """EmitterGroup.disconnect"""
     grp = EmitterGroup(em1=Event)
     
     assert len(grp.em1.callbacks) == 0, grp.em1.callbacks
     grp.connect(self.record_event)
     assert len(grp.em1.callbacks) == 1
     grp.add(em2=Event)
     assert len(grp.em2.callbacks) == 1
     grp.disconnect()
     assert len(grp.em1.callbacks) == 0
     assert len(grp.em2.callbacks) == 0
Ejemplo n.º 4
0
 def test_group_construction(self):
     """EmitterGroup basic construction"""
     grp = EmitterGroup(em1=Event,
                        em2=BasicEvent,
                        em3=TypedEvent)
                        
     grp.em1.connect(self.record_event)
     grp.em2.connect(self.record_event)
     grp.em3.connect(self.record_event)
     self.result = None
     ev = grp.em1()
     self.assert_result(event=ev, type='em1', event_class=Event)
     ev = grp.em2()
     self.assert_result(event=ev, type='em2', event_class=BasicEvent)
     ev = grp.em3()
     self.assert_result(event=ev, type='typed_event', event_class=TypedEvent)
Ejemplo n.º 5
0
 def test_group_block(self):
     """EmitterGroup.block_all"""
     grp = EmitterGroup(em1=Event, em2=Event)
     def cb(ev):
         self.result = 1
     grp.em1.connect(self.record_event)
     grp.em2.connect(self.record_event)
     grp.connect(cb)
     
     self.result = None
     grp.block_all()
     try:
         grp.em1()
         grp.em2()
         grp(type='test_event')
     finally:
         grp.unblock_all()
     assert self.result is None
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        self.events = EmitterGroup(
            source=self,
            initialize=Event,
            resize=ResizeEvent,
            paint=PaintEvent,
            mouse_press=MouseEvent,
            mouse_release=MouseEvent,
            mouse_move=MouseEvent,
            mouse_wheel=MouseEvent,
            key_press=KeyEvent,
            key_release=KeyEvent,
            stylus=Event,
            touch=Event,
            close=Event,
        )

        # Store input and initialize backend attribute
        self._args = args
        self._kwargs = kwargs
        self._backend = None

        # Extract kwargs that are for us
        # Most are used in _set_backend
        self._our_kwargs = {}
        self._our_kwargs['title'] = kwargs.pop('title', 'Vispy canvas')
        self._our_kwargs['show'] = kwargs.pop('show', False)
        self._our_kwargs['autoswap'] = kwargs.pop('autoswap', True)
        self._our_kwargs['size'] = kwargs.pop('size', (800, 600))
        self._our_kwargs['position'] = kwargs.pop('position', None)

        # Initialise some values
        self._title = ''

        # Get app instance
        self._app = kwargs.pop('app', vispy.app.default_app)

        # Create widget now
        if 'native' in kwargs:
            self._set_backend(kwargs.pop('native'))
        else:
            self.create_native()
Ejemplo n.º 7
0
    def test_add_custom_emitter(self):
        class Emitter(EventEmitter):
            def _prepare_event(self, *args, **kwds):
                ev = super(Emitter, self)._prepare_event(*args, **kwds)
                ev.test_key = 1
                return ev

        class Source:
            pass
        src = Source()

        grp = EmitterGroup(source=src, em1=Emitter(type='test_event1'))
        grp.em1.connect(self.record_event)
        self.result = None
        ev = grp.em1()
        self.assert_result(event=ev, test_key=1, type='test_event1', source=src)
        
        grp.add(em2=Emitter(type='test_event2'))
        grp.em2.connect(self.record_event)
        self.result = None
        ev = grp.em2()
        self.assert_result(event=ev, test_key=1, type='test_event2', source=src)
Ejemplo n.º 8
0
 def __init__(self, interval=0.0, connect=None, iterations=-1, start=False, app=None):
     self.events = EmitterGroup(source=self, 
                     start=Event, 
                     stop=Event,
                     timeout=Event)
     #self.connect = self.events.timeout.connect
     #self.disconnect = self.events.timeout.disconnect
     
     # Get app instance and make sure that it has an associated backend 
     self._app = vispy.app.default_app if app is None else app
     self._app.use()
     
     # Instantiate the backed with the right class
     self._backend = self._app.backend_module.TimerBackend(self)
     
     self._interval = interval
     self._running = False
     self.iter_count = 0
     self.max_iterations = iterations
     if connect is not None:
         self.connect(connect)
     if start:
         self.start()
Ejemplo n.º 9
0
 def test_group_connect(self):
     grp = EmitterGroup(source=self, em1=Event)
     grp.connect(self.record_event)
     self.result = None
     ev = grp.em1(test_key=1)
     self.assert_result(event=ev, source=self, sources=[self, self], test_key=1)
Ejemplo n.º 10
0
 def __init__(self):
     self.events = EmitterGroup(source=self)
     self.events['changed'] = EventEmitter(event_class=ConfigEvent, source=self)
     self._config = {}