From 16cf86d5abf024207c69b3eafa7fb367485268bc Mon Sep 17 00:00:00 2001 From: Peter Lind Date: Wed, 13 Aug 2014 09:36:20 +0200 Subject: [PATCH 1/2] Adding feature to switch between profiles using keybindings - adding config options - adding prefeditor code - adding event handlers to switch back and forth --- terminatorlib/config.py | 4 +++- terminatorlib/prefseditor.py | 4 +++- terminatorlib/terminal.py | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 801dc9c0..04448b80 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -176,7 +176,9 @@ DEFAULTS = { 'insert_number' : '', 'insert_padded' : '', 'edit_window_title': '', - 'layout_launcher' : '' + 'layout_launcher' : '', + 'next_profile' : '', + 'previous_profile' : '' }, 'profiles': { 'default': { diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index 9e3c684d..5bce8ab5 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -147,7 +147,9 @@ class PrefsEditor: 'insert_number' : 'Insert terminal number', 'insert_padded' : 'Insert zero padded terminal number', 'edit_window_title': 'Edit window title', - 'layout_launcher' : 'Open layout launcher window' + 'layout_launcher' : 'Open layout launcher window', + 'next_profile' : 'Switch to next profile', + 'previous_profile' : 'Switch to previous profile' } def __init__ (self, term): diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index adf18adc..012c9ebb 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -196,6 +196,44 @@ class Terminal(gtk.VBox): """Return our profile name""" return(self.config.profile) + def switch_to_next_profile(self): + profilelist = self.config.list_profiles() + + if len(profilelist) > 1: + next = False + first = False + + for profile in profilelist: + if first == False: + first = profile + + if next: + self.force_set_profile(False, profile) + return + + if profile == self.get_profile(): + next = True + + if first: + self.force_set_profile(False, first) + + def switch_to_previous_profile(self): + profilelist = self.config.list_profiles() + + if len(profilelist) > 1: + last = False + + for profile in profilelist: + if profile == self.get_profile(): + if last: + self.force_set_profile(False, last) + return + + last = profile + + if last: + self.force_set_profile(False, last) + def get_cwd(self): """Return our cwd""" return(self.terminator.pid_cwd(self.pid)) @@ -1545,6 +1583,12 @@ class Terminal(gtk.VBox): def key_zoom_in(self): self.zoom_in() + def key_next_profile(self): + self.switch_to_next_profile() + + def key_previous_profile(self): + self.switch_to_previous_profile() + def key_zoom_out(self): self.zoom_out() From f3403d72a9cc5019af259e265b6d295fe81ad5b4 Mon Sep 17 00:00:00 2001 From: Peter Lind Date: Wed, 13 Aug 2014 18:52:59 +0200 Subject: [PATCH 2/2] Improved code for cycling through profiles --- terminatorlib/terminal.py | 42 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 012c9ebb..6b57fc63 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -198,41 +198,23 @@ class Terminal(gtk.VBox): def switch_to_next_profile(self): profilelist = self.config.list_profiles() + list_length = len(profilelist) - if len(profilelist) > 1: - next = False - first = False - - for profile in profilelist: - if first == False: - first = profile - - if next: - self.force_set_profile(False, profile) - return - - if profile == self.get_profile(): - next = True - - if first: - self.force_set_profile(False, first) + if list_length > 1: + if profilelist.index(self.get_profile()) + 1 == list_length: + self.force_set_profile(False, profilelist[0]) + else: + self.force_set_profile(False, profilelist[profilelist.index(self.get_profile()) + 1]) def switch_to_previous_profile(self): profilelist = self.config.list_profiles() + list_length = len(profilelist) - if len(profilelist) > 1: - last = False - - for profile in profilelist: - if profile == self.get_profile(): - if last: - self.force_set_profile(False, last) - return - - last = profile - - if last: - self.force_set_profile(False, last) + if list_length > 1: + if profilelist.index(self.get_profile()) == 0: + self.force_set_profile(False, profilelist[list_length - 1]) + else: + self.force_set_profile(False, profilelist[profilelist.index(self.get_profile()) - 1]) def get_cwd(self): """Return our cwd"""