1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
7 #Cura/util classes should not depend on wx...
11 if sys.platform.startswith('darwin'):
13 #Foundation import can crash on some MacOS installs
14 from Foundation import *
18 if sys.platform.startswith('darwin'):
19 if hasattr(sys, 'frozen'):
21 resourceBasePath = NSBundle.mainBundle().resourcePath()
23 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
25 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
27 if hasattr(sys, 'frozen'):
28 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
30 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
32 def getPathForResource(dir, subdir, resource_name):
33 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
34 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
35 assert os.path.isfile(path), "{p} is not a file.".format(p=path)
38 def getPathForImage(name):
39 return getPathForResource(resourceBasePath, 'images', name)
41 def getPathForMesh(name):
42 return getPathForResource(resourceBasePath, 'meshes', name)
44 def getPathForFirmware(name):
45 return getPathForResource(resourceBasePath, 'firmware', name)
47 def setupLocalization():
49 if sys.platform.startswith('darwin'):
50 languages = NSLocale.preferredLanguages()
52 #Using wx.Locale before you created wx.App seems to cause an nasty exception. So default to 'en' at the moment.
53 languages = [wx.Locale(wx.LANGUAGE_DEFAULT).GetCanonicalName()]
54 except Exception as e:
57 locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
58 translation = gettext.translation('Cura', locale_path, languages, fallback=True)
59 translation.install(unicode=True)