chiark / gitweb /
Copyright message needs to be after the __future__ imports.
[cura.git] / Cura / util / resources.py
1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
3
4 import os
5 import sys
6
7 __all__ = ['getPathForResource', 'getPathForImage', 'getPathForMesh']
8
9
10 if sys.platform.startswith('darwin'):
11         if hasattr(sys, 'frozen'):
12                 from Foundation import *
13                 resourceBasePath = NSBundle.mainBundle().resourcePath()
14         else:
15                 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
16 else:
17         if hasattr(sys, 'frozen'):
18                 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
19         else:
20                 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
21
22 def getPathForResource(dir, subdir, resource_name):
23         assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
24         path = os.path.normpath(os.path.join(dir, subdir, resource_name))
25         assert os.path.isfile(path), "{p} is not a file.".format(p=path)
26         return path
27
28 def getPathForImage(name):
29         return getPathForResource(resourceBasePath, 'images', name)
30
31 def getPathForMesh(name):
32         return getPathForResource(resourceBasePath, 'meshes', name)
33
34 def getPathForFirmware(name):
35         return getPathForResource(resourceBasePath, 'firmware', name)