本文整理匯總了Python中repeated_timer.RepeatedTimer類的典型用法代碼示例。如果您正苦於以下問題:Python RepeatedTimer類的具體用法?Python RepeatedTimer怎麽用?Python RepeatedTimer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RepeatedTimer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DashieSampler
class DashieSampler(object):
def __init__(self, app, interval):
self._app = app
self._timer = RepeatedTimer(interval, self._sample)
def stop(self):
self._timer.stop()
def name(self):
'''
Child class implements this function
'''
return 'UnknownSampler'
def sample(self):
'''
Child class implements this function
'''
return {}
def _send_event(self, widget_id, body):
body['id'] = widget_id
body['updateAt'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0000')
formatted_json = 'data: %s\n\n' % (json.dumps(body))
self._app.last_events[widget_id] = formatted_json
for event_queue in self._app.events_queue.values():
event_queue.put(formatted_json)
def _sample(self):
data = self.sample()
if data:
self._send_event(self.name(), data)
示例2: __init__
class DatDashSampler:
def __init__(self, app, interval):
self._app = app
self._timer = RepeatedTimer(interval, self._sample)
def stop(self):
self._timer.stop()
def name(self):
"""
Child class implements this function
"""
return "UnknownSampler"
def sample(self):
"""
Child class implements this function
"""
return {}
def _send_event(self, widget_id, body):
body["id"] = widget_id
body["updateAt"] = \
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S +0000")
formatted_json = "data: %s\n\n" % (json.dumps(body))
self._app.last_events[widget_id] = formatted_json
for event_queue in self._app.events_queue.values():
event_queue.put(formatted_json)
def _sample(self):
data = self.sample()
if data:
self._send_event(self.name(), data)
示例3: __init__
class MultiTouchInput:
current_state = 0
current_state_counter = [0]*12
touch_timer = None
def __init__(self, ipcon, key_queue):
if not config.UID_MULTI_TOUCH_BRICKLET:
print("Not Configured: Multi Touch")
return
self.key_queue = key_queue
self.ipcon = ipcon
self.mt = MultiTouch(config.UID_MULTI_TOUCH_BRICKLET, self.ipcon)
try:
self.mt.get_electrode_sensitivity()
print("Found: Multi Touch ({0})").format(config.UID_MULTI_TOUCH_BRICKLET)
except:
print("Not Found: Multi Touch ({0})").format(config.UID_MULTI_TOUCH_BRICKLET)
return
self.mt.set_electrode_sensitivity(100)
self.mt.register_callback(self.mt.CALLBACK_TOUCH_STATE, self.cb_touch_state)
self.touch_timer = RepeatedTimer(0.1, self.touch_tick)
def stop(self):
if self.touch_timer is not None:
self.touch_timer.stop()
def state_to_queue(self, state):
for item in config.KEYMAP_MULTI_TOUCH.items():
if state & (1 << item[0]):
self.key_queue.put(item[1])
def touch_tick(self):
state = 0
for i in range(12):
if self.current_state & (1 << i):
self.current_state_counter[i] += 1
else:
self.current_state_counter[i] = 0
if self.current_state_counter[i] > 5:
state |= (1 << i)
if state != 0:
self.state_to_queue(state)
def cb_touch_state(self, state):
changed_state = self.current_state ^ state
self.current_state = state
self.state_to_queue(changed_state & self.current_state)
示例4: on_complete
def on_complete(self):
self.animation_loader.on_complete()
self.interval_animation.stop()
if os.path.isfile(self.NODE_JS_BINARY_TARFILE_FULL_PATH) :
os.remove(self.NODE_JS_BINARY_TARFILE_FULL_PATH)
node_js = NodeJS()
npm = NPM()
self.animation_loader = AnimationLoader(["[= ]", "[ = ]", "[ = ]", "[ = ]", "[ =]", "[ = ]", "[ = ]", "[ = ]"], 0.067, "Installing npm dependencies ")
self.interval_animation = RepeatedTimer(self.animation_loader.sec, self.animation_loader.animate)
try :
npm.getCurrentNPMVersion(True)
except Exception as e:
if node_variables.NODE_JS_OS == "win" :
sublime.error_message("Can't use \"npm\"! To use features that requires \"npm\", you must install it! Download it from https://nodejs.org site")
print("Error: "+traceback.format_exc())
try :
npm.install_all()
except Exception as e :
#print("Error: "+traceback.format_exc())
pass
self.animation_loader.on_complete()
self.interval_animation.stop()
if node_js.getCurrentNodeJSVersion(True) == self.NODE_JS_VERSION :
sublime.active_window().status_message("Node.js "+self.NODE_JS_VERSION+" installed correctly! NPM version: "+npm.getCurrentNPMVersion(True))
else :
sublime.active_window().status_message("Can't install Node.js! Something went wrong during installation.")
示例5: __init__
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.title(self, 'OpenSlides')
tk.Tk.resizable(self, width=False, height=False)
self.protocol('WM_DELETE_WINDOW', self.on_close_app)
self.root = tk.Frame(self, bg=self.cget('bg'))
self.root.pack(side="top", fill="both", expand = True)
self.btn_settings = None
self.btn_db_backup = None
self.btn_sync_db = None
self.btn_reset_admin = None
self.chb_auto_svr = None
self.btn_server = None
self.backup_timer = RepeatedTimer(self.on_backup_timer)
self.lbl_host = None
self.lbl_port = None
if not self.initialize_gui():
self.quit()
self.createMenuBar()
self.createMainframe()
示例6: updateNPMDependencies
def updateNPMDependencies():
npm = NPM()
try :
npm.getCurrentNPMVersion(True)
except Exception as e:
print("Error: "+traceback.format_exc())
return
animation_loader = AnimationLoader(["[= ]", "[ = ]", "[ = ]", "[ = ]", "[ =]", "[ = ]", "[ = ]", "[ = ]"], 0.067, "Updating npm dependencies ")
interval_animation = RepeatedTimer(animation_loader.sec, animation_loader.animate)
try :
npm.update_all(False)
except Exception as e:
pass
animation_loader.on_complete()
interval_animation.stop()
示例7: run_game_loop
def run_game_loop(self):
self.frame_rendered(0)
self.timer = RepeatedTimer(0.1, self.tick)
while self.loop:
key = self.kp.read_single_keypress().lower()
if key == 'a':
self.move_paddle(0, -1)
elif key == 's':
self.move_paddle(0, 1)
elif key == 'k':
self.move_paddle(1, -1)
elif key == 'l':
self.move_paddle(1, 1)
elif key == 'r':
self.init_game()
elif not config.HAS_GUI and key == 'q':
break
if not config.IS_LED_STRIP_V2:
self.led_strip.register_callback(self.led_strip.CALLBACK_FRAME_RENDERED, None)
else:
self.led_strip.register_callback(self.led_strip.CALLBACK_FRAME_STARTED, None)
self.timer.stop()
self.kp.stop()
示例8: run_game_loop
def run_game_loop(self):
self.frame_rendered(0)
self.drop_timer = RepeatedTimer(1.0, self.drop_tetromino)
while self.loop:
key = self.kp.read_single_keypress()
if key == 'a':
self.speaker.beep_input()
self.move_tetromino(0, -1, self.tetromino_form)
elif key == 'd':
self.speaker.beep_input()
self.move_tetromino(0, 1, self.tetromino_form)
elif key == 's':
self.speaker.beep_input()
self.move_tetromino(1, 0, self.tetromino_form)
elif key == 'k':
self.speaker.beep_input()
self.move_tetromino(0, 0, (self.tetromino_form-1) % 4)
elif key == 'l':
self.speaker.beep_input()
self.move_tetromino(0, 0, (self.tetromino_form+1) % 4)
elif key == 'r':
self.init_game()
elif not config.HAS_GUI and key == 'q':
break
if not config.IS_LED_STRIP_V2:
self.led_strip.register_callback(self.led_strip.CALLBACK_FRAME_RENDERED, None)
else:
self.led_strip.register_callback(self.led_strip.CALLBACK_FRAME_STARTED, None)
self.drop_timer.stop()
self.kp.stop()
示例9: updateNPMDependencies
def updateNPMDependencies():
npm = NPM()
try :
npm.getCurrentNPMVersion(True)
except Exception as e:
if node_variables.NODE_JS_OS == "win" :
sublime.active_window().status_message("Can't use \"npm\"! To use features that requires \"npm\", you must install it! Download it from https://nodejs.org site")
print("Error: "+traceback.format_exc())
return
animation_loader = AnimationLoader(["[= ]", "[ = ]", "[ = ]", "[ = ]", "[ =]", "[ = ]", "[ = ]", "[ = ]"], 0.067, "Updating npm dependencies ")
interval_animation = RepeatedTimer(animation_loader.sec, animation_loader.animate)
try :
npm.update_all(False)
except Exception as e:
pass
animation_loader.on_complete()
interval_animation.stop()
示例10: __init__
def __init__(self, msg_func, master):
self.msg_func = msg_func
self.master = master
self.child_process = None
self.output_queue = queue.Queue()
self.output_read_thread = None
self.output_mutex = threading.RLock()
self.update_timer = RepeatedTimer(self.on_update_timer)
self._exitcode = None
示例11: start
def start(self, info):
logging.info('Master Starts')
self.last_wake_time = datetime.datetime.utcnow()
self.is_started = True
self.pop_forever_handler = threading.Thread(target=self.start_popping_tasks)
self.pop_forever_handler.start()
self.repeated_timer = RepeatedTimer(self.clean_time_gap, self.notice_refresh, None)
示例12: __init__
def __init__(self):
# GPIO番號でピンを指定
# ServoBlasterの起動(rootで実行する必要あり)
# 50%指定時の中間位置を--maxで調整する。--max=200がちょうどよかった
os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod --idle-timeout=2000 --max=200')
self.servos = []
for index in RPiServoblasterController.PIN_MAP.iterkeys():
pin = RPiServoblasterController.PIN_MAP[index]
# サーボを作る
self.servos.append(SG90Servoblaster(pin, self.getPartName(index)))
# self.positionの內容を定期的にcommit()を使ってservoblasterで反映する
self.positions = []
self.timer = RepeatedTimer(RPiServoblasterController.COMMIT_INTERVAL_SEC, self.commit)
self.timer.start()
示例13: __init__
def __init__(self, address=0x40):
# I2C経由でのコントロール用ライブラリ
# https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
self.pwm = Adafruit_PCA9685.PCA9685(address, busnum=1)
self.pwm.set_pwm_freq(SG90PCA9685.PWM_FREQ)
self.servos = []
for index in RPiPCA9685Controller.PIN_MAP.iterkeys():
pin = RPiPCA9685Controller.PIN_MAP[index]
# サーボを作る
self.servos.append(SG90PCA9685(pin, self.getPartName(index), self.pwm))
# self.positionの內容を定期的にcommit()を使ってservoblasterで反映する
self.positions = []
self.timer = RepeatedTimer(RPiPCA9685Controller.COMMIT_INTERVAL_SEC, self.commit)
self.timer.start()
示例14: start_timer
def start_timer(self):
self.threading_timer = RepeatedTimer(3, self.refresh)
self.threading_timer.start()
示例15: BettingDisplay
class BettingDisplay():
def __init__(self, parent, meeting):
self.parent = parent
self.display_type = 'odds'
self.date = datetime.date.today().strftime("%Y-%m-%d") #Currently will need to be restarted each day
self.meeting = meeting #PLACEHOLDER
self.schedule = Schedule(self.date, self.meeting)
self.races = self.schedule.meetings[0].races
self.next_race = None
self.set_next_race()
self.odds_var = StringVar()
self.title_var = StringVar()
self.dets_var = StringVar()
self.build_display()
self.start_timer()
print("STARTED SUCCESSFULLY")
def set_next_race(self):
next_race = None
found = False
for race in self.races:
cur_time = int(datetime.datetime.now().strftime("%H%M%S"))
race_time = int(re.sub('[:]', '', race.time))
if race_time > cur_time and not found:
next_race = race
found = True
if next_race is not self.next_race:
self.next_race = next_race
def start_timer(self):
self.threading_timer = RepeatedTimer(3, self.refresh)
self.threading_timer.start()
def refresh(self):
if self.display_type == 'odds':
self.set_next_race()
self.next_race.load_odds()
#---TEMP---#
horse_nums = ['']*20
for i in range(min(20, len(self.next_race.entries))):
horse_nums[i] = str(self.next_race.entries[i].number)
horse_names = ['']*20
for i in range(min(20, len(self.next_race.entries))):
horse_names[i] = str(self.next_race.entries[i].name)
win_odds = ['']*20
for i in range(min(20, len(self.next_race.entries))):
win_odds[i] = str(self.next_race.entries[i].odds_win)
lst = horse_nums + horse_names + win_odds
odds_str = TEST_TEMPLATE.format(lst)
title_str = TITLE_TEMPLATE.format(name=self.next_race.name)
dets_str = TIME_TEMPLATE.format(time=self.next_race.time, venue=self.next_race.meeting.venue, meet_no=self.next_race.meeting.number, country=self.next_race.meeting.country)
self.title_var.set(title_str)
self.dets_var.set(dets_str)
self.odds_var.set(odds_str)
#---TEMP END---#
elif self.display_type == 'test':
self.title_var.set('test')
self.dets_var.set('')
self.odds_var.set('')
def build_display(self):
#----TEMP----
self.cur_race_name = StringVar()
self.cur_race_time = StringVar()
self.title_text = Label(self.parent, fg="white", bg="black", font=("Courier", 40, "bold"), textvariable=self.title_var)
self.title_text.place(relx = 0.5, rely = 0, anchor=N, height = 80, width=1100)
self.dets_text = Label(self.parent, textvariable=self.dets_var, fg="white", bg="black", font=("Courier", 20, "bold"))
self.dets_text.place(relx = 0.5, y = 80, anchor=N, height = 30, width=1100)
self.odds_text = Label(self.parent, textvariable=self.odds_var, fg="white", bg="black", font=("Courier", 20, "bold"))
self.odds_text.place(relx = 0.5, y = 110, anchor=N, width=1100, height = 600)
self.quitbutton = Button(self.parent, text='quit', command=self.quitclick)
self.quitbutton.place(relx = 0.5, rely = 1, anchor=S)
#---TEMP END ---#
def quitclick(self):
self.threading_timer.stop()
self.parent.destroy()