changeset 648:b2c2b6f56291 pyntnclick

baby steps to fixing rect_drawer - it has now progressed to being completely useless
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 12 Feb 2012 12:28:27 +0200
parents 96daa4119745
children e59b119bb0f9
files pyntnclick/main.py pyntnclick/tools/rect_drawer.py
diffstat 2 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/main.py	Sun Feb 12 12:13:08 2012 +0200
+++ b/pyntnclick/main.py	Sun Feb 12 12:28:27 2012 +0200
@@ -22,7 +22,7 @@
 from pyntnclick.sound import Sound
 from pyntnclick import state
 
-from pyntnclick.tools.rect_drawer import RectApp, make_rect_display
+from pyntnclick.tools.rect_drawer import RectEngine, make_rect_display
 from pyntnclick.tools.utils import list_scenes
 
 
@@ -144,7 +144,7 @@
             display = make_rect_display()
             # FIXME: Remove Albow from here
             try:
-                self.engine = RectApp(display, self.initial_state, opts.scene,
+                self.engine = RectEngine(self, self.initial_state, opts.scene,
                         opts.detail)
             except KeyError:
                 print 'Invalid scene: %s' % opts.scene
--- a/pyntnclick/tools/rect_drawer.py	Sun Feb 12 12:13:08 2012 +0200
+++ b/pyntnclick/tools/rect_drawer.py	Sun Feb 12 12:28:27 2012 +0200
@@ -23,13 +23,14 @@
 
 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN,
                            K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z,
-                           BLEND_RGBA_MIN, SRCALPHA)
+                           BLEND_RGBA_MIN, SRCALPHA, QUIT)
 import pygame
 
 import pyntnclick.constants
 from pyntnclick import state
 state.DEBUG_RECTS = True
 from pyntnclick.widgets import BoomLabel
+from pyntnclick.widgets.base import Container
 
 
 class RectDrawerConstants(pyntnclick.constants.GameConstants):
@@ -554,7 +555,38 @@
     return button
 
 
-class RectApp(RootWidget):
+class RectApp(Container):
+    """The actual rect drawer main app"""
+    def __init__(self, rect, gd):
+        super(RectApp, self).__init__(rect, gd)
+
+
+class RectEngine(object):
+    """Engine for the rect drawer."""
+
+    def __init__(self, gd, get_initial_state, scene, detail):
+        self.state = None
+        self._gd = gd
+        rect = pygame.display.get_surface().get_rect()
+        self.app = RectApp(rect, self._gd)
+
+    def run(self):
+        """App loop"""
+        clock = pygame.time.Clock()
+        while True:
+            events = pygame.event.get()
+            for ev in events:
+                if ev.type == QUIT:
+                    return
+                else:
+                    self.app.event(ev)
+            surface = pygame.display.get_surface()
+            self.app.draw(surface)
+            pygame.display.flip()
+            clock.tick(self._gd.constants.frame_rate)
+
+
+class RectAppOld(RootWidget):
     """Handle the app stuff for the rect drawer"""
 
     def __init__(self, display, get_initial_state, scene, detail):