当前位置: 首页>>代码示例>>Python>>正文


Python EmitterGroup.start方法代码示例

本文整理汇总了Python中vispy.util.event.EmitterGroup.start方法的典型用法代码示例。如果您正苦于以下问题:Python EmitterGroup.start方法的具体用法?Python EmitterGroup.start怎么用?Python EmitterGroup.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vispy.util.event.EmitterGroup的用法示例。


在下文中一共展示了EmitterGroup.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Timer

# 需要导入模块: from vispy.util.event import EmitterGroup [as 别名]
# 或者: from vispy.util.event.EmitterGroup import start [as 别名]
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,代码行数:103,代码来源:timer.py


注:本文中的vispy.util.event.EmitterGroup.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。