From bec2ec415aed83414e07d3b115464bbdc0e5fb76 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Sun, 29 Mar 2015 17:57:04 +0200 Subject: [PATCH] Check first if ui file exists at specified path before falling back to global dir. This allows load_ui to be used by custom tools built by users. --- glue/qt/qtutil.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/glue/qt/qtutil.py b/glue/qt/qtutil.py index 841f58f1a..f886b8f9f 100644 --- a/glue/qt/qtutil.py +++ b/glue/qt/qtutil.py @@ -725,9 +725,12 @@ def _load_ui_pyqt4(path, parent): return loadUi(path, parent) -def load_ui(name, parent=None): +def load_ui(path, parent=None): """ - Load a UI file, given it's name + Load a UI file, given its name. + + This will first check if `path` exists, and if not it will assume it is the + name of a ui file to search for in the global glue ui directory. Parameters ---------- @@ -742,14 +745,19 @@ def load_ui(name, parent=None): w : QWidget The new widget """ - path = ui_path(name) + + if not os.path.exists(path): + path = global_ui_path(path) + if is_pyside(): return _load_ui_pyside(path, parent) - return _load_ui_pyqt4(path, parent) + else: + return _load_ui_pyqt4(path, parent) -def ui_path(ui_name): - """Return the absolute path to a .ui file +def global_ui_path(ui_name): + """ + Return the absolute path to a .ui file bundled with glue. Parameters ----------