[meld] Create new conf module for application-wide configuration



commit 661590fdb250c97557665a2c18ab879a576b7de8
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Dec 7 19:06:17 2010 +1000

    Create new conf module for application-wide configuration
    
    The new conf module supersedes the old paths module, and also includes
    version and application name information.

 bin/meld              |   12 +++++++-----
 meld/conf.py          |   19 +++++++++++++++++++
 meld/meldapp.py       |    7 +++----
 meld/meldwindow.py    |    5 ++++-
 meld/paths.py         |   44 --------------------------------------------
 meld/ui/gnomeglade.py |    8 +++-----
 6 files changed, 36 insertions(+), 59 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index 275ba11..46f0872 100755
--- a/bin/meld
+++ b/bin/meld
@@ -78,14 +78,14 @@ else:
     ]
 
 # i18n support
-import meld.paths
+import meld.conf
 import gettext
 _ = gettext.gettext
 
 # Locale setting in gtk.Builder appears somewhat broken under Python. See:
 #   https://bugzilla.gnome.org/show_bug.cgi?id=574520
-locale_domain = "meld"
-locale_dir = meld.paths.locale_dir()
+locale_domain = meld.conf.PACKAGE
+locale_dir = meld.conf.LOCALEDIR
 
 gettext.bindtextdomain(locale_domain, locale_dir)
 locale.setlocale(locale.LC_ALL, '')
@@ -147,8 +147,10 @@ except (ImportError, AssertionError) as e:
     missing_reqs("pygobject", pygobjectver, e)
 
 gobject.threads_init()
-gtk.icon_theme_get_default().append_search_path(meld.paths.icon_dir())
-gtk.rc_parse(meld.paths.share_dir("gtkrc"))
+icon_dir = os.path.join(meld.conf.DATADIR, "icons")
+gtk.icon_theme_get_default().append_search_path(icon_dir)
+rc_file = os.path.join(meld.conf.DATADIR, "gtkrc")
+gtk.rc_parse(rc_file)
 
 
 def main():
diff --git a/meld/conf.py b/meld/conf.py
new file mode 100644
index 0000000..3a73855
--- /dev/null
+++ b/meld/conf.py
@@ -0,0 +1,19 @@
+
+import os
+
+PACKAGE = "meld" # "@PACKAGE"
+VERSION = "1.7.3" # "@VERSION"
+SHAREDIR = ( #SHAREDIR#
+)
+HELPDIR = ( #HELPDIR#
+)
+LOCALEDIR = ( #LOCALEDIR#
+)
+
+melddir = os.path.abspath(os.path.join(
+              os.path.dirname(os.path.realpath(__file__)), ".."))
+
+DATADIR = SHAREDIR or os.path.join(melddir, "data")
+HELPDIR = HELPDIR or os.path.join(melddir, "help")
+LOCALEDIR = LOCALEDIR or os.path.join(melddir, "po")
+
diff --git a/meld/meldapp.py b/meld/meldapp.py
index f7e91db..0e941e2 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -28,12 +28,11 @@ import gio
 import gobject
 import gtk
 
+from . import conf
 from . import filters
 from . import preferences
 from . import recent
 
-version = "1.8.1"
-
 
 class MeldApp(gobject.GObject):
 
@@ -48,7 +47,7 @@ class MeldApp(gobject.GObject):
         gobject.GObject.__init__(self)
         gobject.set_application_name("Meld")
         gtk.window_set_default_icon_name("meld")
-        self.version = version
+        self.version = conf.VERSION
         self.prefs = preferences.MeldPreferences()
         self.prefs.notify_add(self.on_preference_changed)
         self.file_filters = self._parse_filters(self.prefs.filters,
@@ -112,7 +111,7 @@ class MeldApp(gobject.GObject):
         parser = optparse.OptionParser(
             usage=usage,
             description=_("Meld is a file and directory comparison tool."),
-            version="%prog " + version)
+            version="%prog " + conf.VERSION)
         parser.add_option("-L", "--label", action="append", default=[],
             help=_("Set label to use instead of file name"))
         parser.add_option("-n", "--newtab", action="store_true", default=False,
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index d35b965..cc7e5bb 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -23,6 +23,7 @@ import gio
 import gtk
 import gobject
 
+from . import conf
 from . import dirdiff
 from . import filediff
 from . import filemerge
@@ -533,7 +534,9 @@ class MeldWindow(gnomeglade.Component):
     # Toolbar and menu items (help)
     #
     def on_menu_help_activate(self, button):
-        misc.open_uri("ghelp:///"+os.path.abspath(paths.help_dir("C/meld.xml")))
+        # FIXME: This is why our current localised help isn't used.
+        help_dir = "/".join((conf.HELPDIR, "C", "meld.xml"))
+        misc.open_uri("ghelp:///" + os.path.abspath(help_dir))
 
     def on_menu_help_bug_activate(self, button):
         misc.open_uri("http://bugzilla.gnome.org/buglist.cgi?query=product%3Ameld";)
diff --git a/meld/ui/gnomeglade.py b/meld/ui/gnomeglade.py
index df006e6..8907d18 100644
--- a/meld/ui/gnomeglade.py
+++ b/meld/ui/gnomeglade.py
@@ -20,16 +20,14 @@ import os
 
 import gtk
 
-import meld.paths
+import meld.conf
 
 # Import support module to get all builder-constructed widgets in the namespace
 from meld.ui import gladesupport
 
-# FIXME: duplicate defn in bin/meld
-locale_domain = "meld"
 
 def ui_file(filename):
-    return os.path.join(meld.paths._share_dir, "ui", filename)
+    return os.path.join(meld.conf.DATADIR, "ui", filename)
 
 
 class Component(object):
@@ -46,7 +44,7 @@ class Component(object):
     def __init__(self, filename, root, extra=None):
         """Load the widgets from the node 'root' in file 'filename'"""
         self.builder = gtk.Builder()
-        self.builder.set_translation_domain(locale_domain)
+        self.builder.set_translation_domain(meld.conf.PACKAGE)
         objects = [root] + extra if extra else [root]
         filename = ui_file(filename)
         self.builder.add_objects_from_file(filename, objects)


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