resourcePath finds stuff relative to parent dir of mcedit2 module (src/), not current dir

allows mcedit2 script to run from any dir in source installs
This commit is contained in:
David Vierra 2015-01-06 18:58:06 -10:00
parent e0438afbcb
commit a83977da99
2 changed files with 8 additions and 9 deletions

View File

@ -78,7 +78,7 @@ class MCEditApp(QtGui.QApplication):
# --- Necessities --- # --- Necessities ---
translator = QtCore.QTranslator() translator = QtCore.QTranslator()
translator.load('i18n/en_US') translator.load(resourcePath('mcedit2/i18n/en_US.ts'))
self.installTranslator(translator) self.installTranslator(translator)
self.setOrganizationName("MCEdit") self.setOrganizationName("MCEdit")

View File

@ -11,14 +11,13 @@ log = logging.getLogger(__name__)
def resourcePath(filename): def resourcePath(filename):
filename = filename.replace('/', os.path.sep) filename = filename.replace('/', os.path.sep)
path = os.path.join( basedir = getattr(sys, "_MEIPASS", None) # if pyinstaller'd
getattr( if basedir is None:
sys, import mcedit2
"_MEIPASS", # if pyinstaller'd mod = mcedit2.__file__
os.path.abspath("src") # if running from source basedir = os.path.dirname(mod) + "/.."
), basedir = os.path.normpath(basedir)
filename path = os.path.join(basedir, filename)
)
if not os.path.exists(path): if not os.path.exists(path):
raise RuntimeError("Could not get resource path for %s\n(Tried %s which does not exist)" % (filename, path)) raise RuntimeError("Could not get resource path for %s\n(Tried %s which does not exist)" % (filename, path))