本文整理汇总了Python中timer.Timer.time方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.time方法的具体用法?Python Timer.time怎么用?Python Timer.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.time方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: acquisition
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import time [as 别名]
def acquisition(config):
timer = Timer()
getch = _Getch()
last_char = ""
last_char2 = ""
nl_count = 0
bs_count = 0
char_count = 0
quit = False
while not quit:
# on lit un caractère
my_char = getch()
char_count += 1
# saut de ligne:
if my_char == "\r":
print
nl_count += 1
# reset le dernier caractère
last_char = ""
last_char2 = ""
# autre caractère
else:
nl_count = 0
# caractère BACKSPACE
if my_char == "\x08" or my_char == "\x7f":
# on compte le nb de backspace pour les stats
bs_count += 1
# écrire un backspace déplace simplement le curseur
# il faut effacer avec un espace
sys.stdout.write("\x08 \x08")
# reset le dernier caractère
last_char = ""
else:
sys.stdout.write(my_char)
# si un précédent caractère était présent
if last_char != "":
# récupérer le temps entre deux frappes
t = timer.time()
# ajout dans la configuration si l'intervalle semble correct
if t < 1:
config.add(last_char + my_char, t)
if last_char2 != "":
config.add(last_char2 + last_char + my_char, t)
# sauvegarde du dernier caractère
last_char2 = last_char
last_char = my_char
# deux appuis simultanés sur ENTER quittent la boucle
if nl_count == 2:
quit = True
# reset du chronomètre
timer.start()
return float(bs_count) / float(char_count) * 100
示例2: App
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import time [as 别名]
class App(GObject.GObject):
backend = None
config = None
ind = None
timer = None
_current_project = None
_current_task = None
projects = []
tasks = []
timer_started = None
timer_stopped = None
__gsignals__ = {
"current-project-changed": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()),
"current-task-changed": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()),
}
def __init__(self, *args):
GObject.GObject.__init__(self)
self.config = Config()
self.backend = Backend(self.config)
self.timer = Timer(self.config)
# get all projects
for p in models.Project.select():
self.projects.append(p)
def set_current_project(self, project):
self._current_project = project
self.emit("current-project-changed")
def get_current_project(self):
return self._current_project
def set_current_task(self, task):
self._current_task = task
self.emit("current-task-changed")
def get_current_task(self):
return self._current_task
def save_current_timer(self):
w = models.WorklogEntry()
w.started_at = self.timer.started_at
w.stopped_at = self.timer.stopped_at
w.seconds = self.timer.time()
w.task = self.get_current_task()
print w.seconds
if w.seconds == 0:
raise ValueError("A timer with %i seconds will not be saved" % w.seconds)
w.save()