我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用gi.repository.GLib.timeout_add()。
def __init__( self, applet, iid ): self.data_path = os.path.join('/','usr','share','ukui-menu') self.applet = applet self.settings = Gio.Settings.new("org.ukui.ukui-menu") self.settings.connect("changed::show-category-menu",self.changeMenuState) self.state = self.settings.get_boolean("show-category-menu") self.actionNormal = Gtk.Action(name="UkuiNormalMenu", label=_("Normal Menu"), tooltip=None, stock_id="gtk-about") self.actionNormal.connect("activate", self.LoadNormalMenu) self.actionCategory = Gtk.Action(name="UkuiCategoryMenu", label=_("Category Menu"), tooltip=None, stock_id="gtk-about") self.actionCategory.connect("activate", self.LoadCategoryMenu) self.createPanelButton() self.applet.set_flags( UkuiPanelApplet.AppletFlags.EXPAND_MINOR ) self.applet.connect( "button-press-event", self.showMenu ) self.applet.connect( "enter-notify-event", self.enter_notify ) self.applet.connect( "leave-notify-event", self.leave_notify ) GLib.timeout_add(500, self.InitMenu )
def timer(self, name, delay, callback, *data, **kwdata): """ Runs callback after specified number of seconds. Uses GLib.timeout_add_seconds with small wrapping to allow named timers to be canceled by reset() call """ method = GLib.timeout_add_seconds if delay < 1 and delay > 0: method = GLib.timeout_add delay = delay * 1000.0 if name is None: # No wrapping is needed, call GLib directly method(delay, callback, *data, **kwdata) else: if name in self._timers: # Cancel old timer GLib.source_remove(self._timers[name]) # Create new one self._timers[name] = method(delay, self._callback, name, callback, *data, **kwdata)
def on_lblMarkup_activate_link(self, trash, link): if link.startswith("quick://"): action = self.parser.restart(link[8:]).parse() self.editor.reset_active_component() self.editor.set_action(action, from_custom=True) elif link == "grab://trigger_button": def cb(action): action = TriggerAction(254, 255, action) self.editor.set_action(action, from_custom=True) self.editor.force_page("trigger") b = SimpleChooser(self.app, "buttons", cb) b.set_title(_("Select Button")) b.hide_axes() b.show(self.editor.window) elif link.startswith("page://"): def cb(): self.editor.force_page(link[7:]) GLib.timeout_add(0.1, cb)
def _gtk_configure(self, widget, event): def resize(*args): self._resize_timer_id = None width, height = self._window.get_size() columns = width // self._cell_pixel_width rows = height // self._cell_pixel_height if self._screen.columns == columns and self._screen.rows == rows: return self._bridge.resize(columns, rows) if not self._screen: return if event.width == self._pixel_width and \ event.height == self._pixel_height: return if self._resize_timer_id is not None: GLib.source_remove(self._resize_timer_id) self._resize_timer_id = GLib.timeout_add(250, resize)