Exemple #1
0
    def onEntryChanged(self, cell, path, accel_string, accel_label, entry_store):
        iter = entry_store.get_iter(path)
        keybindings, kb_iter = self.kb_tree.get_selection().get_selected()
        if kb_iter:
            current_keybinding = keybindings[kb_iter][1]

        # Check for duplicates
        for category in self.main_store:
            for keybinding in category.keybindings:
                for entry in keybinding.entries:
                    found = False
                    if Gtk.accelerator_parse_with_keycode(accel_string) == Gtk.accelerator_parse_with_keycode(entry):
                        found = True

                    if found and keybinding.label != current_keybinding.label:
                        dialog = Gtk.MessageDialog(None,
                                                   Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                                   Gtk.MessageType.QUESTION,
                                                   Gtk.ButtonsType.YES_NO,
                                                   None)
                        dialog.set_default_size(400, 200)
                        msg = _("This key combination, <b>%(combination)s</b> is currently in use by <b>%(old)s</b>.  ")
                        msg += _("If you continue, the combination will be reassigned to <b>%(new)s</b>.\n\n")
                        msg += _("Do you want to continue with this operation?")
                        dialog.set_markup(msg % {'combination':html.escape(accel_label), 'old':html.escape(keybinding.label), 'new':html.escape(current_keybinding.label)})
                        dialog.show_all()
                        response = dialog.run()
                        dialog.destroy()
                        if response == Gtk.ResponseType.YES:
                            keybinding.setBinding(keybinding.entries.index(entry), None)
                        else:
                            return
        current_keybinding.setBinding(int(path), accel_string)
        self.onKeyBindingChanged(self.kb_tree)
        self.entry_tree.get_selection().select_path(path)
Exemple #2
0
    def onEntryChanged(self, cell, path, accel_string, accel_label, entry_store):
        iter = entry_store.get_iter(path)
        keybindings, kb_iter = self.kb_tree.get_selection().get_selected()
        if kb_iter:
            current_keybinding = keybindings[kb_iter][1]

        # Check for duplicates
        for category in self.main_store:
            for keybinding in category.keybindings:
                for entry in keybinding.entries:
                    found = False
                    if Gtk.accelerator_parse_with_keycode(accel_string) == Gtk.accelerator_parse_with_keycode(entry):
                        found = True

                    if found and keybinding.label != current_keybinding.label:
                        dialog = Gtk.MessageDialog(None,
                                                   Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                                   Gtk.MessageType.QUESTION,
                                                   Gtk.ButtonsType.YES_NO,
                                                   None)
                        dialog.set_default_size(400, 200)
                        msg = _("This key combination, <b>%(combination)s</b> is currently in use by <b>%(old)s</b>.  ")
                        msg += _("If you continue, the combination will be reassigned to <b>%(new)s</b>.\n\n")
                        msg += _("Do you want to continue with this operation?")
                        dialog.set_markup(msg % {'combination':accel_label, 'old':cgi.escape(keybinding.label), 'new':cgi.escape(current_keybinding.label)})
                        dialog.show_all()
                        response = dialog.run()
                        dialog.destroy()
                        if response == Gtk.ResponseType.YES:
                            keybinding.setBinding(keybinding.entries.index(entry), None)
                        elif response == Gtk.ResponseType.NO:
                            return
        current_keybinding.setBinding(int(path), accel_string)
        self.onKeyBindingChanged(self.kb_tree)
        self.entry_tree.get_selection().select_path(path)
 def update_label(self):
     if not self.accel_string:
         text = _("unassigned")
     else:
         key, codes, mods = Gtk.accelerator_parse_with_keycode(self.accel_string)
         text = Gtk.accelerator_get_label_with_keycode(None, key, codes[0], mods)
     self.set_property("text", text)
Exemple #4
0
 def update_label(self):
     if not self.accel_string:
         text = _("unassigned")
     else:
         key, codes, mods = Gtk.accelerator_parse_with_keycode(self.accel_string)
         text = Gtk.accelerator_get_label_with_keycode(None, key, codes[0], mods)
     self.set_property("text", text)
Exemple #5
0
 def update_label(self):
     text = _("unassigned")
     if self.accel_string:
         key, codes, mods = Gtk.accelerator_parse_with_keycode(self.accel_string)
         if codes is not None and len(codes) > 0:
             text = Gtk.accelerator_get_label_with_keycode(None, key, codes[0], mods)
     self.set_property("text", text)
Exemple #6
0
def get_keybinding_display_name(accel_string):
    """Get keybinding display name.

    Converts an accelerator keyval and modifier mask into a (possibly translated) string that can
    be displayed to a user.

    Parameters
    ----------
    accel_string : str
        Accel. string.

    Returns
    -------
    str
        Accel. string display name.
    """
    text = accel_string

    if accel_string:
        key, codes, mods = Gtk.accelerator_parse_with_keycode(accel_string)
        if codes is not None and len(codes) > 0:
            text = Gtk.accelerator_get_label_with_keycode(
                None, key, codes[0], mods)

    return text
