[meld] Move all locating of GtkBuilder and UIManager files into gnomeglade



commit aa32cf8557daa62e0a83fcda24bf50f02d3ec64f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Jan 27 08:48:31 2012 +1000

    Move all locating of GtkBuilder and UIManager files into gnomeglade

 meld/dirdiff.py       |    7 +++----
 meld/filediff.py      |   11 ++++-------
 meld/meldwindow.py    |    9 ++++-----
 meld/newdifftab.py    |    3 +--
 meld/patchdialog.py   |    4 +---
 meld/paths.py         |   14 +-------------
 meld/preferences.py   |    3 +--
 meld/ui/findbar.py    |    5 ++---
 meld/ui/gnomeglade.py |    8 ++++++++
 meld/ui/listwidget.py |    3 +--
 meld/ui/vcdialogs.py  |    7 ++-----
 meld/vcview.py        |    7 +++----
 12 files changed, 31 insertions(+), 50 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 6bd5725..f3efcd6 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -35,7 +35,6 @@ import gtk.keysyms
 from . import melddoc
 from . import tree
 from . import misc
-from . import paths
 from . import recent
 from .ui import gnomeglade
 from .ui import emblemcellrenderer
@@ -265,10 +264,10 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def __init__(self, prefs, num_panes):
         melddoc.MeldDoc.__init__(self, prefs)
-        gnomeglade.Component.__init__(self, paths.ui_dir("dirdiff.ui"),
-                                      "dirdiff", ["DirdiffActions"])
+        gnomeglade.Component.__init__(self, "dirdiff.ui", "dirdiff",
+                                      ["DirdiffActions"])
 
-        self.ui_file = paths.ui_dir("dirdiff-ui.xml")
+        self.ui_file = gnomeglade.ui_file("dirdiff-ui.xml")
         self.actiongroup = self.DirdiffActions
         self.actiongroup.set_translation_domain("meld")
         self.main_actiongroup = None
diff --git a/meld/filediff.py b/meld/filediff.py
index 8909906..acb297d 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -40,7 +40,6 @@ from . import melddoc
 from . import merge
 from . import misc
 from . import patchdialog
-from . import paths
 from . import recent
 from . import undo
 from .ui import findbar
@@ -157,7 +156,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         """Start up an filediff with num_panes empty contents.
         """
         melddoc.MeldDoc.__init__(self, prefs)
-        gnomeglade.Component.__init__(self, paths.ui_dir("filediff.ui"), "filediff")
+        gnomeglade.Component.__init__(self, "filediff.ui", "filediff")
         self.map_widgets_into_lists(["textview", "fileentry", "diffmap",
                                      "scrolledwindow", "linkmap",
                                      "statusimage", "msgarea_mgr", "vbox",
@@ -300,7 +299,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
              self.on_action_lock_scrolling_toggled, True),
         )
 
-        self.ui_file = paths.ui_dir("filediff-ui.xml")
+        self.ui_file = gnomeglade.ui_file("filediff-ui.xml")
         self.actiongroup = gtk.ActionGroup('FilediffPopupActions')
         self.actiongroup.set_translation_domain("meld")
         self.actiongroup.add_actions(actions)
@@ -847,8 +846,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         response = gtk.RESPONSE_OK
         modified = [b.data.modified for b in self.textbuffer]
         if True in modified:
-            ui_path = paths.ui_dir("filediff.ui")
-            dialog = gnomeglade.Component(ui_path, "check_save_dialog")
+            dialog = gnomeglade.Component("filediff.ui", "check_save_dialog")
             dialog.widget.set_transient_for(self.widget.get_toplevel())
             if label:
                 dialog.widget.props.text = label
@@ -1680,8 +1678,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         response = gtk.RESPONSE_OK
         unsaved = [b.data.label for b in self.textbuffer if b.data.modified]
         if unsaved:
-            ui_path = paths.ui_dir("filediff.ui")
-            dialog = gnomeglade.Component(ui_path, "revert_dialog")
+            dialog = gnomeglade.Component("filediff.ui", "revert_dialog")
             dialog.widget.set_transient_for(self.widget.get_toplevel())
             # FIXME: Should be packed into dialog.widget.get_message_area(),
             # but this is unbound on currently required PyGTK.
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 1fd04b1..d35b965 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -29,7 +29,6 @@ from . import filemerge
 from . import melddoc
 from . import misc
 from . import newdifftab
-from . import paths
 from . import preferences
 from . import recent
 from . import task
@@ -53,8 +52,7 @@ class MeldWindow(gnomeglade.Component):
     # init
     #
     def __init__(self):
-        gladefile = paths.ui_dir("meldapp.ui")
-        gnomeglade.Component.__init__(self, gladefile, "meldapp")
+        gnomeglade.Component.__init__(self, "meldapp.ui", "meldapp")
         self.widget.set_name("meldapp")
 
         actions = (
@@ -164,7 +162,7 @@ class MeldWindow(gnomeglade.Component):
                 _("Show or hide the statusbar"),
                 self.on_menu_statusbar_toggled, app.prefs.statusbar_visible)
         )
