chiark / gitweb /
Move resources in to their own subdirectory and update the code that uses the resources.
[cura.git] / Cura / util / resources.py
1 # coding=utf-8
2 from __future__ import absolute_import
3 import os
4 import sys
5
6 __all__ = ['getPathForResource', 'getPathForImage', 'getPathForMesh']
7
8
9 if sys.platform.startswith('darwin'):
10         if hasattr(sys, 'frozen'):
11                 from Foundation import *
12                 resourceBasePath = NSBundle.mainBundle().resourcePath()
13         else:
14                 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
15 else:
16         if hasattr(sys, 'frozen'):
17                 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
18         else:
19                 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
20
21 def getPathForResource(dir, subdir, resource_name):
22         assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
23         path = os.path.normpath(os.path.join(dir, subdir, resource_name))
24         assert os.path.isfile(path), "{p} is not a file.".format(p=path)
25         return path
26
27 def getPathForImage(name):
28         return getPathForResource(resourceBasePath, 'images', name)
29
30 def getPathForMesh(name):
31         return getPathForResource(resourceBasePath, 'meshes', name)
32
33 def getPathForFirmware(name):
34         return getPathForResource(resourceBasePath, 'firmware', name)