Python gi.repository.Gtk 模块,accelerator_parse() 实例源码

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

项目:Linalfred    作者:PeterHo    | 项目源码 | 文件源码
def grab(self, accelerator):
        keyVal, modifiers = Gtk.accelerator_parse(accelerator)
        if not accelerator or (not keyVal and not modifiers):
            return

        keyCode = self.keymap.get_entries_for_keyval(keyVal)[1][0].keycode
        modifiers = int(modifiers)

        catch = error.CatchError(error.BadAccess)
        for ignored_mask in self.ignored_masks:
            mod = modifiers | ignored_mask
            self.root.grab_key(keyCode, mod, True, X.GrabModeAsync, X.GrabModeSync, onerror=catch)
        self.display.sync()
        if catch.get_error():
            return False
        self.hotKeyList.append(HotKey().set(keyVal=keyVal, keyCode=keyCode, modifiers=modifiers))
        return True
项目:draobpilc    作者:awamper    | 项目源码 | 文件源码
def _refresh(self):
        self._store.clear()
        sorted_keybindings = [(k, self._keybindings[k]) for k in sorted(
            self._keybindings,
            key=self._keybindings.get,
            reverse=False
        )]

        for kb_key, kb_name in sorted_keybindings:
            key, mods = Gtk.accelerator_parse(common.SETTINGS[kb_key])
            iter = self._store.append()
            columns = [
                KeybindingsWidget.Columns.SETTINGS_KEY,
                KeybindingsWidget.Columns.ACCEL_NAME,
                KeybindingsWidget.Columns.MODS,
                KeybindingsWidget.Columns.KEY
            ]
            values = [kb_key, kb_name, mods, key]
            self._store.set(iter, columns, values)
项目:nautilus-folder-icons    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def _setup_accels(self):
        """Setup accels."""
        self._accels = Gtk.AccelGroup()
        self.add_accel_group(self._accels)

        key, mod = Gtk.accelerator_parse("Escape")
        self._accels.connect(key, mod, Gtk.AccelFlags.VISIBLE,
                             self.close_window)

        key, mod = Gtk.accelerator_parse("Return")
        self._accels.connect(key, mod, Gtk.AccelFlags.VISIBLE,
                             self._do_select)

        key, mod = Gtk.accelerator_parse("<Control>F")
        self._accels.connect(key, mod, Gtk.AccelFlags.VISIBLE,
                             self._toggle_search)
项目:Linalfred    作者:PeterHo    | 项目源码 | 文件源码
def onViKeys(globalhotkey, hotkey):
    for key in hotKeys:
        keyVal, modifiers = Gtk.accelerator_parse(key[0])
        if keyVal == hotkey.keyVal and modifiers == hotkey.modifiers:
            key[1](globalhotkey)
            return True
    return False
项目:Linalfred    作者:PeterHo    | 项目源码 | 文件源码
def onSwitchWnd(hotkey):
    for key in hotKeys:
        keyVal, modifiers = Gtk.accelerator_parse(key[0])
        if keyVal == hotkey.keyVal and modifiers == hotkey.modifiers:
            switchToWnd(key[1])
            return True
    return False
项目:draobpilc    作者:awamper    | 项目源码 | 文件源码
def _get_existed(self, key, mods):
        result = [None, None]

        for settings_key in self._keybindings:
            ex_key, ex_mods = Gtk.accelerator_parse(
                common.SETTINGS[settings_key]
            )
            if ex_key == key and ex_mods == mods:
                result = [settings_key, self._keybindings[settings_key]]
                break

        return result
项目:ukui-menu    作者:ukui    | 项目源码 | 文件源码
def grab(self, key):
        if self.display == None:
            return False
        accelerator = key
        accelerator = accelerator.replace("<Super>", "<Mod4>")
        keyval, modifiers = Gtk.accelerator_parse(accelerator)
        if not accelerator or (not keyval and not modifiers):
            self.keycode = None
            self.modifiers = None
            return False

        self.keytext = key
        self.keycode = self.get_keycode(keyval)
        self.modifiers = int(modifiers)

        catch = error.CatchError(error.BadAccess)
        for ignored_mask in self.ignored_masks:
            mod = modifiers | ignored_mask
            result = self.window.grab_key(self.keycode, mod, True, X.GrabModeAsync, X.GrabModeSync, onerror=catch)
            result = self.window.grab_key(134, mod, True, X.GrabModeAsync, X.GrabModeSync, onerror=catch)
        self.display.flush()
        # sync has been blocking. Don't know why.
        #self.display.sync()
        if catch.get_error():
            return False
        return True
