changeset 758:f4853f817a7a pyntnclick

Refactor scene listing, to avoid having to create a window
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 26 Jan 2013 12:56:21 +0200
parents 8ac05c038e73
children 386475464202
files pyntnclick/main.py pyntnclick/tools/utils.py
diffstat 2 files changed, 12 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/main.py	Sat Jan 26 12:30:17 2013 +0200
+++ b/pyntnclick/main.py	Sat Jan 26 12:56:21 2013 +0200
@@ -130,11 +130,7 @@
                 self._initial_scene = opts.scene
             self._debug_rects = opts.rects
         if self.constants.debug and opts.list_scenes:
-            # FIXME: Horrible hack to avoid image loading issues for
-            # now
-            pygame.display.set_mode(self.constants.screen,
-                                              SWSURFACE)
-            list_scenes(self.initial_state)
+            list_scenes(self.SCENE_MODULE, self._scene_list)
             sys.exit(0)
         if self.constants.debug and opts.rect_drawer:
             if opts.scene is None:
--- a/pyntnclick/tools/utils.py	Sat Jan 26 12:30:17 2013 +0200
+++ b/pyntnclick/tools/utils.py	Sat Jan 26 12:56:21 2013 +0200
@@ -1,15 +1,18 @@
 # Misc utils I don't know where else to put
 
 
-def list_scenes(get_initial_state):
+def list_scenes(scene_module, scene_list):
     """List the scenes in the state"""
-    state = get_initial_state()
-    print 'Available scenes are : '
-    for scene in state.scenes:
-        print '    ', scene
-    print 'Available details are : '
-    for detail in state.detail_views:
-        print '    ', detail
+    print "Available scenes and details:"
+    for scene in scene_list:
+        scenemod = __import__('%s.%s' % (scene_module, scene),
+                         fromlist=[scene])
+        if scenemod.SCENES:
+            print " * %s" % scene
+        else:
+            print " * %s (details only)" % scene
+        for detailcls in getattr(scenemod, 'DETAIL_VIEWS', []):
+            print "   - %s" % detailcls.NAME
 
 
 def draw_rect_image(surface, color, rect, thickness):