From df992c284ed3982f3da82d76650f3a6325a6fd7f Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 21 Jan 2010 21:39:05 +0000 Subject: [PATCH] Look up GNOME system font and focus settings via gconf --- terminatorlib/config.py | 28 ++++++++++++++++++++++++++++ terminatorlib/prefseditor.py | 5 ++++- terminatorlib/terminal.py | 26 +++++++++++++++++++------- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 38fa7ac4..bd7bebfe 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -70,6 +70,11 @@ from configobj.validate import Validator from borg import Borg from util import dbg, err, DEBUG, get_config_dir, dict_diff +try: + import gconf +except ImportError: + dbg('Unable to import gconf, GNOME defaults unavailable') + DEFAULTS = { 'global_config': { 'focus' : 'click', @@ -210,6 +215,7 @@ class Config(object): """Class to provide a slightly richer config API above ConfigBase""" base = None profile = None + gconf = None def __init__(self, profile='default'): self.base = ConfigBase() @@ -259,6 +265,28 @@ class Config(object): """List all configured profiles""" return(self.base.profiles.keys()) + def get_system_font(self): + """Look up the system font""" + if 'gconf' not in globals(): + return + + if self.gconf is None: + self.gconf = gconf.client_get_default() + + value = self.gconf.get('/desktop/gnome/interface/monospace_font_name') + return(value.get_string()) + + def get_system_focus(self): + """Look up the system focus setting""" + if 'gconf' not in globals(): + return + + if self.gconf is None: + self.gconf = gconf.client_get_default() + + value = self.gconf.get('/apps/metacity/general/focus_mode') + return(value.get_string()) + def save(self): """Cause ConfigBase to save our config to file""" return(self.base.save()) diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index c38c7dba..9fa6eafc 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -277,7 +277,10 @@ class PrefsEditor: self.on_system_font_checkbutton_toggled(widget) # Font selector widget = guiget('font-selector') - widget.set_font_name(self.config['font']) + if self.config['use_system_font'] == True: + widget.set_font_name(self.config.get_system_font()) + else: + widget.set_font_name(self.config['font']) # Allow bold text widget = guiget('allow-bold-checkbutton') widget.set_active(self.config['allow_bold']) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 643ccabe..8067e117 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -524,7 +524,11 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) if not self.custom_font_size: try: - self.vte.set_font(pango.FontDescription(self.config['font'])) + if self.config['use_system_font'] == True: + font = self.config.get_system_font() + else: + font = self.config['font'] + self.vte.set_font(pango.FontDescription(font)) except: pass self.vte.set_allow_bold(self.config['allow_bold']) @@ -892,10 +896,14 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) def on_vte_notify_enter(self, term, event): """Handle the mouse entering this terminal""" - if self.config['focus'] in ['sloppy', 'mouse']: - if self.titlebar.editing() == False: - term.grab_focus() - return(False) + sloppy = False + if self.config['focus'] == 'system': + sloppy = self.config.get_system_focus() == 'sloppy' + elif self.config['focus'] in ['sloppy', 'mouse']: + sloppy = True + if sloppy == True and self.titlebar.editing() == False: + term.grab_focus() + return(False) def get_zoom_data(self): """Return a dict of information for Window""" @@ -1103,8 +1111,12 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) def zoom_orig(self): """Restore original font size""" - dbg("Terminal::zoom_orig: restoring font to: %s" % self.config['font']) - self.vte.set_font(pango.FontDescription(self.config['font'])) + if self.config['use_system_font'] == True: + font = self.config.get_system_font() + else: + font = self.config['font'] + dbg("Terminal::zoom_orig: restoring font to: %s" % font) + self.vte.set_font(pango.FontDescription(font)) self.custom_font_size = None def get_cursor_position(self):