项目:mate-menu    作者:ubuntu-mate    | 项目源码 | 文件源码
def grab(self, key):
        accelerator = key
        accelerator = accelerator.replace("<Super>", "<Mod4>")
        keyval, modifiers = Gtk.accelerator_parse(accelerator)
        if not accelerator or (not keyval and not modifiers):
            self.keycode = None
            self.modifiers = None
            return False

        self.keytext = key
        try:
            self.keycode = self.keymap.get_entries_for_keyval(keyval).keys[0].keycode
        except AttributeError:
            # In older Gtk3 the get_entries_for_keyval() returns an unnamed tuple...
            self.keycode = self.keymap.get_entries_for_keyval(keyval)[1][0].keycode
        self.modifiers = int(modifiers)

        # Request to receive key press/release reports from other windows that may not be using modifiers
        catch = error.CatchError(error.BadWindow)
        if self.modifiers:
            self.window.change_attributes(onerror=catch, event_mask = X.KeyPressMask | X.KeyReleaseMask)
        else:
            self.window.change_attributes(onerror=catch, event_mask = X.NoEventMask)
        if catch.get_error():
            return False

        catch = error.CatchError(error.BadAccess)
        for ignored_mask in self.ignored_masks:
            mod = modifiers | ignored_mask
            result = self.window.grab_key(self.keycode, mod, True, X.GrabModeAsync, X.GrabModeAsync, onerror=catch)
        self.display.flush()
        # sync has been blocking. Don't know why.
        #self.display.sync()
        if catch.get_error():
            return False
        return True
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def create(toolbar):
    '''Set of instructions to create the search widget in a toolbar.'''

    # Search components
    toolbar.search_combo_tb = Gtk.ToolItem()
    toolbar.search_combo_align = Gtk.Alignment.new(0, 0.5, 0, 0)
    store = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
    toolbar.search_combo = Gtk.ComboBox.new_with_model(store)
    rendererText = Gtk.CellRendererText()
    rendererPix = Gtk.CellRendererPixbuf()
    toolbar.search_combo.pack_start(rendererPix, False)
    toolbar.search_combo.pack_start(rendererText, True)
    toolbar.search_combo.add_attribute(rendererPix, 'pixbuf', 0)
    toolbar.search_combo.add_attribute(rendererText, 'text', 1)

    options = {
        'String':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_string_16.png')),
        'String no case':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_string_no_case_16.png')),
        'Hexadecimal':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_hexadecimal_16.png')),
        'Regexp':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_regexp_16.png'))
    }

    for option in options.keys():
        store.append([options[option], option])
    toolbar.search_combo.set_active(0)
    toolbar.search_combo_align.add(toolbar.search_combo)
    toolbar.search_combo_tb.add(toolbar.search_combo_align)
    toolbar.main_tb.insert(toolbar.search_combo_tb, -1)

    # Separator
    toolbar.sep = Gtk.SeparatorToolItem()
    toolbar.sep.set_draw(False)
    toolbar.main_tb.insert(toolbar.sep, -1)

    toolbar.search_entry_tb = Gtk.ToolItem()
    toolbar.search_entry = Gtk.Entry()
    toolbar.search_entry.set_max_length(100)
    toolbar.search_entry.set_text('Text to search')
    toolbar.search_entry.set_icon_from_stock(1, Gtk.STOCK_FIND)
    toolbar.search_entry.set_icon_tooltip_text(1, 'Search')
    toolbar.search_entry.connect("activate", toolbar.search)
    toolbar.search_entry.connect("icon-press", toolbar.search)
    toolbar.search_entry.connect('focus-in-event', toolbar._clean, 'in')
    toolbar.search_entry.connect('focus-out-event', toolbar._clean, 'out')
    toolbar.search_entry_tb.add(toolbar.search_entry)
    # We use the AccelGroup object from the main window.
    my_accel = Gtk.accel_groups_from_object(toolbar.main.window)[0]
    key, mod = Gtk.accelerator_parse('<Control>F')
    toolbar.search_entry.set_tooltip_text('Control-F to search')
    toolbar.search_entry.add_accelerator('grab-focus', my_accel, key, mod, Gtk.AccelFlags.MASK)
    toolbar.main_tb.insert(toolbar.search_entry_tb, -1)