1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
8 #Cura/util classes should not depend on wx...
12 if sys.platform.startswith('darwin'):
14 #Foundation import can crash on some MacOS installs
15 from Foundation import *
19 if sys.platform.startswith('darwin'):
20 if hasattr(sys, 'frozen'):
22 resourceBasePath = NSBundle.mainBundle().resourcePath()
24 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
26 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
28 if hasattr(sys, 'frozen'):
29 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
31 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
33 def getPathForResource(dir, subdir, resource_name):
34 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
35 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
36 assert os.path.isfile(path), "{p} is not a file.".format(p=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 setupLocalization(selectedLanguage = None):
54 if sys.platform.startswith('darwin'):
55 languages = NSLocale.preferredLanguages()
57 #Using wx.Locale before you created wx.App seems to cause an nasty exception. So default to 'en' at the moment.
58 languages = [wx.Locale(wx.LANGUAGE_DEFAULT).GetCanonicalName()]
59 except Exception as e:
62 if selectedLanguage is not None:
63 for item in getLanguageOptions():
64 if item[1] == selectedLanguage and item[0] is not None:
67 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
68 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
69 translation.install(unicode=True)
71 def getLanguageOptions():
73 # [None, 'System default'],
77 # ['nl', 'Nederlands'],