From 79a340539b0fc00b80b42d82ab6bf106570e6262 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 9 Feb 2010 00:23:21 +0000 Subject: [PATCH] Make the titlebar presence configurable by config file and context menu. If it's missing, draw a frame around the Terminal, to indicae colour --- terminatorlib/config.py | 1 + terminatorlib/preferences.glade | 18 ++++++++++++++++-- terminatorlib/prefseditor.py | 6 ++++++ terminatorlib/terminal.py | 22 ++++++++++++++++++++-- terminatorlib/terminal_popup_menu.py | 5 +++++ terminatorlib/titlebar.py | 11 +++++++++++ 6 files changed, 59 insertions(+), 4 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 4f882de6..c1281575 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -166,6 +166,7 @@ DEFAULTS = { 'emulation' : 'xterm', 'font' : 'Mono 10', 'foreground_color' : '#aaaaaaaaaaaa', + 'show_titlebar' : True, 'scrollbar_position' : "right", 'scroll_background' : True, 'scroll_on_keystroke' : True, diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index e37c9f6c..d4f9fe2a 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -864,6 +864,20 @@ 5 + + + Show titlebar + True + True + False + True + + + False + False + 6 + + True @@ -896,7 +910,7 @@ False - 6 + 7 @@ -1024,7 +1038,7 @@ False False - 7 + 8 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index f6744ff8..d333fb93 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -318,6 +318,9 @@ class PrefsEditor: # WM_URGENT terminal bell widget = guiget('urgent-bell-checkbutton') widget.set_active(self.config['urgent_bell']) + # Show titlebar + widget = guiget('show_titlebar') + widget.set_active(self.config['show_titlebar']) # Word chars widget = guiget('word-chars-entry') widget.set_text(self.config['word_chars']) @@ -486,6 +489,9 @@ class PrefsEditor: # Urgent Bell widget = guiget('urgent-bell-checkbutton') self.config['urgent_bell'] = widget.get_active() + # Show titlebar + widget = guiget('show_titlebar') + self.config['show_titlebar'] = widget.get_active() # Word chars widget = guiget('word-chars-entry') self.config['word_chars'] = widget.get_text() diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 00c46234..63e0971e 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -74,6 +74,7 @@ class Terminal(gtk.VBox): scrollbar_position = None titlebar = None searchbar = None + border_boxes = None group = None cwd = None @@ -178,6 +179,9 @@ class Terminal(gtk.VBox): def create_terminalbox(self): """Create a GtkHBox containing the terminal and a scrollbar""" + ebox1 = gtk.EventBox() + ebox2 = gtk.EventBox() + ebox1.add(ebox2) terminalbox = gtk.HBox() self.scrollbar = gtk.VScrollbar(self.vte.get_adjustment()) self.scrollbar.set_no_show_all(True) @@ -193,9 +197,19 @@ class Terminal(gtk.VBox): func(self.vte) func(self.scrollbar, False) - terminalbox.show() + ebox2.add(terminalbox) + ebox1.show_all() - return(terminalbox) + self.border_boxes = (ebox1, ebox2) + return(ebox1) + + def terminal_border(self, width, colour=None): + """Show a border around the terminal and optionally colour it in""" + ebox1, ebox2 = self.border_boxes + + ebox2.set_border_width(width) + if colour: + ebox1.modify_bg(gtk.STATE_NORMAL, colour) def update_url_matches(self, posix = True): """Update the regexps used to match URLs""" @@ -728,6 +742,10 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) """Show or hide the terminal scrollbar""" self.toggle_widget_visibility(self.scrollbar) + def do_titlebar_toggle(self): + """Show or hide the terminal titlebar""" + self.toggle_widget_visibility(self.titlebar) + def toggle_widget_visibility(self, widget): """Show or hide a widget""" if widget.get_property('visible'): diff --git a/terminatorlib/terminal_popup_menu.py b/terminatorlib/terminal_popup_menu.py index 370095b9..c2af5ef9 100755 --- a/terminatorlib/terminal_popup_menu.py +++ b/terminatorlib/terminal_popup_menu.py @@ -128,6 +128,11 @@ class TerminalPopupMenu(object): item.connect('toggled', lambda x: terminal.do_scrollbar_toggle()) menu.append(item) + item = gtk.CheckMenuItem(_('Show _titlebar')) + item.set_active(terminal.titlebar.get_property('visible')) + item.connect('toggled', lambda x: terminal.do_titlebar_toggle()) + menu.append(item) + item = gtk.MenuItem(_('_Preferences')) item.connect('activate', lambda x: PrefsEditor(self.terminal)) menu.append(item) diff --git a/terminatorlib/titlebar.py b/terminatorlib/titlebar.py index b1bab28f..6b47ceb8 100755 --- a/terminatorlib/titlebar.py +++ b/terminatorlib/titlebar.py @@ -90,6 +90,7 @@ class Titlebar(gtk.EventBox): def update(self, other=None): """Update our contents""" + default_bg = False self.label.set_text("%s %s" % (self.termtext, self.sizetext)) if other: @@ -100,6 +101,7 @@ class Titlebar(gtk.EventBox): title_fg = self.config['title_inactive_fg_color'] title_bg = self.config['title_inactive_bg_color'] icon = '_receive_off' + default_bg = True else: title_fg = self.config['title_receive_fg_color'] title_bg = self.config['title_receive_bg_color'] @@ -115,6 +117,7 @@ class Titlebar(gtk.EventBox): title_fg = self.config['title_inactive_fg_color'] title_bg = self.config['title_inactive_bg_color'] icon = '_receive_off' + default_bg = True group_fg = self.config['title_inactive_fg_color'] group_bg = self.config['title_inactive_bg_color'] else: @@ -135,6 +138,14 @@ class Titlebar(gtk.EventBox): gtk.gdk.color_parse(group_fg)) self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(title_bg)) + if not self.get_property('visible'): + if default_bg == True: + color = term.get_style().bg[gtk.STATE_NORMAL] + else: + color = gtk.gdk.color_parse(title_bg) + term.terminal_border(2, color) + else: + term.terminal_border(0) self.ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(group_bg)) self.set_from_icon_name(icon, gtk.ICON_SIZE_MENU)