From 180ccbbf032781fa9a7fc49a1eb2f548a0e0372c Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sun, 10 Jan 2010 00:20:24 +0000 Subject: [PATCH] Hook up the keybindings tab in the preferences editor. Loads and saves --- terminatorlib/config.py | 81 ++++++++++++++-------------- terminatorlib/preferences.glade | 96 ++++++++++++++++++++------------- terminatorlib/prefseditor.py | 56 ++++++++++--------- 3 files changed, 130 insertions(+), 103 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index aff5090b..b051b763 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -74,54 +74,53 @@ DEFAULTS = { 'disabled_plugins' : ['TestPlugin', 'CustomCommandsMenu'], }, 'keybindings': { - 'zoom_in' : 'plus', - 'zoom_out' : 'minus', - 'zoom_normal' : '0', - 'new_root_tab' : 'T', - 'new_tab' : 'T', - 'go_next' : ('N','Tab'), - 'go_prev' : ('P','Tab'), + 'zoom_in' : 'plus', + 'zoom_out' : 'minus', + 'zoom_normal' : '0', + 'new_tab' : 't', + 'go_next' : 'n', # FIXME: Define ctrl-tab + 'go_prev' : 'p', #FIXME: ctrl-shift-tab 'go_up' : 'Up', 'go_down' : 'Down', 'go_left' : 'Left', 'go_right' : 'Right', - 'split_horiz' : 'O', - 'split_vert' : 'E', - 'close_term' : 'W', - 'copy' : 'C', - 'paste' : 'V', - 'toggle_scrollbar' : 'S', - 'search' : 'F', - 'close_window' : 'Q', - 'resize_up' : 'Up', - 'resize_down' : 'Down', - 'resize_left' : 'Left', - 'resize_right' : 'Right', - 'move_tab_right' : 'Page_Down', - 'move_tab_left' : 'Page_Up', - 'toggle_zoom' : 'X', - 'scaled_zoom' : 'Z', - 'next_tab' : 'Page_Down', - 'prev_tab' : 'Page_Up', - 'switch_to_tab_1' : None, - 'switch_to_tab_2' : None, - 'switch_to_tab_3' : None, - 'switch_to_tab_4' : None, - 'switch_to_tab_5' : None, - 'switch_to_tab_6' : None, - 'switch_to_tab_7' : None, - 'switch_to_tab_8' : None, - 'switch_to_tab_9' : None, - 'switch_to_tab_10' : None, + 'split_horiz' : 'o', + 'split_vert' : 'e', + 'close_term' : 'w', + 'copy' : 'c', + 'paste' : 'v', + 'toggle_scrollbar' : 's', + 'search' : 'f', + 'close_window' : 'q', + 'resize_up' : 'Up', + 'resize_down' : 'Down', + 'resize_left' : 'Left', + 'resize_right' : 'Right', + 'move_tab_right' : 'Page_Down', + 'move_tab_left' : 'Page_Up', + 'toggle_zoom' : 'x', + 'scaled_zoom' : 'z', + 'next_tab' : 'Page_Down', + 'prev_tab' : 'Page_Up', + 'switch_to_tab_1' : '', + 'switch_to_tab_2' : '', + 'switch_to_tab_3' : '', + 'switch_to_tab_4' : '', + 'switch_to_tab_5' : '', + 'switch_to_tab_6' : '', + 'switch_to_tab_7' : '', + 'switch_to_tab_8' : '', + 'switch_to_tab_9' : '', + 'switch_to_tab_10' : '', 'full_screen' : 'F11', - 'reset' : 'R', - 'reset_clear' : 'G', - 'hide_window' : 'a', + 'reset' : 'r', + 'reset_clear' : 'g', + 'hide_window' : 'a', 'group_all' : 'g', - 'ungroup_all' : 'g', + 'ungroup_all' : 'g', 'group_tab' : 't', - 'ungroup_tab' : 'T', - 'new_window' : 'I', + 'ungroup_tab' : 't', + 'new_window' : 'i', }, 'profiles': { 'default': { diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index b2acfd48..8ae6d543 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -8,16 +8,6 @@ - - - - - - - - - - @@ -189,6 +179,18 @@ + + + + + + + + + + + + 5 normal @@ -2046,40 +2048,56 @@ - + True True - KeybindingsListStore + adjustment4 + never + automatic - - Name + + True + True + KeybindingsListStore + False + 0 - - - 0 - + + Name + + + + 0 + + + - - - - - Action - - - 1 - + + Action + + + + 1 + + + - - - - - Keybinding - - - 2 - + + Keybinding + + + True + + + + + 2 + 3 + + + @@ -2202,4 +2220,10 @@ 10 10 + + 100 + 1 + 10 + 10 + diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index 3790d6b2..7e0c1b8e 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -6,12 +6,13 @@ import gobject from util import dbg, err import config -from keybindings import Keybindings +from keybindings import Keybindings, KeymapError from version import APP_NAME, APP_VERSION from translation import _ class PrefsEditor: config = None + keybindings = None window = None builder = None previous_selection = None @@ -27,6 +28,7 @@ class PrefsEditor: self.config = config.Config() self.term = term self.builder = gtk.Builder() + self.keybindings = Keybindings() try: # Figure out where our library is on-disk so we can open our (head, tail) = os.path.split(config.__file__) @@ -123,7 +125,20 @@ class PrefsEditor: # FIXME: Implement this ## Keybindings tab - # FIXME: Implement this + widget = guiget('keybindingtreeview') + liststore = widget.get_model() + liststore.set_sort_column_id(0, gtk.SORT_ASCENDING) + keybindings = self.config['keybindings'] + for keybinding in keybindings: + keyval = 0 + mask = 0 + value = keybindings[keybinding] + if value is not None and value != '': + try: + (keyval, mask) = self.keybindings._parsebinding(value) + except KeymapError: + pass + liststore.append([keybinding, 'UNDOCUMENTED', keyval, mask]) ## Plugins tab # FIXME: Implement this @@ -184,10 +199,15 @@ class PrefsEditor: # FIXME: Implement this ## Keybindings tab - # FIXME: Implement this + keybindings = self.config['keybindings'] + liststore = guiget('KeybindingsListStore') + for keybinding in liststore: + accel = gtk.accelerator_name(keybinding[2], keybinding[3]) + keybindings[keybinding[0]] = accel ## Plugins tab # FIXME: Implement this + def set_profile_values(self, profile): """Update the profile values for a given profile""" self.config.set_profile(profile) @@ -690,22 +710,14 @@ class PrefsEditor: scheme.set_sensitive(True) self.on_color_scheme_combobox_changed(scheme) - def source_get_type (self, key): - if config.DEFAULTS['global_config'].has_key (key): - print "found %s in global_config" % key - return config.DEFAULTS['global_config'][key].__class__.__name__ - elif config.DEFAULTS['profiles']['default'].has_key (key): - print "found %s in profiles" % key - return config.DEFAULTS['profiles']['default'][key].__class__.__name__ - elif config.DEFAULTS['keybindings'].has_key (key): - print "found %s in keybindings" % key - return config.DEFAULTS['keybindings'][key].__class__.__name__ - else: - print "could not find %s" % key - raise KeyError + def on_cellrenderer_accel_edited(self, liststore, path, key, mods, code): + """Handle an edited keybinding""" + celliter = liststore.get_iter_from_string(path) + liststore.set(celliter, 2, key, 3, mods) - def source_get_value (self, key): - return self.config[key] + def on_cellrenderer_accel_cleared(self, liststore, path): + celliter = liststore.get_iter_from_string(path) + liststore.set(celliter, 2, 0, 3, 0) def source_get_keyname (self, key): if self.data.has_key (key) and self.data[key][0] != '': @@ -714,14 +726,6 @@ class PrefsEditor: label_text = key.replace ('_', ' ').capitalize () return label_text - def apply (self, data): - pass - - def cancel (self, data): - self.window.destroy() - self.term.options = None - del(self) - def prepare_keybindings (self): self.liststore = gtk.ListStore (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_UINT, gobject.TYPE_UINT, gobject.TYPE_BOOLEAN) self.liststore.set_sort_column_id (0, gtk.SORT_ASCENDING)