-        ui_file = paths.ui_dir("meldapp-ui.xml")
+        ui_file = gnomeglade.ui_file("meldapp-ui.xml")
         self.actiongroup = gtk.ActionGroup('MainActions')
         self.actiongroup.set_translation_domain("meld")
         self.actiongroup.add_actions(actions)
@@ -545,7 +543,8 @@ class MeldWindow(gnomeglade.Component):
         builder = gtk.Builder()
         # FIXME: domain literal duplicated from bin/meld
         builder.set_translation_domain("meld")
-        builder.add_objects_from_file(paths.ui_dir("meldapp.ui"), ["about"])
+        ui_file = gnomeglade.ui_file("meldapp.ui")
+        builder.add_objects_from_file(ui_file, ["about"])
         about = builder.get_object("about")
         about.props.version = app.version
         about.set_transient_for(self.widget)
diff --git a/meld/newdifftab.py b/meld/newdifftab.py
index a1f5ad1..e03c7db 100644
--- a/meld/newdifftab.py
+++ b/meld/newdifftab.py
@@ -20,7 +20,6 @@ import os
 import gobject
 import gtk
 
-from . import paths
 from .ui import gnomeglade
 
 from .meldapp import app
@@ -37,7 +36,7 @@ class NewDiffTab(gobject.GObject, gnomeglade.Component):
 
     def __init__(self, parentapp):
         gobject.GObject.__init__(self)
