comparison pyntnclick/resources.py @ 625:85153f422522 pyntnclick

Differently yuck get_image().
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 11 Feb 2012 22:00:50 +0200
parents 38f75cef86d0
children d1ec9e739e23
comparison
equal deleted inserted replaced
624:1c5ef1e02e30 625:85153f422522
56 fn = os.path.join(self.language, resource_path) 56 fn = os.path.join(self.language, resource_path)
57 paths.append(resource_filename(module, fn)) 57 paths.append(resource_filename(module, fn))
58 paths.append(resource_filename(module, resource_path)) 58 paths.append(resource_filename(module, resource_path))
59 return paths 59 return paths
60 60
61 def get_image(self, image_name_fragments, transforms=(), basedir='images'): 61 def get_image(self, *image_name_fragments, **kw):
62 """Load an image and optionally apply mutators. 62 """Load an image and optionally apply mutators.
63 63
64 The `image_name_fragments` parameter may be either a string or a list 64 All positional params end up in `image_name_fragments` and are joined
65 of strings. The latter is a convenience for things that compose an 65 with the path separator.
66 image name out of several fragments.
67 66
68 The `transforms` param may contain transforms, which modify an image 67 Two keyword parameters are also accepted:
69 in-place to apply various effects.
70 68
71 The `basedir` param defaults to 'images', but may be overriden to load 69 * `transforms` may contain transforms, which modify an image in-place
72 images from other places. ('icons', for example.) 70 to apply various effects.
71
72 * `basedir` defaults to 'images', but may be overridden to load images
73 from other places. ('icons', for example.)
73 """ 74 """
74 75
75 # Juggle our various params and find an appropriate image path. 76 transforms = kw.get('transforms', ())
76 if isinstance(image_name_fragments, basestring): 77 basedir = kw.get('basedir', 'images')
77 image_name_fragments = [image_name_fragments] 78
78 image_path = self.get_resource_path(basedir, *image_name_fragments) 79 image_path = self.get_resource_path(basedir, *image_name_fragments)
79 80
80 key = (image_path, transforms) 81 key = (image_path, transforms)
81 if key in self._transformed_image_cache: 82 if key in self._transformed_image_cache:
82 # We already have this cached, so shortcut the whole process. 83 # We already have this cached, so shortcut the whole process.