[meld] Move ui_file helper to meld.conf to avoid circular imports



commit 72a99195c137c7161e9105fb5033b518a022a10b
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Jan 15 08:01:51 2015 +1000

    Move ui_file helper to meld.conf to avoid circular imports
    
    We could easily get circular imports in ui.util because it imports all
    glade-constructable widgets so that it can construct them.

 meld/conf.py          |    4 ++++
 meld/ui/gnomeglade.py |    7 ++-----
 meld/ui/util.py       |   12 ++++--------
 3 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/meld/conf.py b/meld/conf.py
index cb93c4b..04dc7dd 100644
--- a/meld/conf.py
+++ b/meld/conf.py
@@ -49,3 +49,7 @@ def uninstalled():
     data_dir = os.environ.get('XDG_DATA_DIRS', "/usr/local/share/:/usr/share/")
     data_dir = ":".join((melddir, data_dir))
     os.environ['XDG_DATA_DIRS'] = data_dir
+
+
+def ui_file(filename):
+    return os.path.join(DATADIR, "ui", filename)
diff --git a/meld/ui/gnomeglade.py b/meld/ui/gnomeglade.py
index cd55fe7..be093c8 100644
--- a/meld/ui/gnomeglade.py
+++ b/meld/ui/gnomeglade.py
@@ -14,15 +14,12 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
-
 from gi.repository import Gtk
 
 import meld.conf
 
-
-def ui_file(filename):
-    return os.path.join(meld.conf.DATADIR, "ui", filename)
+# For backwards compat
+ui_file = meld.conf.ui_file
 
 
 class Component(object):
diff --git a/meld/ui/util.py b/meld/ui/util.py
index 42e5bae..7c5d127 100644
--- a/meld/ui/util.py
+++ b/meld/ui/util.py
@@ -13,8 +13,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
-
 from gi.repository import Gtk
 
 import meld.conf
@@ -23,19 +21,17 @@ import meld.conf
 from meld.ui import gladesupport
 
 
-def ui_file(filename):
-    return os.path.join(meld.conf.DATADIR, "ui", filename)
-
-
 def get_widget(filename, widget):
     builder = Gtk.Builder()
     builder.set_translation_domain(meld.conf.__package__)
-    builder.add_objects_from_file(ui_file(filename), [widget])
+    path = meld.conf.ui_file(filename)
+    builder.add_objects_from_file(path, [widget])
     return builder.get_object(widget)
 
 
 def get_builder(filename):
     builder = Gtk.Builder()
     builder.set_translation_domain(meld.conf.__package__)
-    builder.add_from_file(ui_file(filename))
+    path = meld.conf.ui_file(filename)
+    builder.add_from_file(path)
     return builder


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