本文整理汇总了Python中clock.Clock类的典型用法代码示例。如果您正苦于以下问题:Python Clock类的具体用法?Python Clock怎么用?Python Clock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Clock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tick
def tick(self):
""" advance the clock by one second """
previous_hour = self._hours
# super().tick()
Clock.tick(self)
if (self._hours < previous_hour):
self.advance()
示例2: now
def now(cls, clock=None, zone=None):
if clock is None and zone is None:
return cls.now(Clock.system_default_zone())
elif zone is None:
return cls.now(Clock.system(zone))
else:
now = clock.instant()
offset = clock.getZone().getRules().getOffset(now)
return cls.of_epoch_second(now.get_epoch_second(), now.get_nano(), offset)
示例3: System
class System(object):
def reset(self, seed=None):
self.feq = FutureEventsQueue()
self.clock = Clock()
self.stats = Stats()
if seed is not None:
random.seed(seed)
self.initialize()
def update_averages(self, overall_stats):
for stat in self.stats:
overall_stats.add(stat, self.stats.get(stat))
def run(self, trials, duration, seed=None):
overall_stats = Stats()
for i in range(trials):
self.reset(seed)
while self.feq.has_events():
event = self.feq.next_event()
self.clock.update(event.time)
if self.clock.has_run(duration):
break
self.update()
self.handle(event)
self.finalize()
self.update_averages(overall_stats)
print "Completed trial %d/%d" % (i+1, trials)
print
return overall_stats
def schedule_event(self, event):
""" Convenience function """
self.feq.schedule_event(event)
def initialize(self):
""" System-specific variables are initialized here and the
first event is scheduled """
pass
def update(self):
""" Anything that must be updated every single iteration
regardless of event type goes here
"""
pass
def handle(self, event):
""" Updating of system state and stats, and scheduling of next event
should go here """
pass
def finalize(self):
""" All final calculations go here before the stats object is
returned """
pass
示例4: handle_ticktock_to_next_update
def handle_ticktock_to_next_update(force):
t = res_manager.get_next_update_time()
if t < 0:
return False
else:
if force:
while Clock.get() < t:
Clock.tick()
return handle_ticktock(1)
else:
return handle_ticktock(t - Clock.get())
示例5: main
def main():
database = Database()
alarmLog = AlarmLog()
summarizer = Summarizer(database, alarmLog)
clock = Clock(summarizer)
alarmWriter = AlarmWriter(summarizer)
driver1 = Driver(1, summarizer)
clock.start()
alarmWriter.start()
driver1.start()
sleep(1000)
示例6: __init__
def __init__(self,screen,bgcolor):
screenHeight = screen.get_height()
screenWidth = screen.get_width()
targetHeight = HDMIClock.defaultHeight * screenHeight
Clock.__init__(self,targetHeight,HDMIClock.defaultColor)
width = self.clockFace.get_width()
height = self.clockFace.get_height()
self.dimensions = pygame.Rect((screenWidth-width)/2,(screenHeight-height)/2,width,height)
self.screen = screen
self.bgcolor = bgcolor
示例7: tick_or_tock
def tick_or_tock():
global __on_tick
if not __on_tick:
res_manager.changed_res_set.clear()
res_manager.run_timer()
__on_tick = True
if len(__clock_tick_event_receiver) > 0:
for receiver in __clock_tick_event_receiver:
notify_id = sky_client.write((RECEIVER, "Event", receiver),fill_content_id=True)
#sky_client.take(template=(TARGET, notify_id, '?'))
else:
res_manager.run_listener()
Clock.tick()
report()
__on_tick = False
示例8: __init__
def __init__(self, speed, *groups):
BackgroundObject.__init__(self, (0, 0), speed, *groups)
self.image = pygame.image.load('gfx/terrain/example_editor.png').convert_alpha()
self.rect = pygame.Rect((0, app.screen_height - self.image.get_height()),
(0, 0))
self.clock = Clock()
示例9: run_timer
def run_timer():
clk = Clock.get()
if clk not in timers:
return
callback_list = timers[clk]
for callback in callback_list:
callback()
示例10: reset
def reset(self, seed=None):
self.feq = FutureEventsQueue()
self.clock = Clock()
self.stats = Stats()
if seed is not None:
random.seed(seed)
self.initialize()
示例11: get_next_update_time
def get_next_update_time():
while len(timers) > 0:
t = min(timers)
if t < Clock.get():
timers.pop(t, None)
else:
return t
return -1
示例12: clockinit
def clockinit(args):
POL = GPIO("480", "out")
CLK = GPIO("481", "out")
clock = Clock(CLK, POL)
statestore = StateStore(clock)
statestore.restore()
nvramstore = NVRAMStore(clock)
if args.require_nvram and not nvramstore.restore():
print("Cannot read clock state from the NVRAM. Exiting...")
sys.exit(1)
if args.invert:
clock.inverse = True
if args.uninvert:
clock.inverse = False
if args.state:
clock.setState(args.state)
return (clock, statestore, nvramstore)
示例13: run
def run(self):
"""Method that starts the game running."""
timeController = Clock(self.S_TURN)
self.isRunning = True
while self.isRunning:
# start turn
timeController.start()
leftTime = self.S_TURN
#TODO think if input should be processed inside the inner loop
# process user input to Game
self.iMngr.processUserInput(self)
#isRunning = not self.iMngr.closedGame()
while timeController.time_left() > self.S_UPDATE:
#sync with remote
self.nMngr.updateGame(self)
# update state of the game
self.uMngr.updateGame(self)
#newState = self.readState()
#self.world.update(newState)
# play sounds
self.sMngr.updateGame(self)
# render
self.gMngr.draw(timeController.time_left(), self)
#self.worldView.draw()
# sleep if necessary
timeController.sleep()
示例14: report_xml
def report_xml(file_name="report.xml", clock=-1):
cur = Clock.get()
if clock < 0:
clock += cur
content = E.content(clock=str(clock))
for name in pool:
value = str(pool.get(name).get_value(clock))
content.insert(0, E.feature(E.name(name), E.currentValue(value)))
with open(file_name, "w") as fout:
fout.write(tostring(content, encoding='utf-8', xml_declaration=True, pretty_print=True))
示例15: get_value
def get_value(value, v):
if utils.is_callable(value):
return value()
elif value == "$self":
return v
elif value == "$clock":
return Clock.get()
elif utils.is_string(value) and value.startswith("$"):
return res_manager.get(value[1:])
else:
return value