Exemplo n.º 1
0
 def refresh_shortcuts(self):
     model = self.shortcuts_model
     model.clear()
     for group in self.win.ui.get_action_groups():
         if group.get_name() == 'clipboard':
             continue
         iter_ = model.append(None)
         lbl = group.get_data('cf::label') or group.get_name()
         model.set(iter_, 0, lbl, 3, False)
         for action in group.list_actions():
             # Don't display menu items with submenus
             if action.get_name().endswith('menu-action') \
             or action.get_name().startswith('activate-editor'):
                 continue
             citer = model.append(iter_)
             accel_path = action.get_accel_path()
             if accel_path is None:
                 keyval = mods = None
             else:
                 shortcut = gtk.accel_map_lookup_entry(accel_path)
                 if shortcut is not None:
                     keyval, mods = shortcut
                 else:
                     keyval = mods = None
             model.set(citer,
                       0, action.props.label.replace('_', ''),
                       3, True,
                       4, action.props.tooltip,
                       5, action)
             if keyval is not None:
                 model.set(citer, 1, keyval)
             if mods is not None:
                 model.set(citer, 2, mods)
 def create_entry(self, actwrap):
     d = gtk.Dialog(parent=None,
                    flags=gtk.DIALOG_MODAL,
                    title='Enter new keypress',
                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                             gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
                    )
     action = actwrap.action
     e = gtk.Entry()
     e.show()
     d.vbox.pack_start(e, expand=False)
     key, mod = gtk.accel_map_lookup_entry(action.accel_path)
     accel = gtk.accelerator_name(key, mod)
     e.set_text(accel)
     def _response(dlg, response):
         d.hide()
         if response == gtk.RESPONSE_ACCEPT:
             newaccel = e.get_text()
             action.set_accel(newaccel)
             actwrap.reset_markup()
             key, mod = gtk.accelerator_parse(newaccel)
             gtk.accel_map_change_entry(action.accel_path, key, mod, True)
         d.destroy()
     d.connect('response', _response)
     d.run()
Exemplo n.º 3
0
    def new(cls, gtk_action, parent):
        """Create a new GAction from a GtkAction and a GtkActionGroup"""
        # This code is similar to code in the loader, investigate
        # if we can use more code reusage
        name = gtk_action.get_name()
        label = gtk_action.get_property('label')
        short_label = gtk_action.get_property('short-label')
        is_important = gtk_action.get_property('is-important')
        tooltip = gtk_action.get_property('tooltip')
        stock_id = gtk_action.get_property('stock-id') or None
        gaction = cls(parent, name, label, short_label, is_important,
                      tooltip, stock_id)

        # check if it has accelerator
        accel_entry = gtk.accel_map_lookup_entry('<Actions>/%s/%s' %
                                                 (parent.name, name))
        if accel_entry:
            key, modifier = accel_entry
            if key != 0:
                gaction.accelerator = gtk.accelerator_name(key, modifier)

        # check if it has signal handler
        callback = gtk_action.get_data('handler')
        if callback:
            gaction.callback = callback

        return gaction
Exemplo n.º 4
0
    def _install_proxy(self, action):
        if not isinstance(action, gtk.Action):
            action = self._action_group.get_action(str(action))

        if not action:
            return

        entry = gtk.accel_map_lookup_entry(action.get_accel_path())

        if not entry:
            return

        mapping = {
            gtk.keysyms.plus: gtk.keysyms.KP_Add,
            gtk.keysyms.KP_Add: gtk.keysyms.plus,
            gtk.keysyms.minus: gtk.keysyms.KP_Subtract,
            gtk.keysyms.KP_Subtract: gtk.keysyms.minus,
            gtk.keysyms._0: gtk.keysyms.KP_0,
            gtk.keysyms.KP_0: gtk.keysyms._0
        }

        if entry[0] in mapping:
            key = mapping[entry[0]]
            mod = entry[1]

            callback = self._proxy_callback_map[action.get_name()]

            self._accel_group.connect_group(key, mod, gtk.ACCEL_LOCKED, callback)
            self._proxy_mapping[action] = (key, mod)
