[gedit] Bug 611161 - Output panel and python console should use terminal font
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Bug 611161 - Output panel and python console should use terminal font
- Date: Sat, 15 May 2010 17:30:01 +0000 (UTC)
commit 4d50011ebe11ef65c317982932937286e16fe64a
Author: Garrett Regier <alias301 gmail com>
Date: Sat May 15 10:29:42 2010 -0700
Bug 611161 - Output panel and python console should use terminal font
plugins/externaltools/tools/outputpanel.py | 70 +++++++++++++++++++++++-
plugins/pythonconsole/pythonconsole/console.py | 68 +++++++++++++++++++++++-
2 files changed, 136 insertions(+), 2 deletions(-)
---
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index fa1bea3..dc9321f 100644
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -21,6 +21,7 @@ __all__ = ('OutputPanel', 'UniqueById')
import gtk, gedit
import pango
+import gconf
import gobject
import os
from weakref import WeakKeyDictionary
@@ -46,6 +47,12 @@ class UniqueById:
return self.__class__.__shared_state
class OutputPanel(UniqueById):
+
+ DEFAULT_FONT = "Monospace 10"
+
+ GCONF_INTERFACE_DIR = "/desktop/gnome/interface"
+ GCONF_PROFILE_DIR = "/apps/gnome-terminal/profiles/Default"
+
def __init__(self, datadir, window):
if UniqueById.__init__(self, window):
return
@@ -57,13 +64,23 @@ class OutputPanel(UniqueById):
'on_view_button_press_event': self.on_view_button_press_event
}
+ gconf_client.add_dir(self.GCONF_INTERFACE_DIR,
+ gconf.CLIENT_PRELOAD_NONE)
+ gconf_client.add_dir(self.GCONF_PROFILE_DIR,
+ gconf.CLIENT_PRELOAD_NONE)
+
+ gconf_client.notify_add(self.GCONF_INTERFACE_DIR,
+ self.on_gconf_notification)
+ gconf_client.notify_add(self.GCONF_PROFILE_DIR,
+ self.on_gconf_notification)
+
self.window = window
self.ui = gtk.Builder()
self.ui.add_from_file(os.path.join(datadir, 'ui', 'outputpanel.ui'))
self.ui.connect_signals(callbacks)
self.panel = self["output-panel"]
- self['view'].modify_font(pango.FontDescription('Monospace'))
+ self.reconfigure()
buffer = self['view'].get_buffer()
@@ -93,6 +110,40 @@ class OutputPanel(UniqueById):
self.link_parser = linkparsing.LinkParser()
self.file_lookup = filelookup.FileLookup()
+ def reconfigure(self):
+ # WORKING ON BUG: 611161
+ # Font
+ font_desc = None
+ system_font = gconf_get_str(self.GCONF_INTERFACE_DIR + "/monospace_font_name",
+ self.DEFAULT_FONT)
+
+ if gconf_get_bool(self.GCONF_PROFILE_DIR + "/use_system_font"):
+ font_name = system_font
+ else:
+ font_name = gconf_get_str(self.GCONF_PROFILE_DIR + "/font", system_font)
+
+ try:
+ font_desc = pango.FontDescription(font_name)
+ except:
+ if font_name != self.DEFAULT_FONT:
+ if font_name != system_font:
+ try:
+ font_desc = pango.FontDescription(system_font)
+ except:
+ pass
+
+ if font_desc == None:
+ try:
+ font_desc = pango.FontDescription(self.DEFAULT_FONT)
+ except:
+ pass
+
+ if font_desc != None:
+ self["view"].modify_font(font_desc)
+
+ def on_gconf_notification(self, client, cnxn_id, entry, what):
+ self.reconfigure()
+
def set_process(self, process):
self.process = process
@@ -220,4 +271,21 @@ class OutputPanel(UniqueById):
gedit.commands.load_location(self.window, gfile, None, link.line_nr, -1)
gobject.idle_add(self.idle_grab_focus)
+gconf_client = gconf.client_get_default()
+def gconf_get_bool(key, default = False):
+ val = gconf_client.get(key)
+
+ if val is not None and val.type == gconf.VALUE_BOOL:
+ return val.get_bool()
+ else:
+ return default
+
+def gconf_get_str(key, default = ""):
+ val = gconf_client.get(key)
+
+ if val is not None and val.type == gconf.VALUE_STRING:
+ return val.get_string()
+ else:
+ return default
+
# ex:ts=4:et:
diff --git a/plugins/pythonconsole/pythonconsole/console.py b/plugins/pythonconsole/pythonconsole/console.py
old mode 100644
new mode 100755
index e9d7a33..b1bdd13
--- a/plugins/pythonconsole/pythonconsole/console.py
+++ b/plugins/pythonconsole/pythonconsole/console.py
@@ -31,6 +31,7 @@ import traceback
import gobject
import gtk
import pango
+import gconf
from config import PythonConsoleConfig
@@ -42,13 +43,28 @@ class PythonConsole(gtk.ScrolledWindow):
'grab-focus' : 'override',
}
+ DEFAULT_FONT = "Monospace 10"
+
+ GCONF_INTERFACE_DIR = "/desktop/gnome/interface"
+ GCONF_PROFILE_DIR = "/apps/gnome-terminal/profiles/Default"
+
def __init__(self, namespace = {}):
gtk.ScrolledWindow.__init__(self)
+ gconf_client.add_dir(self.GCONF_INTERFACE_DIR,
+ gconf.CLIENT_PRELOAD_NONE)
+ gconf_client.add_dir(self.GCONF_PROFILE_DIR,
+ gconf.CLIENT_PRELOAD_NONE)
+
+ gconf_client.notify_add(self.GCONF_INTERFACE_DIR,
+ self.on_gconf_notification)
+ gconf_client.notify_add(self.GCONF_PROFILE_DIR,
+ self.on_gconf_notification)
+
self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.set_shadow_type(gtk.SHADOW_IN)
self.view = gtk.TextView()
- self.view.modify_font(pango.FontDescription('Monospace'))
+ self.reconfigure()
self.view.set_editable(True)
self.view.set_wrap_mode(gtk.WRAP_WORD_CHAR)
self.add(self.view)
@@ -89,6 +105,39 @@ class PythonConsole(gtk.ScrolledWindow):
def do_grab_focus(self):
self.view.grab_focus()
+ def reconfigure(self):
+ # Font
+ font_desc = None
+ system_font = gconf_get_str(self.GCONF_INTERFACE_DIR + "/monospace_font_name",
+ self.DEFAULT_FONT)
+
+ if gconf_get_bool(self.GCONF_PROFILE_DIR + "/use_system_font"):
+ font_name = system_font
+ else:
+ font_name = gconf_get_str(self.GCONF_PROFILE_DIR + "/font", system_font)
+
+ try:
+ font_desc = pango.FontDescription(font_name)
+ except:
+ if font_name != self.DEFAULT_FONT:
+ if font_name != system_font:
+ try:
+ font_desc = pango.FontDescription(system_font)
+ except:
+ pass
+
+ if font_desc == None:
+ try:
+ font_desc = pango.FontDescription(self.DEFAULT_FONT)
+ except:
+ pass
+
+ if font_desc != None:
+ self.view.modify_font(font_desc)
+
+ def on_gconf_notification(self, client, cnxn_id, entry, what):
+ self.reconfigure()
+
def apply_preferences(self, *args):
config = PythonConsoleConfig()
self.error.set_property("foreground", config.color_error)
@@ -367,4 +416,21 @@ class OutFile:
def tell(self): raise IOError, (29, 'Illegal seek')
truncate = tell
+gconf_client = gconf.client_get_default()
+def gconf_get_bool(key, default = False):
+ val = gconf_client.get(key)
+
+ if val is not None and val.type == gconf.VALUE_BOOL:
+ return val.get_bool()
+ else:
+ return default
+
+def gconf_get_str(key, default = ""):
+ val = gconf_client.get(key)
+
+ if val is not None and val.type == gconf.VALUE_STRING:
+ return val.get_string()
+ else:
+ return default
+
# ex:et:ts=4:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]