From ee81bd4f76635eb7464d5af28691a1a72cc586e7 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 26 Dec 2009 20:09:16 +0000 Subject: [PATCH] Make the terminal context menu list available profiles and switch between them --- terminatorlib/config.py | 2 ++ terminatorlib/terminal.py | 9 +++++++++ terminatorlib/terminal_popup_menu.py | 22 +++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 2e2ea335..19abb559 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -198,8 +198,10 @@ class Config(object): def set_profile(self, profile): """Set our profile (which usually means change it)""" + dbg('Config::set_profile: Changing profile to %s' % profile) self.profile = profile if not self.base.profiles.has_key(profile): + dbg('Config::set_profile: %s does not exist, creating' % profile) self.base.profiles[profile] = copy(DEFAULTS['profiles']['default']) def del_profile(self, profile): diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 99198293..9bb176c8 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -135,6 +135,15 @@ class Terminal(gtk.VBox): if self.config['http_proxy'] and self.config['http_proxy'] != '': os.putenv('http_proxy', self.config['http_proxy']) + def set_profile(self, widget, profile): + """Set our profile""" + self.config.set_profile(profile) + self.reconfigure() + + def get_profile(self): + """Return our profile name""" + return(self.config.profile) + def close(self): """Close ourselves""" dbg('Terminal::close: emitting close-term') diff --git a/terminatorlib/terminal_popup_menu.py b/terminatorlib/terminal_popup_menu.py index 0500ddad..c0877c69 100755 --- a/terminatorlib/terminal_popup_menu.py +++ b/terminatorlib/terminal_popup_menu.py @@ -10,6 +10,7 @@ from version import APP_NAME from translation import _ from encoding import TerminatorEncoding from util import err +from config import Config import plugin class TerminalPopupMenu(object): @@ -130,10 +131,29 @@ class TerminalPopupMenu(object): item.set_sensitive(False) menu.append(item) + item = gtk.MenuItem(_('Profiles')) + submenu = gtk.Menu() + item.set_submenu(submenu) + menu.append(item) + + config = Config() + current = terminal.get_profile() + + group = None + + for profile in config.list_profiles(): + item = gtk.RadioMenuItem(group, profile.capitalize()) + item.connect('activate', terminal.set_profile, profile) + if profile == current: + item.set_active(True) + submenu.append(item) + + submenu.append(gtk.MenuItem()) + item = gtk.MenuItem(_('Ed_it profile')) item.connect('activate', lambda x: terminal.terminator.edit_profile(terminal)) - menu.append(item) + submenu.append(item) self.add_encoding_items(menu)