Python gi.repository.GLib 模块,timeout_add() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用gi.repository.GLib.timeout_add()

项目:ukui-menu    作者:ukui    | 项目源码 | 文件源码
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 )
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
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)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
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)
项目:python-gui    作者:neovim    | 项目源码 | 文件源码
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)