From 5e54d42eca377ff3c54d26a539241bfc4d351ff6 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 5 Sep 2009 00:34:09 +0100 Subject: [PATCH] work on grouping/ungrouping of all terminals in a tab --- terminatorlib/newterminator.py | 7 +++++++ terminatorlib/terminal.py | 17 +++++++++++++++-- terminatorlib/util.py | 10 +++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/terminatorlib/newterminator.py b/terminatorlib/newterminator.py index 39b312b4..e9466b71 100755 --- a/terminatorlib/newterminator.py +++ b/terminatorlib/newterminator.py @@ -93,4 +93,11 @@ class Terminator(Borg): else: return([widget]) + def group_tab(self, widget): + """Group all the terminals in a tab""" + pass + + def ungroup_tab(self, widget): + """Ungroup all the terminals in a tab""" + pass # vim: set expandtab ts=4 sw=4: diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index f682cced..22605135 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -11,7 +11,7 @@ pygtk.require('2.0') import gtk import gobject -from util import dbg, err, gerr +from util import dbg, err, gerr, has_ancestor from config import Config from cwd import get_default_cwd from newterminator import Terminator @@ -35,6 +35,8 @@ class Terminal(gtk.VBox): (gobject.TYPE_STRING,)), 'enumerate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)), + 'group-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'ungroup-tab': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), } TARGET_TYPE_VTE = 8 @@ -63,6 +65,8 @@ class Terminal(gtk.VBox): self.terminator = Terminator() self.connect('enumerate', self.terminator.do_enumerate) + self.connect('group-tab', self.terminator.group_tab) + self.connect('ungroup-tab', self.terminator.ungroup_tab) self.matches = {} @@ -277,7 +281,16 @@ class Terminal(gtk.VBox): item.connect('activate', self.ungroup, self.group) menu.append(item) - # FIXME: Functions to group/ungroup all terms in current tab + if has_ancestor(self, gtk.Notebook): + item = gtk.MenuItem(_('G_roup all in tab')) + item.connect('activate', lambda menu_item: self.emit('group_tab')) + menu.append(item) + + if len(self.terminator.groups) > 0: + item = gtk.MenuItem(_('Ungr_oup all in tab')) + item.connect('activate', lambda menu_item: + self.emit('ungroup_tab')) + menu.append(item) if len(self.terminator.groups) > 0: item = gtk.MenuItem(_('Remove all groups')) diff --git a/terminatorlib/util.py b/terminatorlib/util.py index eb08b4ab..6bde7b95 100755 --- a/terminatorlib/util.py +++ b/terminatorlib/util.py @@ -17,6 +17,7 @@ """Terminator.util - misc utility functions""" import sys +import gtk # set this to true to enable debugging output DEBUG = True @@ -34,8 +35,15 @@ def gerr(message = None): """Display a graphical error. This should only be used for serious errors as it will halt execution""" - import gtk dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message) dialog.run() +def has_ancestor(widget, type): + """Walk up the family tree of widget to see if any ancestors are of type""" + while widget: + widget = widget.get_parent() + if isinstance(widget, type): + return(True) + return(False) +