本文整理匯總了Python中Timer.on方法的典型用法代碼示例。如果您正苦於以下問題:Python Timer.on方法的具體用法?Python Timer.on怎麽用?Python Timer.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Timer
的用法示例。
在下文中一共展示了Timer.on方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Transition
# 需要導入模塊: import Timer [as 別名]
# 或者: from Timer import on [as 別名]
class Transition(PubSub):
def __init__(self, current, next):
PubSub.__init__(self)
self.current = current
self.next = next
self.timer = Timer()
self.timer.on('tick', self.on_timer)
self.timer.on('finished', self.on_timer_finished)
self.timer.on('started', self.on_timer_started)
self.parent_temp = None
def start(self, delay=0, duration='infinite', interval=0, repeats='infinite', message_type='tick'):
if self.current.parent == None or self.current == self.next:
return
if self.current.transitioning or self.next.transitioning:
print 'stopping'
return
self.emitter = self.current._stage
self.timer.start(self.emitter, delay, duration, interval, repeats, message_type)
def on_timer_started(self):
self.current.transitioning = True
self.next.transitioning = True
self.next.transition_target = [self.current.x, self.current.y, self.next.width, self.next.height]
self.on_start()
self.emit('started')
self.parent_temp = self.next.parent
self.current.parent.add_child(self.next)
if self.current.parent.on_stage:
self.next.enter(self.current)
def on_start(self):
pass
def on_timer(self):
pass
def on_stop(self):
pass
def on_timer_finished(self, event, **kwargs):
self.emit('finished', event = event, args = kwargs)
self.current.parent.remove_child(self.current)
self.current.transitioning = False
self.next.transitioning = False
self.next.transition_target = None
if self.parent_temp is not None:
self.parent_temp.add_child(self.current)
self.current.exit(self.next)
self.on_stop()