Exemplo n.º 5
0
    def _install_proxy(self, action):
        if not isinstance(action, gtk.Action):
            action = self._action_group.get_action(str(action))

        if not action:
            return

        entry = gtk.accel_map_lookup_entry(action.get_accel_path())

        if not entry:
            return

        mapping = {
            gtk.keysyms.plus: gtk.keysyms.KP_Add,
            gtk.keysyms.KP_Add: gtk.keysyms.plus,
            gtk.keysyms.minus: gtk.keysyms.KP_Subtract,
            gtk.keysyms.KP_Subtract: gtk.keysyms.minus,
            gtk.keysyms._0: gtk.keysyms.KP_0,
            gtk.keysyms.KP_0: gtk.keysyms._0
        }

        if entry[0] in mapping:
            key = mapping[entry[0]]
            mod = entry[1]

            callback = self._proxy_callback_map[action.get_name()]

            self._accel_group.connect_group(key, mod, gtk.ACCEL_LOCKED,
                                            callback)
            self._proxy_mapping[action] = (key, mod)
Exemplo n.º 6
0
    def next (self):
       while self.to_traverse != []:
	 (w, prefix, level) = self.to_traverse.pop ()

	 if isinstance (w, gtk.MenuItem):
	   accel_path = ""
	   result = None
	   for m in w.get_children():
	     if isinstance (m, gtk.Label):
		accel_path = prefix + m.get_text()
		accel = ""
		if isinstance (m, gtk.AccelLabel):
		   key = gtk.accel_map_lookup_entry (prefix + m.get_text())
		   if key and key[0] != 0:
		      accel = gtk.accelerator_name (key[0], key[1])
		result = (w, accel_path, accel, level)

	   if w.get_submenu ():
	     self.to_traverse = self.to_traverse + \
		[(c, accel_path + "/", level + 1) \
		 for c in w.get_submenu ()]
	   if result:
	     return result

	 elif isinstance (w, gtk.Container):
	   self.to_traverse = self.to_traverse + \
	      [(c, prefix, level + 1) for c in w.get_children ()]
       raise StopIteration
