From 5dd6ae0154f087a9fe62bca3551716c65faf3528 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sun, 8 Nov 2009 23:06:26 +0000 Subject: [PATCH] improve container signal registration function to never double-register. add a fake resize-term signal to Paned for nested terminal resizes. Implement terminal resizing. --- terminatorlib/container.py | 17 +++++++++++------ terminatorlib/paned.py | 39 +++++++++++++++++++++++++++++++++++++- terminatorlib/terminal.py | 12 ++++++++---- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/terminatorlib/container.py b/terminatorlib/container.py index bba4f7dd..8f1f598c 100755 --- a/terminatorlib/container.py +++ b/terminatorlib/container.py @@ -32,13 +32,18 @@ class Container(object): def register_signals(self, widget): """Register gobject signals in a way that avoids multiple inheritance""" + existing = gobject.signal_list_names(widget) for signal in self.signals: - dbg("Container:: registering signal for %s on %s" % (signal['name'], widget)) - gobject.signal_new(signal['name'], - widget, - signal['flags'], - signal['return_type'], - signal['param_types']) + if signal['name'] in existing: + dbg('Container:: skipping signal %s for %s, already exists' % ( + signal['name'], widget)) + else: + dbg('Container:: registering signal for %s on %s' % (signal['name'], widget)) + gobject.signal_new(signal['name'], + widget, + signal['flags'], + signal['return_type'], + signal['param_types']) def get_offspring(self): """Return a list of child widgets, if any""" diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index f4adb045..fcc1af31 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -20,6 +20,10 @@ class Paned(Container): """Class initialiser""" self.terminator = Terminator() self.cnxids = {} + self.signals.append({'name': 'resize-term', + 'flags': gobject.SIGNAL_RUN_LAST, + 'return_type': gobject.TYPE_NONE, + 'param_types': (gobject.TYPE_STRING,)}) Container.__init__(self) gobject.type_register(HPaned) @@ -78,6 +82,11 @@ class Paned(Container): self.split_horiz)) self.cnxids[widget].append(widget.connect('split-vert', self.split_vert)) + self.cnxids[widget].append(widget.connect('resize-term', + self.resizeterm)) + elif isinstance(widget, gtk.Paned): + self.cnxids[widget].append(widget.connect('resize-term', + self.resizeterm)) def remove(self, widget): """Remove a widget from the container""" @@ -104,7 +113,35 @@ class Paned(Container): def resizeterm(self, widget, keyname): """Handle a keyboard event requesting a terminal resize""" - raise NotImplementedError('resizeterm') + if keyname in ['up', 'down'] and isinstance(self, gtk.VPaned): + # This is a key we can handle + position = self.get_position() + + if isinstance(widget, Terminal): + fontheight = widget.vte.get_char_height() + else: + fontheight = 10 + + if keyname == 'up': + self.set_position(position - fontheight) + else: + self.set_position(position + fontheight) + elif keyname in ['left', 'right'] and isinstance(self, gtk.HPaned): + # This is a key we can handle + position = self.get_position() + + if isinstance(widget, Terminal): + fontwidth = widget.vte.get_char_width() + else: + fontwidth = 10 + + if keyname == 'left': + self.set_position(position - fontwidth) + else: + self.set_position(position + fontwidth) + else: + # This is not a key we can handle + self.emit('resize-term', keyname) class HPaned(Paned, gtk.HPaned): """Merge gtk.HPaned into our base Paned Container""" diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index dcb77d03..7b594123 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -49,6 +49,8 @@ class Terminal(gtk.VBox): 'focus-in': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'zoom': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'maximise': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'resize-term': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,)), } TARGET_TYPE_VTE = 8 @@ -743,6 +745,8 @@ class Terminal(gtk.VBox): shell = None command = None + self.vte.grab_focus() + if self.config['use_custom_command']: command = self.config['custom_command'] @@ -906,16 +910,16 @@ class Terminal(gtk.VBox): self.terminator.newtab(self) def key_resize_up(self): - self.terminator.resizeterm (self, 'Up') + self.emit('resize-term', 'up') def key_resize_down(self): - self.terminator.resizeterm (self, 'Down') + self.emit('resize-term', 'down') def key_resize_left(self): - self.terminator.resizeterm (self, 'Left') + self.emit('resize-term', 'left') def key_resize_right(self): - self.terminator.resizeterm (self, 'Right') + self.emit('resize-term', 'right') def key_move_tab_right(self): self.terminator.move_tab (self, 'right')