def OnTimer(self, id, timeVal): if id: timer.kill_timer (id) if self.intervaler.IsTime() or self.bConnectNow : # do the work. try: self.dlg.SetWindowText(self.dlg.title + " - Working...") self.dlg.butOK.EnableWindow(0) self.dlg.butCancel.EnableWindow(0) self.CaptureOutput() try: exec(self.dlg.doWork) print "The last operation completed successfully." except: t, v, tb = sys.exc_info() str = "Failed: %s: %s" % (t, `v`) print str self.oldErr.write(str) tb = None # Prevent cycle finally: self.ReleaseOutput() self.dlg.butOK.EnableWindow() self.dlg.butCancel.EnableWindow() self.dlg.SetWindowText(self.dlg.title) else: now = time.time() nextTime = self.intervaler.GetNextTime() if nextTime: timeDiffSeconds = nextTime - now timeDiffMinutes = int(timeDiffSeconds / 60) timeDiffSeconds = timeDiffSeconds % 60 timeDiffHours = int(timeDiffMinutes / 60) timeDiffMinutes = timeDiffMinutes % 60 self.dlg.prompt1.SetWindowText("Next connection due in %02d:%02d:%02d" % (timeDiffHours,timeDiffMinutes,timeDiffSeconds)) self.timerId = timer.set_timer (self.intervaler.GetWakeupInterval(), self.OnTimer) self.bConnectNow = 0
def OnTimer(self, id, timeVal): if id: timer.kill_timer (id) if self.intervaler.IsTime() or self.bConnectNow : # do the work. try: self.dlg.SetWindowText(self.dlg.title + " - Working...") self.dlg.butOK.EnableWindow(0) self.dlg.butCancel.EnableWindow(0) self.CaptureOutput() try: exec(self.dlg.doWork) print "The last operation completed successfully." except: t, v, tb = sys.exc_info() str = "Failed: %s: %s" % (t, repr(v)) print str self.oldErr.write(str) tb = None # Prevent cycle finally: self.ReleaseOutput() self.dlg.butOK.EnableWindow() self.dlg.butCancel.EnableWindow() self.dlg.SetWindowText(self.dlg.title) else: now = time.time() nextTime = self.intervaler.GetNextTime() if nextTime: timeDiffSeconds = nextTime - now timeDiffMinutes = int(timeDiffSeconds / 60) timeDiffSeconds = timeDiffSeconds % 60 timeDiffHours = int(timeDiffMinutes / 60) timeDiffMinutes = timeDiffMinutes % 60 self.dlg.prompt1.SetWindowText("Next connection due in %02d:%02d:%02d" % (timeDiffHours,timeDiffMinutes,timeDiffSeconds)) self.timerId = timer.set_timer (self.intervaler.GetWakeupInterval(), self.OnTimer) self.bConnectNow = 0
def on_timer(timer_id, unused): # when Excel is starting up and PyXLL imports its modules there # is no Excel window, and so the COM object needed to register # the shortcut might not be available yet. try: xl_window = get_active_object() except RuntimeError: if time.time() - start_time > timeout: _log.error("Timed out waiting for Excel COM interface to become available.") timer.kill_timer(timer_id) _timer_id = None return # Get the Excel application from its window xl_app = Dispatch(xl_window).Application while _shortcuts_to_add: accelerator, macroname = _shortcuts_to_add.pop() try: xl_app.OnKey(accelerator, macroname) except: _log.error("Failed to add shortcut %s -> %s" % (accelerator, macroname), exc_info=True) _log.debug("Finished adding shortcuts") timer.kill_timer(timer_id) _timer_id = None
def OnDestroy(self, hwnd, msg, wparam, lparam): import timer if self.timer_id is not None: timer.kill_timer(self.timer_id) self.item_map = None if self.imageList: win32gui.ImageList_Destroy(self.imageList) FolderSelector_Parent.OnDestroy(self, hwnd, msg, wparam, lparam)
def _UpdateStatus(self): # We have problems with the order of events - we get the notification # events before the new states are available via GetItem. # Therefore, we start a one-shot, immediate timer, which ends up # at the end of the message queue, and we work. import timer if self.timer_id is not None: timer.kill_timer(self.timer_id) self.timer_id = timer.set_timer (0, self._DoUpdateStatus)
def increment (self, id, time): print 'x = %d' % self.x self.x = self.x + 1 # if we've reached the max count, # kill off the timer. if self.x > self.max: # we could have used 'self.id' here, too timer.kill_timer (id) win32event.SetEvent(self.event)
def increment(self, id, time): print('x = %d' % self.x) self.x = self.x + 1 # if we've reached the max count, # kill off the timer. if self.x > self.max: # we could have used 'self.id' here, too timer.kill_timer(id) win32event.SetEvent(self.event)
def _UpdateStatus(self): # We have problems with the order of events - we get the notification # events before the new states are available via GetItem. # Therefore, we start a one-shot, immediate timer, which ends up # at the end of the message queue, and we work. import timer if self.timer_id is not None: timer.kill_timer(self.timer_id) self.timer_id = timer.set_timer(0, self._DoUpdateStatus)
def Done(self): if self.timer_id is not None: timer.kill_timer(self.timer_id) self.timer_id = None return processors.ButtonProcessor.Done(self)
def _KillNotifyTimer(self): assert _thread.get_ident() == self.owner_thread_ident if self.notify_timer_id is not None: timer.kill_timer(self.notify_timer_id) self.LogDebug(2, "The notify timer with id=%d was stopped" % self.notify_timer_id) self.notify_timer_id = None
def poll_ioloop(timer_id, time): # if the kernel has been closed then run the event loop until it gets to the # stop event added by IPKernelApp.shutdown_request if self.kernel.shell.exit_now: _log.debug("IPython kernel stopping (%s)" % self.connection_file) timer.kill_timer(timer_id) loop.start() sys._ipython_kernel_running = False return # otherwise call the event loop but stop immediately if there are no pending events loop.add_timeout(0, lambda: loop.add_callback(loop.stop)) loop.start()
def OnDestroy(self, hwnd, msg, wparam, lparam): self.quitting = True timer.kill_timer(self.t) nid = (self.hwnd, 0) Shell_NotifyIcon(NIM_DELETE, nid) if self.running: if self.ipodder.download_engine: self.ipodder.download_engine.stop(timeout=3) begin = time.time() delay = time.time() - begin while self.running and delay < QUIT_TIMEOUT: time.sleep(0.1) delay = time.time() - begin PostQuitMessage(0) # Terminate the app.
def go(self): if self.timer_id is not None: timer.kill_timer(self.timer_id) self.timer_id = None if self.presscount >= 2: self.presscount = 0 self.fire() else: x = self.presscount if x > 0: self.presscount = 0 self.pending = True try: self.shell.SendKeys(';' * x) finally: self.pending = False
def _DoUpdateStatus(self, id, timeval): import timer self.timer_id = None timer.kill_timer(id) self._CheckSelectionsValid() names = [] num_checked = 0 for info, spec in self._YieldCheckedChildren(): num_checked += 1 if len(names) < 20: names.append(info[3]) status_string = "%s%s %d folder" % (self.select_desc_noun, self.select_desc_noun_suffix, num_checked) if num_checked != 1: status_string += "s" self.SetDlgItemText("IDC_STATUS1", status_string) self.SetDlgItemText("IDC_STATUS2", "; ".join(names))
def my_callback(timer_id, time): """Наша функция, которую вызовет таймер""" # Выведем информацию. print можно написать по разному. # Здесь вначале создадим строку 'my_callback {} time={}' в которую с помощью # format подставим два значения на место значков {} # format - функция присущая текстовым строкам # получившуюся после подстановки значений строку отправим print-у print('my_callback {} time={}'.format(timer_id, time)) # В выводе можем заметить, что все выведенные time отличаются почти на 100 global my_timer_id # Явно показываем, что берём глобальную переменную print('my_timer_id == timer_id {}'.format(my_timer_id == timer_id)) # как мы увидим, идентификаторы имеют одинаковое значение. global counter # Явно показываем, что берём глобальную переменную, # вдруг новую локальную создаст, или упадёт counter = counter + 1 # После 4-го срабатывания остановим таймер и удалим из ОС if counter == 4: # Останавливаем таймер. timer.kill_timer(timer_id)
def _DoUpdateStatus(self, id, timeval): import timer # Kill the timer first to prevent it firing again. self.timer_id = None timer.kill_timer(id) self._CheckSelectionsValid() names = [] num_checked = 0 for info, spec in self._YieldCheckedChildren(): num_checked += 1 if len(names) < 20: names.append(info[3]) status_string = "%s%s %d folder" % ( self.select_desc_noun, self.select_desc_noun_suffix, num_checked) if num_checked != 1: status_string += "s" self.SetDlgItemText("IDC_STATUS1", status_string) self.SetDlgItemText("IDC_STATUS2", "; ".join(names))
def Term(self): timer.kill_timer(self.timerid)
def check_for_shutdown(self, id, time): if self.app_state.wait_for_app_shutdown(None): timer.kill_timer(self.timer_id) self.destroy(self.window_id, None, None, None)
def stop_click_timer(self): # Stop the timer if self.click_timer: timer.kill_timer(self.click_timer) self.click_timer = None
def OnDestroy(self, msg): timer.kill_timer(self.timerid)
def update_monitor(timer_id, timer_t): if need_update(): if not (hasattr(st, 'displayed') and st.displayed): with_update_dialog(st) else: timer.kill_timer(timer_id)
def update_on_start(timer_id, timer_t): print "startup update" timer.kill_timer(timer_id) if need_update(): with_update_dialog(st)
def OnDestroy (self, msg): timer.kill_timer(self.timerid)
def _KillNotifyTimer(self): assert thread.get_ident() == self.owner_thread_ident if self.notify_timer_id is not None: timer.kill_timer(self.notify_timer_id) self.LogDebug(2, "The notify timer with id=%d was stopped" % self.notify_timer_id) self.notify_timer_id = None
def stop(self): if self.timerId: timer.kill_timer(self.timerId) self.timerId = None
def on_timer(self, timer_id, time): kill_timer(timer_id) self.destroyWindow()
def on_timer(timer_id, time): timer.kill_timer(timer_id) os.unlink(filename)
def stop(self): if self.timerId: timer.kill_timer (self.timerId) self.timerId = None
def _UpdateStatus(self): import timer if self.timer_id is not None: timer.kill_timer(self.timer_id) self.timer_id = timer.set_timer (0, self._DoUpdateStatus)