From e65e396d32a5b5d12d5a5d34916badeeee90d13a Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Mon, 11 Aug 2008 19:02:14 +0100 Subject: [PATCH] Hook up new keybinding code. Making them configurable shouldn't be far away... --- terminatorlib/keybindings.py | 15 +-- terminatorlib/terminator.py | 20 ++-- terminatorlib/terminatorterm.py | 163 +++++++++++++++----------------- 3 files changed, 95 insertions(+), 103 deletions(-) diff --git a/terminatorlib/keybindings.py b/terminatorlib/keybindings.py index 7d7491f0..707d1641 100644 --- a/terminatorlib/keybindings.py +++ b/terminatorlib/keybindings.py @@ -30,9 +30,10 @@ class TerminatorKeybindings: 'resize_down': 'Down', 'resize_left': 'Left', 'resize_right': 'Right', - 'move_tab_right': 'Page_Up', - 'move_tab_left': 'Page_Down', + 'move_tab_right': 'Page_Down', + 'move_tab_left': 'Page_Up', 'toggle_zoom': 'X', + 'scaled_zoom': 'Z', 'next_tab': 'Page_Down', 'prev_tab': 'Page_Up', 'go_prev': 'Tab', @@ -49,9 +50,9 @@ class TerminatorKeybindings: empty = {} def __init__(self): - self._parse() + self.reload() - def _parse(self): + def reload(self): self._lookup = {} self._masks = 0 for action, binding in self.keys.items(): @@ -65,7 +66,9 @@ class TerminatorKeybindings: raise e else: self._lookup.setdefault(mask, {}) - self._lookup[mask][key] = action + self._lookup[mask][keyval] = action + if key == 'Tab': + self._lookup[mask][gtk.gdk.keyval_from_name('ISO_Left_Tab')] = action self._masks |= mask def _parsebinding(self, binding): @@ -88,5 +91,5 @@ class TerminatorKeybindings: def lookup(self, event): mask = event.state & self._masks keyval = gtk.gdk.keyval_name(event.keyval) - return self._lookup.get(mask, self.empty).get(keyval, None) + return self._lookup.get(mask, self.empty).get(event.keyval, None) diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 3670f4e3..19ff9562 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -26,6 +26,7 @@ from terminatorlib.version import * # import our configuration loader from terminatorlib import config from terminatorlib.config import dbg, err, debug +from terminatorlib.keybindings import TerminatorKeybindings #import TerminatorTerm from terminatorlib.terminatorterm import TerminatorTerm @@ -121,8 +122,10 @@ class Terminator: self.icon_theme = gtk.IconTheme () + self.keybindings = TerminatorKeybindings() if self.conf.f11_modifier: - self._f11_modifier = True + self.keybindings.keys['full_screen'] = 'F11' + self.keybindings.reload() if self.conf.handle_size in xrange (0,6): gtk.rc_parse_string(""" @@ -254,15 +257,14 @@ class Terminator: * F11: toggle fullscreen state of the window. * CTRL - SHIFT - Q: close all terminals """ - keyname = gtk.gdk.keyval_name (event.keyval) - mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK + mapping = self.keybindings.lookup(event) - if (keyname == 'F11' and (self._f11_modifier == False or event.state & mask)): - self.fullscreen_toggle () - return (True) - - if (event.state & mask) == mask: - if keyname == 'Q': + if mapping: + dbg("on_key_press: lookup found %s" % repr(mapping)) + if mapping == 'full_screen': + self.fullscreen_toggle () + return (True) + elif mapping == 'close_window': if not self.on_delete_event (window, gtk.gdk.Event (gtk.gdk.DELETE)): self.on_destroy_event (window, gtk.gdk.Event (gtk.gdk.DESTROY)) diff --git a/terminatorlib/terminatorterm.py b/terminatorlib/terminatorterm.py index e2a41b49..b24e8598 100755 --- a/terminatorlib/terminatorterm.py +++ b/terminatorlib/terminatorterm.py @@ -668,98 +668,85 @@ text/plain #keybindings for the individual splited terminals (affects only the #the selected terminal) + UnhandledKeybindings = ('close_window', 'full_screen') def on_vte_key_press (self, term, event): - keyname = gtk.gdk.keyval_name (event.keyval) + mapping = self.terminator.keybindings.lookup(event) - mask = gtk.gdk.CONTROL_MASK - if (event.state & mask) == mask: - if keyname == 'plus': - self.zoom (True) - return (True) - elif keyname == 'minus': - self.zoom (False) - return (True) - elif keyname == 'equal': - self.zoom_orig () - return (True) + if mapping and mapping not in self.UnhandledKeybindings: + dbg("on_vte_key_press: lookup found %s" % repr(mapping)) + getattr(self, "key_" + mapping)() + return True - mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK | gtk.gdk.MOD1_MASK - if (event.state & mask) == mask: - #Top level tab - if keyname == 'T': - self.terminator.newtab (self, True) - return (True) - # bindings that should be moved to Terminator as they all just call - # a function of Terminator. It would be cleaner is TerminatorTerm - # has absolutely no reference to Terminator. - # N (next) - P (previous) - O (horizontal) - E (vertical) - W (close) + return False - mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK - if (event.state & mask) == mask: - if keyname == 'N': - self.terminator.go_next (self) - return (True) - elif keyname == "P": - self.terminator.go_prev (self) - return (True) - elif keyname == 'O': - self.terminator.splitaxis (self, False) - return (True) - elif keyname == 'E': - self.terminator.splitaxis (self, True) - return (True) - elif keyname == 'W': - self.terminator.closeterm (self) - return (True) - elif keyname == 'C': - self._vte.copy_clipboard () - return (True) - elif keyname == 'V': - self.paste_clipboard () - return (True) - elif keyname == 'S': - self.do_scrollbar_toggle () - return (True) - elif keyname == 'T': - self.terminator.newtab(self) - return (True) - elif keyname in ('Up', 'Down', 'Left', 'Right'): - self.terminator.resizeterm (self, keyname) - return (True) - elif keyname == 'Page_Down': - self.terminator.move_tab(self, 'right') - return (True) - elif keyname == 'Page_Up': - self.terminator.move_tab(self, 'left') - return (True) - elif keyname == 'Z': - self.terminator.toggle_zoom (self, True) - return (True) - elif keyname == 'X': - self.terminator.toggle_zoom (self) - return (True) - - mask = gtk.gdk.CONTROL_MASK - if (event.state & mask) == mask: - if keyname == 'Page_Down': - self.terminator.next_tab(self) - return (True) - elif keyname == 'Page_Up': - self.terminator.previous_tab(self) - return (True) - - if keyname and (keyname == 'Tab' or keyname.endswith('_Tab')): - mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK - if (event.state & mask) == mask: - self.terminator.go_prev (self) - return (True) - mask = gtk.gdk.CONTROL_MASK - if (event.state & mask) == mask: - self.terminator.go_next (self) - return (True) - # Warning, mask value is either gtk.gdk.CONTROL_MASK or gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK - # if you intend to use it, reinit it - return (False) + # Key events + def key_zoom_in(self): self.zoom (True) + + def key_zoom_out(self): self.zoom (False) + + def key_copy(self): self._vte.copy_clipboard () + + def key_paste(self): self.paste_clipboard () + + def key_toggle_scrollbar(self): self.do_scrollbar_toggle () + + def key_zoom_normal(self): self.zoom_orig () + + # bindings that should be moved to Terminator as they all just call + # a function of Terminator. It would be cleaner if TerminatorTerm + # has absolutely no reference to Terminator. + # N (next) - P (previous) - O (horizontal) - E (vertical) - W (close) + def key_new_root_tab(self): + self.terminator.newtab (self, True) + + def key_go_next(self): + self.terminator.go_next (self) + + def key_go_prev(self): + self.terminator.go_prev (self) + + def key_split_horiz(self): + self.terminator.splitaxis (self, False) + + def key_split_vert(self): + self.terminator.splitaxis (self, True) + + def key_close_term(self): + self.terminator.closeterm (self) + + def key_new_tab(self): + self.terminator.newtab(self) + + def key_resize_up(self): + self.terminator.resizeterm (self, 'Up') + + def key_resize_down(self): + self.terminator.resizeterm (self, 'Down') + + def key_resize_left(self): + self.terminator.resizeterm (self, 'Left') + + def key_resize_right(self): + self.terminator.resizeterm (self, 'Right') + + def key_move_tab_right(self): + self.terminator.move_tab (self, 'right') + + def key_move_tab_right(self): + self.terminator.move_tab (self, 'left') + + def key_toggle_zoom(self): + self.terminator.toggle_zoom (self) + + def key_scaled_zoom(self): + self.terminator.toggle_zoom (self, True) + + def key_go_prev(self): + self.terminator.go_prev (self) + + def key_go_next(self): + self.terminator.go_next (self) + # End key events def zoom_orig (self): self._vte.set_font (pango.FontDescription (self.conf.font))