我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用gtk.timeout_add()。
def doIteration(self, delay): # flush some pending events, return if there was something to do # don't use the usual "while gtk.events_pending(): mainiteration()" # idiom because lots of IO (in particular test_tcp's # ProperlyCloseFilesTestCase) can keep us from ever exiting. log.msg(channel='system', event='iteration', reactor=self) if gtk.events_pending(): gtk.mainiteration(0) return # nothing to do, must delay if delay == 0: return # shouldn't delay, so just return self.doIterationTimer = gtk.timeout_add(int(delay * 1000), self.doIterationTimeout) # This will either wake up from IO or from a timeout. gtk.mainiteration(1) # block # note: with the .simulate timer below, delays > 0.1 will always be # woken up by the .simulate timer if self.doIterationTimer: # if woken by IO, need to cancel the timer gtk.timeout_remove(self.doIterationTimer) self.doIterationTimer = None
def __init__(self, ttrss): self.ttrss = ttrss self.menu = gtk.Menu() quitter = gtk.ImageMenuItem(gtk.STOCK_QUIT) quitter.set_always_show_image(True) self.menu.append(quitter) quitter.show() quitter.connect("activate", gtk.main_quit) self.viewer = ArticleViewer() self.viewer.on_hide = self.update_articles self.status_icon = gtk.StatusIcon() self.status_icon.set_from_icon_name("mail-read") self.update_headlines() self.to = gtk.timeout_add(1000 * 60, self.update_headlines) self.status_icon.connect("activate", self.toggle_viewer) self.status_icon.connect("popup-menu", self.show_menu)
def run(self, installSignalHandlers=1): self.startRunning(installSignalHandlers=installSignalHandlers) gtk.timeout_add(0, self.simulate) gtk.mainloop()
def simulate(self): """Run simulation loops and reschedule callbacks. """ global _simtag if _simtag is not None: gtk.timeout_remove(_simtag) self.runUntilCurrent() timeout = min(self.timeout(), 0.1) if timeout is None: timeout = 0.1 _simtag = gtk.timeout_add(int(timeout * 1010), self.simulate) # grumble
def simulate(self): """Run simulation loops and reschedule callbacks. """ global _simtag if _simtag is not None: gtk.timeout_remove(_simtag) self.iterate() timeout = min(self.timeout(), 0.1) if timeout is None: timeout = 0.1 _simtag = gtk.timeout_add((timeout * 1010), self.simulate) # grumble
def loginReport(self, txt): print 'setting login report',repr(txt) self.logstat.set_text(txt) if not (self._resetTimeout is None): gtk.timeout_remove(self._resetTimeout) self._resetTimeout = gtk.timeout_add(59000, self.loginReset)
def update_articles(self): ids = self.viewer.read self.ttrss.updateArticle(ids, 0, 2) self.viewer.read = [] gtk.timeout_remove(self.to) self.update_headlines() self.to = gtk.timeout_add(1000 * 60, self.update_headlines)
def change_avtar(self,event): print 'ok' if self.isBanner_mode: self.img=cv2.cv.LoadImage(templates+"Banner_2.png") self.timer_id=gtk.timeout_add(20*1000,self.reset) self.isBanner_mode=False self.drawing_area.queue_draw()