improve container signal registration function to never double-register. add a fake resize-term signal to Paned for nested terminal resizes. Implement terminal resizing.

This commit is contained in:
Chris Jones 2009-11-08 23:06:26 +00:00
parent 5352731984
commit 5dd6ae0154
3 changed files with 57 additions and 11 deletions

View File

@ -32,8 +32,13 @@ 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))
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'],

View File

@ -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"""

View File

@ -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')