Exemplo n.º 7
0
    def create_entry(self, actwrap):
        d = gtk.Dialog(parent=None,
                       flags=gtk.DIALOG_MODAL,
                       title='Enter new keypress',
                       buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                                gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        action = actwrap.action
        e = gtk.Entry()
        e.show()
        d.vbox.pack_start(e, expand=False)
        key, mod = gtk.accel_map_lookup_entry(action.accel_path)
        accel = gtk.accelerator_name(key, mod)
        e.set_text(accel)

        def _response(dlg, response):
            d.hide()
            if response == gtk.RESPONSE_ACCEPT:
                newaccel = e.get_text()
                action.set_accel(newaccel)
                actwrap.reset_markup()
                key, mod = gtk.accelerator_parse(newaccel)
                gtk.accel_map_change_entry(action.accel_path, key, mod, True)
            d.destroy()

        d.connect('response', _response)
        d.run()
Exemplo n.º 8
0
 def getAccelerator(self, widget):
     action = widget.get_action()
     if action:
         accelPath = action.get_accel_path()
         if accelPath:
             keyVal, modifier = gtk.accel_map_lookup_entry(accelPath)
             if keyVal:
                 return gtk.accelerator_get_label(keyVal, modifier)
     return ""
Exemplo n.º 9
0
 def update_keymap(self, accel_path):
     if not accel_path:
         return
     for k, v in self.keymap.items():
         if v.get_accel_path() == accel_path:
             del self.keymap[k]
     shortcut = gtk.accel_map_lookup_entry(accel_path)
     if shortcut:
         for action in self.actions:
             if action.get_accel_path() == accel_path:
                 self.keymap[shortcut] = action
                 return
         print 'Ignoring keybinding for', accel_path
Exemplo n.º 10
0
	def __init__(self, plugin, window):
		self._window = window
		self._plugin = plugin
		self._entry = None
		accel_path = '<gedit>/plugins/commander/activate'

		accel = gtk.accel_map_lookup_entry(accel_path)

		if accel == None:
			gtk.accel_map_add_entry(accel_path, gtk.keysyms.period, gtk.gdk.CONTROL_MASK)

		self._accel = gtk.AccelGroup()
		self._accel.connect_by_path(accel_path, self._do_command)
		self._window.add_accel_group(self._accel)
Exemplo n.º 11
0
    def __init__(self):
        gtk.HBox.__init__(self, False, 4)

        gconf_client.add_dir(self.GCONF_PROFILE_DIR,
                             gconf.CLIENT_PRELOAD_RECURSIVE)

        self._vte = vte.Terminal()
        self.reconfigure_vte()
        self._vte.set_size(self._vte.get_column_count(), 5)
        self._vte.set_size_request(200, 50)
        self._vte.show()
        self.pack_start(self._vte)

        self._scrollbar = gtk.VScrollbar(self._vte.get_adjustment())
        self._scrollbar.show()
        self.pack_start(self._scrollbar, False, False, 0)

        gconf_client.notify_add(self.GCONF_PROFILE_DIR,
                                self.on_gconf_notification)

        # we need to reconf colors if the style changes
        self._vte.connect("style-set",
                          lambda term, oldstyle: self.reconfigure_vte())
        self._vte.connect("key-press-event", self.on_vte_key_press)
        self._vte.connect("button-press-event", self.on_vte_button_press)
        self._vte.connect("popup-menu", self.on_vte_popup_menu)
        self._vte.connect("child-exited", lambda term: term.fork_command())

        self._accel_base = '<gedit>/plugins/terminal'
        self._accels = {
            'copy-clipboard': [
                gtk.keysyms.C, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK,
                self.copy_clipboard
            ],
            'paste-clipboard': [
                gtk.keysyms.V, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK,
                self.paste_clipboard
            ]
        }

        for name in self._accels:
            path = self._accel_base + '/' + name
            accel = gtk.accel_map_lookup_entry(path)

            if accel == None:
                gtk.accel_map_add_entry(path, self._accels[name][0],
                                        self._accels[name][1])

        self._vte.fork_command()
Exemplo n.º 12
0
 def _is_valid_accel(self, keyval, mod):
     accel_path = self.action_path + self.action_list[self.accel_index]
     old_accel = gtk.accel_map_lookup_entry(accel_path)
     if not gtk.accel_map_change_entry(accel_path, keyval, mod, False):
         msgdlg = gtk.MessageDialog(self.dialog,
                                    gtk.DIALOG_MODAL,
                                    gtk.MESSAGE_ERROR,
                                    gtk.BUTTONS_OK,
                                    _('Shortcut %s is already in use') % gtk.accelerator_name(keyval, mod))
         msgdlg.run()
         msgdlg.destroy()
         return False
     else:
         gtk.accel_map_change_entry(accel_path, old_accel[0], old_accel[1], True)
         return True
    def __init__(self, plugin, window):
        self._window = window
        self._plugin = plugin
        self._entry = None
        accel_path = '<gedit>/plugins/commander/activate'

        accel = gtk.accel_map_lookup_entry(accel_path)

        if accel == None:
            gtk.accel_map_add_entry(accel_path, gtk.keysyms.period,
                                    gtk.gdk.CONTROL_MASK)

        self._accel = gtk.AccelGroup()
        self._accel.connect_by_path(accel_path, self._do_command)
        self._window.add_accel_group(self._accel)
Exemplo n.º 14
0
    def on_vte_key_press(self, term, event):
        modifiers = event.state & gtk.accelerator_get_default_mod_mask()
        if event.keyval in (gtk.keysyms.Tab, gtk.keysyms.KP_Tab, gtk.keysyms.ISO_Left_Tab):
            if modifiers == gtk.gdk.CONTROL_MASK:
                self.get_toplevel().child_focus(gtk.DIR_TAB_FORWARD)
                return True
            elif modifiers == gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK:
                self.get_toplevel().child_focus(gtk.DIR_TAB_BACKWARD)
                return True

        for name in self._accels:
            path = self._accel_base + '/' + name
            entry = gtk.accel_map_lookup_entry(path)

            if entry and entry[0] == event.keyval and entry[1] == modifiers:
                self._accels[name][2]()
                return True

        return False
Exemplo n.º 15
0
def _setup_accel(widget, name, shortcut=None):
    """Setup accelerators for a menu item.

    This method sets an accel path for the widget and optionally connects a
    shortcut to that accel path.
    """
    # The GTK docs say that we should set the path using this form:
    # <Window-Name>/Menu/Submenu/MenuItem
    # ...but this is hard to do because we don't yet know what window/menu
    # this menu item is going to be added to.  gtk.Action and gtk.ActionGroup
    # don't follow the above suggestion, so we don't need to either.
    path = "<MiroActions>/MenuBar/%s" % name
    widget.set_accel_path(path)
    if shortcut is not None:
        accel_string = keymap.get_accel_string(shortcut)
        key, mods = gtk.accelerator_parse(accel_string)
        if gtk.accel_map_lookup_entry(path) is None:
            gtk.accel_map_add_entry(path, key, mods)
        else:
            gtk.accel_map_change_entry(path, key, mods, True)
Exemplo n.º 16
0
def _setup_accel(widget, name, shortcut=None):
    """Setup accelerators for a menu item.

    This method sets an accel path for the widget and optionally connects a
    shortcut to that accel path.
    """
    # The GTK docs say that we should set the path using this form:
    # <Window-Name>/Menu/Submenu/MenuItem
    # ...but this is hard to do because we don't yet know what window/menu
    # this menu item is going to be added to.  gtk.Action and gtk.ActionGroup
    # don't follow the above suggestion, so we don't need to either.
    path = "<MiroActions>/MenuBar/%s" % name
    widget.set_accel_path(path)
    if shortcut is not None:
        accel_string = keymap.get_accel_string(shortcut)
        key, mods = gtk.accelerator_parse(accel_string)
        if gtk.accel_map_lookup_entry(path) is None:
            gtk.accel_map_add_entry(path, key, mods)
        else:
            gtk.accel_map_change_entry(path, key, mods, True)
Exemplo n.º 17
0
    def on_vte_key_press(self, term, event):
        modifiers = event.state & gtk.accelerator_get_default_mod_mask()
        if event.keyval in (gtk.keysyms.Tab, gtk.keysyms.KP_Tab,
                            gtk.keysyms.ISO_Left_Tab):
            if modifiers == gtk.gdk.CONTROL_MASK:
                self.get_toplevel().child_focus(gtk.DIR_TAB_FORWARD)
                return True
            elif modifiers == gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK:
                self.get_toplevel().child_focus(gtk.DIR_TAB_BACKWARD)
                return True

        for name in self._accels:
            path = self._accel_base + '/' + name
            entry = gtk.accel_map_lookup_entry(path)

            if entry and entry[0] == event.keyval and entry[1] == modifiers:
                self._accels[name][2]()
                return True

        return False
Exemplo n.º 18
0
    def __init__(self):
        gtk.HBox.__init__(self, False, 4)

        gconf_client.add_dir(self.GCONF_PROFILE_DIR,
                             gconf.CLIENT_PRELOAD_RECURSIVE)

        self._vte = vte.Terminal()
        self.reconfigure_vte()
        self._vte.set_size(self._vte.get_column_count(), 5)
        self._vte.set_size_request(200, 50)
        self._vte.show()
        self.pack_start(self._vte)

        self._scrollbar = gtk.VScrollbar(self._vte.get_adjustment())
        self._scrollbar.show()
        self.pack_start(self._scrollbar, False, False, 0)

        gconf_client.notify_add(self.GCONF_PROFILE_DIR,
                                self.on_gconf_notification)

        # we need to reconf colors if the style changes
        self._vte.connect("style-set", lambda term, oldstyle: self.reconfigure_vte())
        self._vte.connect("key-press-event", self.on_vte_key_press)
        self._vte.connect("button-press-event", self.on_vte_button_press)
        self._vte.connect("popup-menu", self.on_vte_popup_menu)
        self._vte.connect("child-exited", lambda term: term.fork_command())

        self._accel_base = '<gedit>/plugins/terminal'
        self._accels = {
            'copy-clipboard': [gtk.keysyms.C, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK, self.copy_clipboard],
            'paste-clipboard': [gtk.keysyms.V, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK, self.paste_clipboard]
        }

        for name in self._accels:
            path = self._accel_base + '/' + name
            accel = gtk.accel_map_lookup_entry(path)

            if accel == None:
                 gtk.accel_map_add_entry(path, self._accels[name][0], self._accels[name][1])

        self._vte.fork_command()