3 Helper module to get easy access to the path where resources are stored.
4 This is because the resource location is depended on the packaging method and OS
6 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
14 if sys.platform.startswith('darwin'):
16 #Foundation import can crash on some MacOS installs
17 from Foundation import *
21 if sys.platform.startswith('darwin'):
22 if hasattr(sys, 'frozen'):
24 resourceBasePath = NSBundle.mainBundle().resourcePath()
26 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
28 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
30 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
32 def getPathForResource(dir, subdir, resource_name):
33 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
34 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
35 assert os.path.isfile(path), "{p} is not a file.".format(p=path)
38 def getPathForImage(name):
39 return getPathForResource(resourceBasePath, 'images', name)
41 def getPathForMesh(name):
42 return getPathForResource(resourceBasePath, 'meshes', name)
44 def getPathForFirmware(name):
45 return getPathForResource(resourceBasePath, 'firmware', name)
47 def getDefaultMachineProfiles():
48 path = os.path.normpath(os.path.join(resourceBasePath, 'machine_profiles', '*.ini'))
49 return glob.glob(path)
51 def setupLocalization(selectedLanguage = None):
55 if selectedLanguage is not None:
56 for item in getLanguageOptions():
57 if item[1] == selectedLanguage and item[0] is not None:
60 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
61 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
62 translation.install(unicode=True)
64 def getLanguageOptions():
70 # ['nl', 'Nederlands'],