當前位置: 首頁>>代碼示例>>Python>>正文


Python event.EmitterGroup類代碼示例

本文整理匯總了Python中vispy.util.event.EmitterGroup的典型用法代碼示例。如果您正苦於以下問題:Python EmitterGroup類的具體用法?Python EmitterGroup怎麽用?Python EmitterGroup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EmitterGroup類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_add_custom_emitter

    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)
開發者ID:LiloD,項目名稱:vispy,代碼行數:31,代碼來源:test_emitter_group.py

示例2: Config

class Config(object):
    """ Container for global settings used application-wide in vispy.
    
    Events:
    -------
    Config.events.changed - Emits ConfigEvent whenever the configuration changes.
    """
    def __init__(self):
        self.events = EmitterGroup(source=self)
        self.events['changed'] = EventEmitter(event_class=ConfigEvent, source=self)
        self._config = {}
    
    def __getitem__(self, item):
        return self._config[item]
    
    def __setitem__(self, item, val):
        self._config[item] = val
        # inform any listeners that a configuration option has changed
        self.events.changed(changes={item:val})
        
    def update(self, **kwds):
        self._config.update(kwds)
        self.events.changed(changes=kwds)

    def __repr__(self):
        return repr(self._config)
開發者ID:ds604,項目名稱:vispy,代碼行數:26,代碼來源:__init__.py

示例3: test_group_connect

 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)
開發者ID:LiloD,項目名稱:vispy,代碼行數:12,代碼來源:test_emitter_group.py

示例4: test_group_construction

    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)
開發者ID:Zulko,項目名稱:vispy,代碼行數:14,代碼來源:test_emitter_group.py

示例5: test_group_disconnect

    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
開發者ID:LiloD,項目名稱:vispy,代碼行數:12,代碼來源:test_emitter_group.py

示例6: test_group_ignore

 def test_group_ignore(self):
     """EmitterGroup.block_all"""
     grp = EmitterGroup(em1=Event)
     grp.em1.connect(self.error_event)
     with use_log_level("warning", record=True, print_msg=False) as l:
         grp.em1()
     assert_true(len(l) >= 1)
     grp.ignore_callback_errors = False
     assert_raises(RuntimeError, grp.em1)
     grp.ignore_callback_errors = True
     with use_log_level("warning", record=True, print_msg=False) as l:
         grp.em1()
     assert_true(len(l) >= 1)
開發者ID:Zulko,項目名稱:vispy,代碼行數:13,代碼來源:test_emitter_group.py

示例7: __init__

 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._last_emit_time = None
     self.iter_count = 0
     self.max_iterations = iterations
     if connect is not None:
         self.connect(connect)
     if start:
         self.start()
開發者ID:alfonsodiecko,項目名稱:PYTHON_DIST,代碼行數:24,代碼來源:timer.py

示例8: __init__

 def __init__(self):
     self.events = EmitterGroup(source=self)
     self.events['changed'] = EventEmitter(event_class=ConfigEvent, source=self)
     self._config = {}
開發者ID:ds604,項目名稱:vispy,代碼行數:4,代碼來源:__init__.py

示例9: test_group_block

    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
開發者ID:LiloD,項目名稱:vispy,代碼行數:19,代碼來源:test_emitter_group.py

示例10: test_group_add_emitter

    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
開發者ID:LiloD,項目名稱:vispy,代碼行數:33,代碼來源:test_emitter_group.py

示例11: test_group_autoconnect

    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
開發者ID:LiloD,項目名稱:vispy,代碼行數:33,代碼來源:test_emitter_group.py

示例12: Timer

class Timer(object):
    """Timer used to schedule events in the future or on a repeating schedule.
    """
    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._last_emit_time = None
        self.iter_count = 0
        self.max_iterations = iterations
        if connect is not None:
            self.connect(connect)
        if start:
            self.start()
            
        
    @property
    def app(self):
        """ The vispy Application instance on which this Timer is based.
        """
        return self._app
    

    @property
    def interval(self):
        return self._interval

    @interval.setter
    def interval(self, val):
        self._interval = val
        if self.running:
            self.stop()
            self.start()

    @property
    def running(self):
        return self._running

    def start(self, interval=None, iterations=None):
        """Start the timer. 

        A timeout event will be generated every *interval* seconds.
        If *interval* is None, then self.interval will be used.
        
        If *iterations* is specified, the timer will stop after 
        emitting that number of events. If unspecified, then 
        the previous value of self.iterations will be used. If the value is 
        negative, then the timer will continue running until stop() is called.
        """
        self.iter_count = 0
        if interval is not None:
            self.interval = interval
        if iterations is not None:
            self.max_iterations = iterations
        self._backend._vispy_start(self.interval)
        self._running = True
        self._last_emit_time = None
        self.events.start(type='timer_start')
        
        
    def stop(self):
        """Stop the timer."""
        self._backend._vispy_stop()
        self._running = False
        self.events.stop(type='timer_stop')
        
    # use timer.app.run() and .quit() instead.
    #def run_event_loop(self):
        #"""Execute the event loop for this Timer's backend.
        #"""
        #return self._backend._vispy_run()
        
    #def quit_event_loop(self):
        #"""Exit the event loop for this Timer's backend.
        #"""
        #return self._backend._vispy_quit()
    
    @property
    def native(self):
        """ The native timer on which this Timer is based.
        """
        return self._backend._vispy_get_native_timer()
    
    def _timeout(self, *args):
        # called when the backend timer has triggered.
        if not self.running:
            return
#.........這裏部分代碼省略.........
開發者ID:alfonsodiecko,項目名稱:PYTHON_DIST,代碼行數:101,代碼來源:timer.py


注:本文中的vispy.util.event.EmitterGroup類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。