From cf81fe937a22b09fb7fee8e6a7cd75a77a8ec6f9 Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Fri, 10 Jul 2015 21:37:35 +0200 Subject: [PATCH] (trunk-1573) Global setting for changing the titlebar font (partially from Eli Zor branch), but expanded and improved (docs/GUI), plus some minor fixup from this. --- doc/terminator_config.5 | 10 ++++- terminatorlib/config.py | 49 +++++++++++++++------- terminatorlib/editablelabel.py | 5 +++ terminatorlib/preferences.glade | 73 +++++++++++++++++++++++++++++++++ terminatorlib/prefseditor.py | 45 +++++++++++++++++++- terminatorlib/terminal.py | 4 +- terminatorlib/titlebar.py | 8 ++++ 7 files changed, 176 insertions(+), 18 deletions(-) diff --git a/doc/terminator_config.5 b/doc/terminator_config.5 index 7cd996d9..56763c04 100644 --- a/doc/terminator_config.5 +++ b/doc/terminator_config.5 @@ -118,6 +118,14 @@ Default value: \fB'#000000'\fR Sets the colour of the background of the titlebar of any terminal that will \fBnot\fR receive input from the active terminal. Default value: \fB'#C0BEBF'\fR .TP +.B title_use_system_font \fR(boolean) +Whether or not to use the GNOME default proportional font for titlebars. +Default value: \fBTrue\fR +.TP +.B title_font \fR(string) +An Pango font name. Examples are "Sans 12" or "Monospace Bold 14". +Default value: \fB"Sans 9"\fR +.TP .B inactive_color_offset Controls how much to reduce the colour values of fonts in terminals that do not have focus. It is a simple multiplication factor. A font colour that was RGB(200,200,200) with an inactive_color_offset of 0.5 would set inactive terminals to @@ -388,7 +396,7 @@ Default value: \fBTrue\fR .TP .B font An Pango font name. Examples are "Sans 12" or "Monospace Bold 14". -Default value: \fBMono 8\fR +Default value: \fBMono 10\fR .TP .B foreground_color Default colour of text in the terminal, as a colour specification (can be HTML-style hex digits, or a colour name such as "red"). \fBNote:\fR You may need to set \fBuse_theme_colors=False\fR to force this setting to take effect. diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 320bc63f..93f4326d 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -117,8 +117,10 @@ DEFAULTS = { 'enabled_plugins' : ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler'], - 'suppress_multiple_term_dialog': False, - 'always_split_with_profile': False, + 'suppress_multiple_term_dialog': False, + 'always_split_with_profile': False, + 'title_use_system_font' : True, + 'title_font' : 'Sans 9', }, 'keybindings': { 'zoom_in' : 'plus', @@ -259,7 +261,8 @@ class Config(object): base = None profile = None gconf = None - system_font = None + system_mono_font = None + system_prop_font = None system_focus = None inhibited = None @@ -341,38 +344,56 @@ class Config(object): """List all configured layouts""" return(self.base.layouts.keys()) - def get_system_font(self): + def get_system_prop_font(self): """Look up the system font""" - if self.system_font is not None: - return(self.system_font) - elif 'gconf' not in globals(): + if self.system_prop_font is not None: + return(self.system_prop_font) + elif 'GConf' not in globals(): return else: if self.gconf is None: self.gconf = GConf.Client.get_default() - value = self.GConf.get( + value = self.gconf.get( + '/desktop/gnome/interface/font_name') + self.system_prop_font = value.get_string() + self.gconf.notify_add( + '/desktop/gnome/interface/font_name', + self.on_gconf_notify) + return(self.system_prop_font) + + def get_system_mono_font(self): + """Look up the system font""" + if self.system_mono_font is not None: + return(self.system_mono_font) + elif 'GConf' not in globals(): + return + else: + if self.gconf is None: + self.gconf = GConf.Client.get_default() + + value = self.gconf.get( '/desktop/gnome/interface/monospace_font_name') - self.system_font = value.get_string() - self.GConf.notify_add( + self.system_mono_font = value.get_string() + self.gconf.notify_add( '/desktop/gnome/interface/monospace_font_name', self.on_gconf_notify) - return(self.system_font) + return(self.system_mono_font) def get_system_focus(self): """Look up the system focus setting""" if self.system_focus is not None: return(self.system_focus) - elif 'gconf' not in globals(): + elif 'GConf' not in globals(): return else: if self.gconf is None: self.gconf = GConf.Client.get_default() - value = self.GConf.get('/apps/metacity/general/focus_mode') + value = self.gconf.get('/apps/metacity/general/focus_mode') if value: self.system_focus = value.get_string() - self.GConf.notify_add('/apps/metacity/general/focus_mode', + self.gconf.notify_add('/apps/metacity/general/focus_mode', self.on_gconf_notify) return(self.system_focus) diff --git a/terminatorlib/editablelabel.py b/terminatorlib/editablelabel.py index 7cdf7dd9..a073be21 100644 --- a/terminatorlib/editablelabel.py +++ b/terminatorlib/editablelabel.py @@ -150,4 +150,9 @@ class EditableLabel(Gtk.EventBox): def set_custom(self): """Set the customness of the string to True""" self._custom = True + + def modify_font(self, fontdesc): + """Set the label font using a pango.FontDescription""" + self._label.modify_font(fontdesc) + GObject.type_register(EditableLabel) diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index f4a9ec9b..eede5d7e 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -1243,6 +1243,7 @@ True False + 3 2 12 6 @@ -1259,6 +1260,78 @@ 2 + GTK_FILL + + + + + + _Use the system font + True + True + False + False + True + True + + + + 2 + 1 + 2 + GTK_FILL + + + + + + True + False + 12 + + + True + False + 12 + + + True + False + 0 + _Font: + True + font_selector + + + False + False + 0 + + + + + True + True + True + False + False + Choose A Titlebar Font + True + + + + False + False + 1 + + + + + + + 2 + 2 + 3 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index 4432e053..8ffd98d1 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -284,6 +284,19 @@ class PrefsEditor: #Always split with profile widget = guiget('always_split_with_profile') widget.set_active(self.config['always_split_with_profile']) + #Titlebar font selector + # Use system font + widget = guiget('title_system_font_checkbutton') + widget.set_active(self.config['title_use_system_font']) + self.on_title_system_font_checkbutton_toggled(widget) + # Font selector + widget = guiget('title_font_selector') + if self.config['title_use_system_font'] == True: + fontname = self.config.get_system_prop_font() + if fontname is not None: + widget.set_font_name(fontname) + else: + widget.set_font_name(self.config['title_font']) ## Profile tab # Populate the profile list @@ -372,7 +385,7 @@ class PrefsEditor: widget = guiget('font_selector') if self.config['use_system_font'] == True: - fontname = self.config.get_system_font() + fontname = self.config.get_system_mono_font() if fontname is not None: widget.set_font_name(fontname) else: @@ -895,6 +908,11 @@ class PrefsEditor: self.config['font'] = widget.get_font_name() self.config.save() + def on_title_font_selector_font_set(self, widget): + """Titlebar Font changed""" + self.config['title_font'] = widget.get_font_name() + self.config.save() + def on_title_receive_bg_color_color_set(self, widget): """Title receive background colour changed""" self.config['title_receive_bg_color'] = color2hex(widget) @@ -1114,6 +1132,31 @@ class PrefsEditor: widget.set_sensitive(not value) self.config['use_system_font'] = value self.config.save() + + if self.config['use_system_font'] == True: + fontname = self.config.get_system_mono_font() + if fontname is not None: + widget.set_font_name(fontname) + else: + widget.set_font_name(self.config['font']) + + def on_title_system_font_checkbutton_toggled(self, checkbox): + """Toggling the title_use_system_font checkbox needs to alter the + sensitivity of the font selector""" + guiget = self.builder.get_object + widget = guiget('title_font_selector') + value = checkbox.get_active() + + widget.set_sensitive(not value) + self.config['title_use_system_font'] = value + self.config.save() + + if self.config['title_use_system_font'] == True: + fontname = self.config.get_system_prop_font() + if fontname is not None: + widget.set_font_name(fontname) + else: + widget.set_font_name(self.config['title_font']) def on_reset_compatibility_clicked(self, widget): """Reset the confusing and annoying backspace/delete options to the diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 1b543eee..b2e49212 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -623,7 +623,7 @@ class Terminal(Gtk.VBox): if not self.custom_font_size: try: if self.config['use_system_font'] == True: - font = self.config.get_system_font() + font = self.config.get_system_mono_font() else: font = self.config['font'] self.set_font(Pango.FontDescription(font)) @@ -1427,7 +1427,7 @@ class Terminal(Gtk.VBox): def zoom_orig(self): """Restore original font size""" if self.config['use_system_font'] == True: - font = self.config.get_system_font() + font = self.config.get_system_mono_font() else: font = self.config['font'] dbg("Terminal::zoom_orig: restoring font to: %s" % font) diff --git a/terminatorlib/titlebar.py b/terminatorlib/titlebar.py index 6589ad7f..4cd26145 100755 --- a/terminatorlib/titlebar.py +++ b/terminatorlib/titlebar.py @@ -5,6 +5,7 @@ from gi.repository import Gtk, Gdk from gi.repository import GObject +from gi.repository import Pango import random import itertools @@ -106,6 +107,13 @@ class Titlebar(Gtk.EventBox): else: self.label.set_text("%s %s" % (self.termtext, self.sizetext)) + if (not self.config['title_use_system_font']) and self.config['title_font']: + title_font = Pango.FontDescription(self.config['title_font']) + else: + title_font = Pango.FontDescription(self.config.get_system_prop_font()) + self.label.modify_font(title_font) + self.grouplabel.modify_font(title_font) + if other: term = self.terminal terminator = self.terminator