2 Helper module to get easy access to the path where resources are stored.
3 This is because the resource location is depended on the packaging method and OS
5 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
11 #Cura/util classes should not depend on wx...
15 if sys.platform.startswith('darwin'):
17 #Foundation import can crash on some MacOS installs
18 from Foundation import *
22 if sys.platform.startswith('darwin'):
23 if hasattr(sys, 'frozen'):
25 resourceBasePath = NSBundle.mainBundle().resourcePath()
27 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
29 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
31 if hasattr(sys, 'frozen'):
32 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
34 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
36 def getPathForResource(dir, subdir, resource_name):
37 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
38 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
39 assert os.path.isfile(path), "{p} is not a file.".format(p=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 setupLocalization(selectedLanguage = None):
57 if sys.platform.startswith('darwin'):
58 languages = NSLocale.preferredLanguages()
60 #Using wx.Locale before you created wx.App seems to cause an nasty exception. So default to 'en' at the moment.
61 languages = [wx.Locale(wx.LANGUAGE_DEFAULT).GetCanonicalName()]
62 except Exception as e:
65 if selectedLanguage is not None:
66 for item in getLanguageOptions():
67 if item[1] == selectedLanguage and item[0] is not None:
70 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
71 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
72 translation.install(unicode=True)
74 def getLanguageOptions():
76 # [None, 'System default'],
80 # ['nl', 'Nederlands'],