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 if not os.path.isfile(path):
39 def getPathForImage(name):
40 return getPathForResource(resourceBasePath, 'images', name)
42 def getPathForMesh(name):
43 return getPathForResource(resourceBasePath, 'meshes', name)
45 def getPathForFirmware(name):
46 return getPathForResource(resourceBasePath, 'firmware', name)
48 def getDefaultMachineProfiles():
49 path = os.path.normpath(os.path.join(resourceBasePath, 'machine_profiles', '*.ini'))
50 return glob.glob(path)
52 def setupLocalization(selectedLanguage = None):
56 if selectedLanguage is not None:
57 for item in getLanguageOptions():
58 if item[1] == selectedLanguage and item[0] is not None:
61 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
62 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
63 #translation.ugettext = lambda message: u'#' + message
64 translation.install(unicode=True)
66 def getLanguageOptions():
74 # ['nl', 'Nederlands'],