-        gnomeglade.Component.__init__(self, paths.ui_dir("tab-placeholder.ui"),
+        gnomeglade.Component.__init__(self, "tab-placeholder.ui",
                                       "new_comparison_tab")
         self.map_widgets_into_lists(["file_chooser", "dir_chooser",
                                      "vc_chooser"])
diff --git a/meld/patchdialog.py b/meld/patchdialog.py
index 719ff06..e45ef94 100644
--- a/meld/patchdialog.py
+++ b/meld/patchdialog.py
@@ -23,7 +23,6 @@ import os
 import gtk
 import pango
 
-from . import paths
 from .ui import gnomeglade
 
 from .util.compat import text_type
@@ -33,8 +32,7 @@ from .util.sourceviewer import srcviewer
 class PatchDialog(gnomeglade.Component):
 
     def __init__(self, filediff):
-        ui_file = paths.ui_dir("patch-dialog.ui")
-        gnomeglade.Component.__init__(self, ui_file, "patchdialog")
+        gnomeglade.Component.__init__(self, "patch-dialog.ui", "patchdialog")
 
         self.widget.set_transient_for(filediff.widget.get_toplevel())
         self.prefs = filediff.prefs
diff --git a/meld/paths.py b/meld/paths.py
index 36fb1bc..2126ca1 100644
--- a/meld/paths.py
+++ b/meld/paths.py
@@ -28,7 +28,7 @@ appdir = os.path.dirname(os.path.dirname(__file__))
 
 if not _locale_dir: _locale_dir = os.path.join(appdir,"po")
 if not _help_dir:    _help_dir  = os.path.join(appdir,"help")
-if not _share_dir:  _share_dir  = appdir
+if not _share_dir:  _share_dir  = os.path.join(appdir, "data")
 
 def locale_dir(*args): # i18n files
     return os.path.join(_locale_dir, *args)
@@ -36,18 +36,6 @@ def locale_dir(*args): # i18n files
 def help_dir(*args): # help
     return os.path.join(_help_dir, *args)
 
-def share_dir(*args):
-    if os.path.exists(os.path.join(_share_dir, "data")):
-        return os.path.join(_share_dir, "data", *args)
-    else:
-        return os.path.join(_share_dir, *args)
-
-def ui_dir(*args):
-    if os.path.exists(os.path.join(_share_dir, "data")):
-        return os.path.join(_share_dir, "data", "ui", *args)
-    else:
-        return os.path.join(_share_dir, "ui", *args)
-
 def icon_dir(*args):
     if os.path.exists(os.path.join(_share_dir, "data")):
         return os.path.join(_share_dir, "data", "icons", *args)
diff --git a/meld/preferences.py b/meld/preferences.py
index 802c58e..1342110 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -26,7 +26,6 @@ import gtk
 
 from . import filters
 from . import misc
-from . import paths
 from . import vc
 from .ui import gnomeglade
 from .ui import listwidget
@@ -142,7 +141,7 @@ class ColumnList(listwidget.ListWidget):
 class PreferencesDialog(gnomeglade.Component):
 
     def __init__(self, parent, prefs):
-        gnomeglade.Component.__init__(self, paths.ui_dir("preferences.ui"),
+        gnomeglade.Component.__init__(self, "preferences.ui",
                                       "preferencesdialog",
                                       ["adjustment1", "adjustment2", "fileorderstore"])
         self.widget.set_transient_for(parent)
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index 3549977..861a08f 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -20,7 +20,6 @@ import gtk
 import re
 
 from meld import misc
-from meld import paths
 from . import gnomeglade
 
 from gettext import gettext as _
@@ -28,8 +27,8 @@ from gettext import gettext as _
 
 class FindBar(gnomeglade.Component):
     def __init__(self, parent):
-        gnomeglade.Component.__init__(self, paths.ui_dir("findbar.ui"),
-                                      "findbar", ["arrow_left", "arrow_right"])
+        gnomeglade.Component.__init__(self, "findbar.ui", "findbar",
+                                      ["arrow_left", "arrow_right"])
         self.textview = None
         self.orig_base_color = self.find_entry.get_style().base[0]
         self.arrow_left.show()
diff --git a/meld/ui/gnomeglade.py b/meld/ui/gnomeglade.py
index 4be95ac..df006e6 100644
--- a/meld/ui/gnomeglade.py
+++ b/meld/ui/gnomeglade.py
@@ -16,14 +16,21 @@
 ### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 ### USA.
 
+import os
+
 import gtk
 
+import meld.paths
+
 # 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)
+
 
 class Component(object):
     """Base class for all gtk.Builder created objects
@@ -41,6 +48,7 @@ class Component(object):
         self.builder = gtk.Builder()
         self.builder.set_translation_domain(locale_domain)
         objects = [root] + extra if extra else [root]
+        filename = ui_file(filename)
         self.builder.add_objects_from_file(filename, objects)
         self.builder.connect_signals(self)
         self.widget = getattr(self, root)
diff --git a/meld/ui/listwidget.py b/meld/ui/listwidget.py
index b20075b..a1c9c27 100644
--- a/meld/ui/listwidget.py
+++ b/meld/ui/listwidget.py
@@ -17,14 +17,13 @@
 ### USA.
 
 
-from meld import paths
 from . import gnomeglade
 
 
 class ListWidget(gnomeglade.Component):
 
     def __init__(self, ui_file, widget, store, treeview, new_row_data=None):
-        gnomeglade.Component.__init__(self, paths.ui_dir(ui_file),
+        gnomeglade.Component.__init__(self, ui_file,
                                       widget, store)
         self.new_row_data = new_row_data
         self.list = getattr(self, treeview)
diff --git a/meld/ui/vcdialogs.py b/meld/ui/vcdialogs.py
index ae85521..567c3b9 100644
--- a/meld/ui/vcdialogs.py
+++ b/meld/ui/vcdialogs.py
@@ -26,7 +26,6 @@ import gtk
 import pango
 
 from meld import misc
-from meld import paths
 from . import gnomeglade
 
 
@@ -42,8 +41,7 @@ def _commonprefix(files):
 class CommitDialog(gnomeglade.Component):
 
     def __init__(self, parent):
-        gnomeglade.Component.__init__(self, paths.ui_dir("vcview.ui"),
-                                      "commitdialog")
+        gnomeglade.Component.__init__(self, "vcview.ui", "commitdialog")
         self.parent = parent
         self.widget.set_transient_for(parent.widget.get_toplevel())
         selected = parent._get_selected_files()
@@ -111,8 +109,7 @@ class CommitDialog(gnomeglade.Component):
 class PushDialog(gnomeglade.Component):
 
     def __init__(self, parent):
-        gnomeglade.Component.__init__(self, paths.ui_dir("vcview.ui"),
-                                      "pushdialog")
+        gnomeglade.Component.__init__(self, "vcview.ui", "pushdialog")
         self.parent = parent
         self.widget.set_transient_for(parent.widget.get_toplevel())
         self.widget.show_all()
diff --git a/meld/vcview.py b/meld/vcview.py
index 84ccc2c..043a181 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -32,7 +32,6 @@ import pango
 
 from . import melddoc
 from . import misc
-from . import paths
 from . import recent
 from . import tree
 from . import vc
@@ -154,10 +153,10 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
 
     def __init__(self, prefs):
         melddoc.MeldDoc.__init__(self, prefs)
-        gnomeglade.Component.__init__(self, paths.ui_dir("vcview.ui"),
-                                      "vcview", ["VcviewActions", 'liststore_vcs'])
+        gnomeglade.Component.__init__(self, "vcview.ui", "vcview",
+                                      ["VcviewActions", 'liststore_vcs'])
 
-        self.ui_file = paths.ui_dir("vcview-ui.xml")
+        self.ui_file = gnomeglade.ui_file("vcview-ui.xml")
         self.actiongroup = self.VcviewActions
         self.actiongroup.set_translation_domain("meld")
         self.model = VcTreeStore()


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