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 getSimpleModeProfiles():
55 path = os.path.normpath(os.path.join(resourceBasePath, 'quickprint', 'profiles', '*.ini'))
56 user_path = os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', 'profiles')))
57 if os.path.isdir(user_path):
58 return sorted(glob.glob(user_path))
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 return sorted(glob.glob(user_path))
66 return sorted(glob.glob(path))
68 def setupLocalization(selectedLanguage = None):
72 if selectedLanguage is not None:
73 for item in getLanguageOptions():
74 if item[1] == selectedLanguage and item[0] is not None:
77 if languages[0] == 'AUTO':
79 defaultLocale = getDefaultLocale()
80 if defaultLocale is not None:
81 for item in getLanguageOptions():
84 if item[0] is not None and defaultLocale.startswith(item[0]):
87 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
88 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
89 #translation.ugettext = lambda message: u'#' + message
90 translation.install(unicode=True)
92 def getLanguageOptions():
94 ['AUTO', 'Autodetect'],
101 # ['nl', 'Nederlands'],
106 def getDefaultLocale():
109 # On Windows, we look for the actual UI language, as someone could have
110 # an english windows but use a non-english locale.
111 if platform.system() == "Windows":
115 windll = ctypes.windll.kernel32
116 defaultLocale = locale.windows_locale[windll.GetUserDefaultUILanguage()]
120 if defaultLocale is None:
122 defaultLocale = locale.getdefaultlocale()[0]