création d'un dispatcher d'événement central.
[minwii.git] / src / app / widgets / cursors.py
index 6d81a67..b52bfb3 100755 (executable)
@@ -8,9 +8,12 @@ $URL$
 
 import pygame
 import os
+from eventutils import EventHandlerMixin, event_handler
+from itertools import cycle
+from pygame.locals import USEREVENT
+TIMEOUT = USEREVENT + 1
 
-
-class WarpingCursor(pygame.sprite.Sprite):
+class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin):
     '''
     The class for animating the warping cursor
         
@@ -63,6 +66,7 @@ class WarpingCursor(pygame.sprite.Sprite):
         
         surface = pygame.display.get_surface()
         surface.blit(self.image, self.rect)
+        self._startBlink()
         
         #self.flashImagePath = flashImage
         #self.durations = durations
@@ -73,6 +77,20 @@ class WarpingCursor(pygame.sprite.Sprite):
         #self._imagePointer = 0
         #self._animationOffset = 0
         #self._flashTimer = 0
+    
+    def _startBlink(self) :
+        pygame.time.set_timer(TIMEOUT, self.duration)
+        self.iterator = self.iterImages()
+    
+    def iterImages(self) :
+        for img in cycle(self.images) :
+            yield img
+    
+    @event_handler(TIMEOUT)
+    def loadNext(self, event) :
+        self.image = self.iterator.next()
+        surface = pygame.display.get_surface()
+        surface.blit(self.image, self.rect)
 
     def update(self) :
         print 'cursor update'