diff --git a/gooey/__init__.py b/gooey/__init__.py index b0d3d41..7321da3 100644 --- a/gooey/__init__.py +++ b/gooey/__init__.py @@ -1,5 +1,5 @@ import os from gooey.python_bindings.gooey_decorator import Gooey from gooey.python_bindings.gooey_parser import GooeyParser - +from gooey.gui.util.freeze import localResourcePath as local_resource_path __version__ = '1.0.3' diff --git a/gooey/gui/util/freeze.py b/gooey/gui/util/freeze.py index a755aa3..d3a84f4 100644 --- a/gooey/gui/util/freeze.py +++ b/gooey/gui/util/freeze.py @@ -1,3 +1,9 @@ +''' +Utils for retrieving resources when when in a frozen state. + +MEIPASS explanation: +https://pythonhosted.org/PyInstaller/#run-time-operation +''' import os import sys @@ -26,3 +32,17 @@ def getResourcePath(*args): resource_dir = os.path.normpath( os.path.join(os.path.dirname(__file__), '..', '..')) return os.path.join(resource_dir, *args) + + +def localResourcePath(path): + """ + A packaging aware util for getting the path to the local working directory. + When non-packaged, this is os.getcwd(), when packaged, it will be the local + (dynamic) directory where PyInstaller decompresses content. + """ + if is_frozen(): + basedir = getattr(sys, '_MEIPASS', None) + return os.path.join(basedir or sys.executable, path) + else: + return os.path.join(os.getcwd(), path) + \ No newline at end of file