本文整理汇总了Python中Timer.Timer.getElapsedTime方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.getElapsedTime方法的具体用法?Python Timer.getElapsedTime怎么用?Python Timer.getElapsedTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer.Timer
的用法示例。
在下文中一共展示了Timer.getElapsedTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IndicatorController
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import getElapsedTime [as 别名]
class IndicatorController(object):
"""Indicator Controller class, all the actions are here"""
def __init__(self, indicator):
self.timer = Timer()
self.indicator = indicator
self.eventSource = None
# Function that start a study phase. It changes the label of
# the trigger and deactivate all the other indicator menu entries.
def startPhase(self, trigger):
self.indicator.throwNotification("Working phase has started!")
trigger.set_label("Stop Phase")
trigger.disconnect_by_func(self.startPhase)
trigger.connect('activate', self.stopPhase)
self.indicator.disableMenuItems(trigger)
self.timer.setStartTime()
self.eventSource = GObject.timeout_add(1000, self.labelChanger, self.timer.getPhaseDuration(), "Working Phase is finished!", trigger, "Start Phase")
# Stop the phase and reset the indicator label. It also
# enable all the indicator menu items
def stopPhase(self, trigger):
trigger.set_label("Start Phase")
trigger.disconnect_by_func(self.stopPhase)
trigger.connect('activate', self.startPhase)
self.indicator.enableMenuItems()
if (self.eventSource != None):
self.indicator.getView().set_label("", "")
GObject.source_remove(self.eventSource)
# Start break phase. It is the same of startPhase
def startBreak(self, trigger):
self.indicator.throwNotification("Break has started!")
trigger.set_label("Stop Break")
trigger.disconnect_by_func(self.startBreak)
trigger.connect('activate', self.stopBreak)
self.indicator.disableMenuItems(trigger)
self.timer.setStartTime()
self.eventSource = GObject.timeout_add(1000, self.labelChanger, self.timer.getBreakDuration(), "Break is finished! Back to work!", trigger, "Start Break")
# Stop break phase. It is the same of stopPhase
def stopBreak(self, trigger):
trigger.set_label("Start Break")
trigger.disconnect_by_func(self.stopBreak)
trigger.connect('activate', self.startBreak)
self.indicator.enableMenuItems()
if (self.eventSource != None):
self.indicator.getView().set_label("", "")
GObject.source_remove(self.eventSource)
# Start a work session, it is composed of some working phases
# an some break phases. For example, 3 working phases and 3
# break phases.
def startSession(self, trigger):
self.indicator.throwNotification("Session has started!")
trigger.set_label("Stop Session")
trigger.disconnect_by_func(self.startSession)
trigger.connect('activate', self.stopSession)
self.indicator.disableMenuItems(trigger)
self.timer.setStartTime()
self.eventSource = GObject.timeout_add(1000, self.labelChangerSession, trigger, self.timer.getPhaseDuration(), 0, self.timer.getSessionDuration())
def stopSession(self, trigger):
trigger.set_label("Start Session")
trigger.disconnect_by_func(self.stopSession)
trigger.connect('activate', self.startSession)
self.indicator.enableMenuItems()
if (self.eventSource != None):
self.indicator.getView().set_label("", "")
GObject.source_remove(self.eventSource)
# This function change the label of the indicator, and it is used
# inside a GObject loop. When the time arrive to a max, it will
# return False instead of True
def labelChanger(self, max, message, trigger, new_label):
clock = self.timer.getElapsedTime()
if (clock[0] == max):
self.indicator.throwNotification(message)
self.indicator.getView().set_label("", "")
self.indicator.rebuildMenu()
self.indicator.playSound()
return False
time = self.sanitizeTime(clock)
self.indicator.changeLabel(time[0], time[1])
return True
# This function is similar to labelChanger, but it is design specifically
# for the session operation. It will call continuously the same function
# as long as the counter is less than sessionDuration
def labelChangerSession(self, trigger, max, counter, maxCounter):
clock = self.timer.getElapsedTime()
if (counter==maxCounter):
self.indicator.throwNotification("Session is finished!")
self.indicator.getView().set_label("", "")
self.indicator.rebuildMenu()
trigger.set_label("Start Session")
self.indicator.playSound()
return False
if (clock[0] == max and max == self.timer.getPhaseDuration()):
#.........这里部分代码省略.........