chiark / gitweb /
Merge remote-tracking branch 'upstream/master' into macosx
[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                 imagesPath = os.path.join(NSBundle.mainBundle().resourcePath(), 'images')
13                 meshesPath = os.path.join(NSBundle.mainBundle().resourcePath(), 'images')
14         else:
15                 imagesPath = os.path.join(os.path.dirname(__file__), "../images")
16                 meshesPath = os.path.join(os.path.dirname(__file__), "../images")
17 else:
18         if hasattr(sys, 'frozen'):
19                 imagesPath = os.path.join(os.path.dirname(__file__), "../../images")
20                 meshesPath = os.path.join(os.path.dirname(__file__), "../../images")
21         else:
22                 imagesPath = os.path.join(os.path.dirname(__file__), "../images")
23                 meshesPath = os.path.join(os.path.dirname(__file__), "../images")
24
25
26 def getPathForResource(dir, resource_name):
27         assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
28         path = os.path.normpath(os.path.join(dir, resource_name))
29         assert os.path.isfile(path), "{p} is not a file.".format(p=path)
30         return path
31
32 def getPathForImage(name):
33         return getPathForResource(imagesPath, name)
34
35 def getPathForMesh(name):
36         return getPathForResource(meshesPath, name)