# HG changeset patch # User Jeremy Thurgood # Date 1328970176 -7200 # Node ID 27809609eeca8ea578263104d1d1d2805f994e94 # Parent 071a934419950b6960c9aa4efadd277f88f89b2c Allow different image basedir. diff -r 071a93441995 -r 27809609eeca pyntnclick/main.py --- 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) diff -r 071a93441995 -r 27809609eeca pyntnclick/resources.py --- 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) diff -r 071a93441995 -r 27809609eeca pyntnclick/tests/test_resources.py --- 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])