From 53527319842126943a6e4d8245f0e1cdab11b5f1 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sun, 8 Nov 2009 01:06:31 +0000 Subject: [PATCH] make paneds be splittable, set their initial position properly and don't call reconfigure() all the time --- terminatorlib/paned.py | 53 ++++++++++++++++++++++++++++++++------- terminatorlib/terminal.py | 10 +++++++- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index f05da200..f4adb045 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -8,6 +8,7 @@ import gobject import gtk from newterminator import Terminator +from terminal import Terminal from container import Container # pylint: disable-msg=R0921 @@ -24,9 +25,35 @@ class Paned(Container): gobject.type_register(HPaned) self.register_signals(HPaned) + def set_initial_position(self, widget, event): + """Set the initial position of the widget""" + if isinstance(self, gtk.VPaned): + position = self.allocation.height / 2 + else: + position = self.allocation.width / 2 + + print "Setting position to: %d" % position + self.set_position(position) + self.disconnect(self.cnxids['init']) + del(self.cnxids['init']) + def split_axis(self, widget, vertical=True): """Default axis splitter. This should be implemented by subclasses""" - raise NotImplementedError('split_axis') + self.remove(widget) + if vertical: + container = VPaned() + else: + container = HPaned() + + sibling = Terminal() + self.terminator.register_terminal(sibling) + sibling.spawn_child() + + container.add(widget) + container.add(sibling) + + self.add(container) + self.show_all() def add(self, widget): """Add a widget to the container""" @@ -34,19 +61,23 @@ class Paned(Container): self.pack1(widget, True, True) self.children.append(widget) elif len(self.children) == 1: - self.pack2(widget, True, True) + if self.get_child1(): + self.pack2(widget, True, True) + else: + self.pack1(widget, True, True) self.children.append(widget) else: raise ValueError('already have two children') self.cnxids[widget] = [] - self.cnxids[widget].append(widget.connect('close-term', - self.wrapcloseterm)) - # FIXME: somehow propagate the title-change signal to the Window - self.cnxids[widget].append(widget.connect('split-horiz', - self.split_horiz)) - self.cnxids[widget].append(widget.connect('split-vert', - self.split_vert)) + if isinstance(widget, Terminal): + self.cnxids[widget].append(widget.connect('close-term', + self.wrapcloseterm)) + # FIXME: somehow propagate the title-change signal to the Window + self.cnxids[widget].append(widget.connect('split-horiz', + self.split_horiz)) + self.cnxids[widget].append(widget.connect('split-vert', + self.split_vert)) def remove(self, widget): """Remove a widget from the container""" @@ -81,6 +112,8 @@ class HPaned(Paned, gtk.HPaned): """Class initialiser""" Paned.__init__(self) gtk.HPaned.__init__(self) + self.cnxids['init'] = self.connect('expose-event', + self.set_initial_position) class VPaned(Paned, gtk.VPaned): """Merge gtk.VPaned into our base Paned Container""" @@ -88,6 +121,8 @@ class VPaned(Paned, gtk.VPaned): """Class initialiser""" Paned.__init__(self) gtk.VPaned.__init__(self) + self.cnxids['init'] = self.connect('expose-event', + self.set_initial_position) gobject.type_register(HPaned) gobject.type_register(VPaned) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index ac636ce1..dcb77d03 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -72,6 +72,8 @@ class Terminal(gtk.VBox): composite_support = None + cnxid = None + def __init__(self): """Class initialiser""" gtk.VBox.__init__(self) @@ -252,7 +254,7 @@ class Terminal(gtk.VBox): self.vte.connect('enter_notify_event', self.on_vte_notify_enter) - self.vte.connect_after('realize', self.reconfigure) + self.cnxid = self.vte.connect_after('realize', self.reconfigure) def create_popup_group_menu(self, widget, event = None): """Pop up a menu for the group widget""" @@ -423,6 +425,12 @@ class Terminal(gtk.VBox): def reconfigure(self, widget=None): """Reconfigure our settings""" + dbg('Terminal::reconfigure') + if self.cnxid: + dbg('Terminal::reconfigure: disconnecting') + self.vte.disconnect(self.cnxid) + self.cnxid = None + # FIXME: actually reconfigure our settings pass