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"
17 if sys.platform.startswith('darwin'):
19 #Foundation import can crash on some MacOS installs
20 from Foundation import *
24 if sys.platform.startswith('darwin'):
25 if hasattr(sys, 'frozen'):
27 resourceBasePath = NSBundle.mainBundle().resourcePath()
29 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
31 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
33 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
35 def getPathForResource(dir, subdir, resource_name):
36 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
37 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
38 if not os.path.isfile(path):
42 def getPathForImage(name):
43 return getPathForResource(resourceBasePath, 'images', name)
45 def getPathForMesh(name):
46 return getPathForResource(resourceBasePath, 'meshes', name)
48 def getPathForFirmware(name):
49 return getPathForResource(resourceBasePath, 'firmware', name)
51 def getDefaultMachineProfiles():
52 path = os.path.normpath(os.path.join(resourceBasePath, 'machine_profiles', '*.ini'))
53 return glob.glob(path)
55 def getSimpleModeIniFiles(subdir, pattern = '*.ini'):
56 machine_type = profile.getMachineSetting('machine_type')
58 paths.append(os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', machine_type, subdir))))
59 paths.append(os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', subdir))))
60 paths.append(os.path.normpath(os.path.join(resourceBasePath, 'quickprint', machine_type, subdir)))
61 paths.append(os.path.normpath(os.path.join(resourceBasePath, 'quickprint', subdir)))
63 if os.path.isdir(path):
64 files = sorted(glob.glob(os.path.join(path, pattern)))
70 def getSimpleModeProfiles():
71 return getSimpleModeIniFiles('profiles')
73 def getSimpleModeMaterials():
74 return getSimpleModeIniFiles('materials')
76 def getSimpleModeOptions():
77 return getSimpleModeIniFiles('options')
79 def setupLocalization(selectedLanguage = None):
83 if selectedLanguage is not None:
84 for item in getLanguageOptions():
85 if item[1] == selectedLanguage and item[0] is not None:
88 if languages[0] == 'AUTO':
90 defaultLocale = getDefaultLocale()
91 if defaultLocale is not None:
92 for item in getLanguageOptions():
95 if item[0] is not None and defaultLocale.startswith(item[0]):
98 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
99 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
100 #translation.ugettext = lambda message: u'#' + message
101 translation.install(unicode=True)
103 def getLanguageOptions():
105 ['AUTO', 'Autodetect'],
112 # ['nl', 'Nederlands'],
117 def getDefaultLocale():
120 # On Windows, we look for the actual UI language, as someone could have
121 # an english windows but use a non-english locale.
122 if platform.system() == "Windows":
126 windll = ctypes.windll.kernel32
127 defaultLocale = locale.windows_locale[windll.GetUserDefaultUILanguage()]
131 if defaultLocale is None:
133 defaultLocale = locale.getdefaultlocale()[0]