Exemple #7
0
 def update_label(self):
     text = _("unassigned")
     if self.accel_string:
         key, codes, mods = Gtk.accelerator_parse_with_keycode(
             self.accel_string)
         if codes is not None and len(codes) > 0:
             text = Gtk.accelerator_get_label_with_keycode(
                 None, key, codes[0], mods)
     self.set_property("text", text)
    def get_keybinding_display_name(self, accel_string):
        text = ""

        if accel_string:
            key, codes, mods = Gtk.accelerator_parse_with_keycode(accel_string)
            if codes is not None and len(codes) > 0:
                text = Gtk.accelerator_get_label_with_keycode(None, key, codes[0], mods)

        return text
Exemple #9
0
 def load_accelerators(self):
     """Reads all gconf paths under /apps/guake/keybindings/local
     and adds to the _lookup.
     """
     for binding, action in self.keys:
         key, keycodes, mask = Gtk.accelerator_parse_with_keycode(
             self.guake.settings.keybindingsLocal.get_string(binding))
         if keycodes and keycodes[0]:
             self._lookup[mask][keycodes[0]] = action
             self._masks |= mask
    def __init__(self, action, bindings):
        super(ShortcutAction, self).__init__()

        self.action = action
        self.bindings = bindings

        self.parsed = []

        for binding in self.bindings:
            key, codes, mods = Gtk.accelerator_parse_with_keycode(binding)

            self.parsed.append((key, codes, mods))
    def __init__(self, action, bindings):
        super(ShortcutAction, self).__init__()

        self.action = action
        self.bindings = bindings

        self.parsed = []

        for binding in self.bindings:
            key, codes, mods = Gtk.accelerator_parse_with_keycode(binding)

            self.parsed.append((key, codes, mods))
Exemple #12
0
def parse_accelerator(accelerator_string):
	a = Gtk.accelerator_parse_with_keycode(accelerator_string)

	if not a.accelerator_codes:
		raise Exception('Can not parse the accelerator string {}'.format(accelerator_string))
	if len(a.accelerator_codes) > 1:
		# https://mail.gnome.org/archives/gtk-devel-list/2000-December/msg00034.html
		raise Exception('Support to keycodes with multiple keyvalues not implemented')

	gdk_keyval = a.accelerator_key
	if Gdk.keyval_to_upper(gdk_keyval) != Gdk.keyval_to_lower(gdk_keyval):
		gdk_keyval = Gdk.keyval_from_name(accelerator_string[-1])
	code = a.accelerator_codes[0]
	mapped_the_same, non_virtual_counterpart = Gdk.Keymap.get_for_display(Gdk.Display.get_default()).map_virtual_modifiers(a.accelerator_mods)
	mask = normalize_state(non_virtual_counterpart)
	return gdk_keyval, code, mask
Exemple #13
0
 def on_key_release(self, widget, event):
     self.ungrab()
     if ((int(event.state) & 0xff & ~IGNORED_MOD_MASK) == 0) and event.keyval == Gdk.KEY_Escape:
         self.set_label(self.cur_val)
         self.teaching = False
         return True
     if ((int(event.state) & 0xff & ~IGNORED_MOD_MASK) == 0) and event.keyval == Gdk.KEY_BackSpace:
         self.teaching = False
         self.set_label()
         self.emit("accel-cleared", self.path)
         return True
     accel_string = Gtk.accelerator_name(event.keyval, event.state)
     accel_string = self.sanitize(accel_string)
     self.cur_val = accel_string
     self.set_label(accel_string)
     self.teaching = False
     key, codes, mods = Gtk.accelerator_parse_with_keycode(accel_string)
     self.emit("accel-edited", self.path, key, mods, codes[0])
     return True
Exemple #14
0
 def on_key_release(self, widget, event):
     widget.disconnect(self.event_id)
     self.ungrab()
     self.event_id = None
     if event.state == 0 and event.keyval == Gdk.KEY_Escape:
         self.set_label(self.cur_val)
         self.teaching = False
         return True
     if event.keyval == Gdk.KEY_BackSpace:
         self.teaching = False
         self.set_label()
         self.emit("accel-cleared", self.path)
         return True
     accel_string = Gtk.accelerator_name(event.keyval, event.state)
     accel_string = self.sanitize(accel_string)
     self.cur_val = accel_string
     self.set_label(accel_string)
     self.teaching = False
     key, codes, mods = Gtk.accelerator_parse_with_keycode(accel_string)
     self.emit("accel-edited", self.path, key, mods, codes[0])
     return True
Exemple #15
0
 def on_key_release(self, widget, event):
     widget.disconnect(self.event_id)
     self.ungrab()
     self.event_id = None
     if event.keyval == Gdk.KEY_Escape:
         self.set_label(self.cur_val)
         self.teaching = False
         return True
     if event.keyval == Gdk.KEY_BackSpace:
         self.teaching = False
         self.set_label()
         self.emit("accel-cleared", self.path)
         return True
     accel_string = Gtk.accelerator_name(event.keyval, event.state)
     accel_string = self.sanitize(accel_string)
     self.cur_val = accel_string
     self.set_label(accel_string)
     self.teaching = False
     key, codes, mods = Gtk.accelerator_parse_with_keycode(accel_string)
     self.emit("accel-edited", self.path, key, mods, codes[0])
     return True