[gedit] Made gconf requirement for python console optional



commit 1aef2d54aa571287a49e843bf6d344d2cca1660e
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Jan 24 13:16:09 2010 +0100

    Made gconf requirement for python console optional

 plugins/pythonconsole/pythonconsole/__init__.py |   25 +++++++++------
 plugins/pythonconsole/pythonconsole/config.py   |   37 +++++++++++++++-------
 2 files changed, 40 insertions(+), 22 deletions(-)
---
diff --git a/plugins/pythonconsole/pythonconsole/__init__.py b/plugins/pythonconsole/pythonconsole/__init__.py
index 995ea1d..a3b480b 100644
--- a/plugins/pythonconsole/pythonconsole/__init__.py
+++ b/plugins/pythonconsole/pythonconsole/__init__.py
@@ -29,6 +29,7 @@ import gedit
 
 from console import PythonConsole
 from config import PythonConsoleConfigDialog
+from config import PythonConsoleConfig
 
 PYTHON_ICON = 'gnome-mime-text-x-python'
 
@@ -56,18 +57,22 @@ class PythonConsolePlugin(gedit.Plugin):
         bottom = window.get_bottom_panel()
         bottom.remove_item(console)
 
-    def is_configurable(self):
-        return True
+def create_configure_dialog(self):
 
-    def create_configure_dialog(self):
-        if not self.dlg:
-            self.dlg = PythonConsoleConfigDialog(self.get_data_dir())
+    if not self.dlg:
+        self.dlg = PythonConsoleConfigDialog(self.get_data_dir())
 
-        dialog = self.dlg.dialog()
-        window = gedit.app_get_default().get_active_window()
-        if window:
-            dialog.set_transient_for(window)
+    dialog = self.dlg.dialog()
+    window = gedit.app_get_default().get_active_window()
+    if window:
+        dialog.set_transient_for(window)
 
-        return dialog
+    return dialog
+
+# Here we dynamically insert create_configure_dialog based on if configuration
+# is enabled. This has to be done like this because gedit checks if a plugin
+# is configurable solely on the fact that it has this member defined or not
+if PythonConsoleConfig.enabled():
+    PythonConsolePlugin.create_configure_dialog = create_configure_dialog
 
 # ex:et:ts=4:
diff --git a/plugins/pythonconsole/pythonconsole/config.py b/plugins/pythonconsole/pythonconsole/config.py
index 79c8616..2afed36 100644
--- a/plugins/pythonconsole/pythonconsole/config.py
+++ b/plugins/pythonconsole/pythonconsole/config.py
@@ -25,9 +25,7 @@
 #     Copyrignt (C), 2005 Raphaël Slinckx
 
 import os
-
 import gtk
-import gconf
 
 __all__ = ('PythonConsoleConfig', 'PythonConsoleConfigDialog')
 
@@ -39,25 +37,37 @@ DEFAULT_COMMAND_COLOR = '#314e6c' # Blue Shadow
 DEFAULT_ERROR_COLOR = '#990000' # Accent Red Dark
 
 class PythonConsoleConfig(object):
+    try:
+        import gconf
+    except ImportError:
+        gconf = None
 
     def __init__(self):
         pass
-    
+
+    @staticmethod
+    def enabled():
+        return PythonConsoleConfig.gconf != None
+
     @staticmethod
     def add_handler(handler):
-        gconf.client_get_default().notify_add(GCONF_KEY_BASE, handler)
+        if PythonConsoleConfig.gconf:
+            PythonConsoleConfig.gconf.client_get_default().notify_add(GCONF_KEY_BASE, handler)
 
     color_command = property(
-        lambda self:  self.gconf_get_str(GCONF_KEY_COMMAND_COLOR, DEFAULT_COMMAND_COLOR),
-        lambda self, value:  self.gconf_set_str(GCONF_KEY_COMMAND_COLOR, value))
+        lambda self: self.gconf_get_str(GCONF_KEY_COMMAND_COLOR, DEFAULT_COMMAND_COLOR),
+        lambda self, value: self.gconf_set_str(GCONF_KEY_COMMAND_COLOR, value))
 
     color_error = property(
-        lambda self:  self.gconf_get_str(GCONF_KEY_ERROR_COLOR, DEFAULT_ERROR_COLOR),
-        lambda self, value:  self.gconf_set_str(GCONF_KEY_ERROR_COLOR, value))
-    
+        lambda self: self.gconf_get_str(GCONF_KEY_ERROR_COLOR, DEFAULT_ERROR_COLOR),
+        lambda self, value: self.gconf_set_str(GCONF_KEY_ERROR_COLOR, value))
+
     @staticmethod
     def gconf_get_str(key, default=''):
-        val = gconf.client_get_default().get(key)
+        if not PythonConsoleConfig.gconf:
+            return default
+
+        val = PythonConsoleConfig.gconf.client_get_default().get(key)
         if val is not None and val.type == gconf.VALUE_STRING:
             return val.get_string()
         else:
@@ -65,9 +75,12 @@ class PythonConsoleConfig(object):
 
     @staticmethod
     def gconf_set_str(key, value):
-        v = gconf.Value(gconf.VALUE_STRING)
+        if not PythonConsoleConfig.gconf:
+            return
+
+        v = PythonConsoleConfig.gconf.Value(gconf.VALUE_STRING)
         v.set_string(value)
-        gconf.client_get_default().set(key, v)
+        PythonConsoleConfig.gconf.client_get_default().set(key, v)
 
 class PythonConsoleConfigDialog(object):
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]