changeset 580:27809609eeca pyntnclick

Allow different image basedir.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 11 Feb 2012 16:22:56 +0200
parents 071a93441995
children 7e4a20eb78b8
files pyntnclick/main.py pyntnclick/resources.py pyntnclick/tests/test_resources.py
diffstat 3 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/main.py	Sat Feb 11 16:21:20 2012 +0200
+++ b/pyntnclick/main.py	Sat Feb 11 16:22:56 2012 +0200
@@ -104,9 +104,8 @@
             self._debug_rects = opts.rects
         display = pygame.display.set_mode(self.constants.screen,
                                           SWSURFACE)
-        pygame.display.set_icon(pygame.image.load(
-            self.resource.get_resource_path('icons/suspended_sentence24x24'
-                                            '.png')))
+        pygame.display.set_icon(self.resource.load_image(
+                'suspended_sentence24x24.png', basedir='icons'))
         pygame.display.set_caption("Suspended Sentence")
         shell = MainShell(display, self.initial_state,
                           self.constants.frame_rate)
--- a/pyntnclick/resources.py	Sat Feb 11 16:21:20 2012 +0200
+++ b/pyntnclick/resources.py	Sat Feb 11 16:22:56 2012 +0200
@@ -36,8 +36,8 @@
             paths.append(resource_filename(module, resource_path))
         return paths
 
-    def load_image(self, image_name, mutators=()):
-        image_path = self.get_resource_path('images', image_name)
+    def load_image(self, image_name, mutators=(), basedir='images'):
+        image_path = self.get_resource_path(basedir, image_name)
 
         if image_path not in self._image_cache:
             image = pygame.image.load(image_path)
--- a/pyntnclick/tests/test_resources.py	Sat Feb 11 16:21:20 2012 +0200
+++ b/pyntnclick/tests/test_resources.py	Sat Feb 11 16:22:56 2012 +0200
@@ -51,3 +51,14 @@
     def test_load_image(self):
         image = self.res.load_image('pyntnclick/hand.png')
         self.assertTrue(isinstance(image, Surface))
+
+    def test_load_image_different_basedir(self):
+        image = self.res.load_image('hand.png', basedir='images/pyntnclick')
+        self.assertTrue(isinstance(image, Surface))
+
+    def test_load_missing(self):
+        try:
+            self.res.load_image('should_not_exist')
+            self.fail('Expected ResourceNotFound error.')
+        except ResourceNotFound, e:
+            self.assertEqual('images/should_not_exist', e.args[0])