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 getSimpleModeProfiles():
53 path = os.path.normpath(os.path.join(resourceBasePath, 'quickprint', 'profiles', '*.ini'))
54 user_path = os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', 'profiles')))
55 if os.path.isdir(user_path):
56 files = sorted(glob.glob(os.path.join(user_path, '*.ini')))
59 return sorted(glob.glob(path))
61 def getSimpleModeMaterials():
62 path = os.path.normpath(os.path.join(resourceBasePath, 'quickprint', 'materials', '*.ini'))
63 user_path = os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', 'materials')))
64 if os.path.isdir(user_path):
65 files = sorted(glob.glob(os.path.join(user_path, '*.ini')))
68 return sorted(glob.glob(path))
70 def setupLocalization(selectedLanguage = None):
74 if selectedLanguage is not None:
75 for item in getLanguageOptions():
76 if item[1] == selectedLanguage and item[0] is not None:
79 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
80 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
81 #translation.ugettext = lambda message: u'#' + message
82 translation.install(unicode=True)
84 def getLanguageOptions():
93 # ['nl', 'Nederlands'],