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"
16 if sys.platform.startswith('darwin'):
18 #Foundation import can crash on some MacOS installs
19 from Foundation import *
23 if sys.platform.startswith('darwin'):
24 if hasattr(sys, 'frozen'):
26 resourceBasePath = NSBundle.mainBundle().resourcePath()
28 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
30 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
32 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
34 def getPathForResource(dir, subdir, resource_name):
35 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
36 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
37 if not os.path.isfile(path):
41 def getPathForImage(name):
42 return getPathForResource(resourceBasePath, 'images', name)
44 def getPathForMesh(name):
45 return getPathForResource(resourceBasePath, 'meshes', name)
47 def getPathForFirmware(name):
48 return getPathForResource(resourceBasePath, 'firmware', name)
50 def getDefaultMachineProfiles():
51 path = os.path.normpath(os.path.join(resourceBasePath, 'machine_profiles', '*.ini'))
52 return glob.glob(path)
54 def setupLocalization(selectedLanguage = None):
58 if selectedLanguage is not None:
59 for item in getLanguageOptions():
60 if item[1] == selectedLanguage and item[0] is not None:
63 if languages[0] == 'AUTO':
65 defaultLocale = getDefaultLocale()
66 if defaultLocale is not None:
67 for item in getLanguageOptions():
70 if item[0] is not None and defaultLocale.startswith(item[0]):
73 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
74 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
75 #translation.ugettext = lambda message: u'#' + message
76 translation.install(unicode=True)
78 def getLanguageOptions():
80 ['AUTO', 'Autodetect'],
87 # ['nl', 'Nederlands'],
92 def getDefaultLocale():
95 # On Windows, we look for the actual UI language, as someone could have
96 # an english windows but use a non-english locale.
97 if platform.system() == "Windows":
101 windll = ctypes.windll.kernel32
102 defaultLocale = locale.windows_locale[windll.GetUserDefaultUILanguage()]
106 if defaultLocale is None:
108 defaultLocale = locale.getdefaultlocale()[0]