From: pin Date: Tue, 23 Feb 2010 15:42:11 +0000 (+0000) Subject: Ajout de listeners sur les colonnes. X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/a7c9d1fda4c70e7213db409ca66b1555e6539c21?ds=sidebyside Ajout de listeners sur les colonnes. Refection du curseur avec ombrage. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@55 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/eventutils.py b/src/app/eventutils.py index 1741579..a89509b 100755 --- a/src/app/eventutils.py +++ b/src/app/eventutils.py @@ -28,6 +28,7 @@ $URL$ """ import types import pygame +from StringIO import StringIO class _EventDispatcher : def __init__(self) : @@ -45,6 +46,18 @@ class _EventDispatcher : listeners = self.registry.get(event.type, []) for listener in listeners : listener(event) + + def __repr__(self) : + out = StringIO() + keys = self.registry.keys() + keys.sort() + for k in keys : + print >> out, "event", k + for listener in self.registry[k] : + print >> out, listener.__name__ + out.seek(0) + return out.read() + EventDispatcher = _EventDispatcher() @@ -64,8 +77,6 @@ class EventInitializer(type): if isinstance(v, types.FunctionType) and hasattr(v, '__islistener__') : listener = getattr(self, k) EventDispatcher.addEventListener(v.__eventtype__, listener) - del v.__islistener__ - del v.__eventtype__ def ctor(self, *args, **kw) : init_listeners(self) diff --git a/src/app/minwii.py b/src/app/minwii.py index a3292f0..6e29cd9 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -6,15 +6,13 @@ $Id$ $URL$ """ -from pgu.gui import Desktop -from pgu.gui import QUIT +#from pgu.gui import Desktop +#from pgu.gui import QUIT from widgets.home import Home from widgets.playingscreen import _PlayingScreenBase, SongPlayingScreenTest -class MinWii(Desktop): +class MinWii(object): def __init__(self) : - Desktop.__init__(self) - import pygame playingScreen = SongPlayingScreenTest() playingScreen.run() diff --git a/src/app/start.py b/src/app/start.py index 02db7ce..8c7a009 100755 --- a/src/app/start.py +++ b/src/app/start.py @@ -12,8 +12,9 @@ def main() : from minwii import MinWii pygame.init() - modeResolution = (1024,768) - window = pygame.display.set_mode(modeResolution, pygame.FULLSCREEN) + #modeResolution = (1024,768) + modeResolution = (600,480) + window = pygame.display.set_mode(modeResolution)#, pygame.FULLSCREEN) MinWii() # from gui.PGUConfiguration import PGUConfiguration # pygame.init() diff --git a/src/app/widgets/cursors.py b/src/app/widgets/cursors.py index 3ac9c43..863b757 100755 --- a/src/app/widgets/cursors.py +++ b/src/app/widgets/cursors.py @@ -9,9 +9,8 @@ $URL$ import pygame import os from eventutils import EventHandlerMixin, event_handler +from events import TIMEOUT from itertools import cycle -from pygame.locals import USEREVENT -TIMEOUT = USEREVENT + 1 class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): ''' @@ -28,7 +27,7 @@ class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): return basePath, images - def __init__(self, theme='black', duration=75, blink=True): + def __init__(self, theme='black', duration=50, blinkMode=True): pygame.sprite.Sprite.__init__(self) pygame.mouse.set_visible(False) imagesPath, images = WarpingCursor._get_theme_images(theme) @@ -49,15 +48,16 @@ class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): self.duration = duration self.image = self.images[0] - self.rect = pygame.Rect((0,0), (self.width, self.height)) + self.rect = pygame.Rect((-self.width/2,-self.height/2), (self.width, self.height)) - self.blink = blink - if blink : - self._startBlink() + self.blinkMode = blinkMode + self._startBlink() def _startBlink(self) : - pygame.time.set_timer(TIMEOUT, self.duration) - self.iterator = self.iterImages() + if self.blinkMode : + self._blinking = True + pygame.time.set_timer(TIMEOUT, self.duration) + self.iterator = self.iterImages() def iterImages(self) : for img in cycle(self.images) : @@ -65,22 +65,22 @@ class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): @event_handler(TIMEOUT) def loadNext(self, event) : - if self.blink : + if self._blinking : self.image = self.iterator.next() @event_handler(pygame.MOUSEBUTTONDOWN) def flashOn(self, event) : - self.blink=False + self._blinking = False self.image = self.flashImage @event_handler(pygame.MOUSEBUTTONUP) def flashOff(self, event) : - self.blink = True - self.loadNext(event) + if self.blinkMode : + self._blinking = True + self.loadNext(event) + else : + self.image = self.images[0] @event_handler(pygame.MOUSEMOTION) def move(self, event) : - x, y = event.rel - self.rect.centerx += x - self.rect.centery += y - #self.rect.move_ip(*rel) + self.rect.move_ip(event.rel) diff --git a/src/app/widgets/data/black/0.png b/src/app/widgets/data/black/0.png index d676349..526d289 100755 Binary files a/src/app/widgets/data/black/0.png and b/src/app/widgets/data/black/0.png differ diff --git a/src/app/widgets/data/black/1.png b/src/app/widgets/data/black/1.png index 7703e89..b8fce1a 100755 Binary files a/src/app/widgets/data/black/1.png and b/src/app/widgets/data/black/1.png differ diff --git a/src/app/widgets/data/black/10.png b/src/app/widgets/data/black/10.png index 6c85004..099c363 100755 Binary files a/src/app/widgets/data/black/10.png and b/src/app/widgets/data/black/10.png differ diff --git a/src/app/widgets/data/black/2.png b/src/app/widgets/data/black/2.png index 9eec08e..5e58215 100755 Binary files a/src/app/widgets/data/black/2.png and b/src/app/widgets/data/black/2.png differ diff --git a/src/app/widgets/data/black/3.png b/src/app/widgets/data/black/3.png index ce93f45..ada3be9 100755 Binary files a/src/app/widgets/data/black/3.png and b/src/app/widgets/data/black/3.png differ diff --git a/src/app/widgets/data/black/4.png b/src/app/widgets/data/black/4.png index 7c9d191..d3642da 100755 Binary files a/src/app/widgets/data/black/4.png and b/src/app/widgets/data/black/4.png differ diff --git a/src/app/widgets/data/black/5.png b/src/app/widgets/data/black/5.png index 34b149d..0821648 100755 Binary files a/src/app/widgets/data/black/5.png and b/src/app/widgets/data/black/5.png differ diff --git a/src/app/widgets/data/black/6.png b/src/app/widgets/data/black/6.png index d118680..1349fdc 100755 Binary files a/src/app/widgets/data/black/6.png and b/src/app/widgets/data/black/6.png differ diff --git a/src/app/widgets/data/black/7.png b/src/app/widgets/data/black/7.png index 68ec2dd..6ca0d90 100755 Binary files a/src/app/widgets/data/black/7.png and b/src/app/widgets/data/black/7.png differ diff --git a/src/app/widgets/data/black/8.png b/src/app/widgets/data/black/8.png index c938fe9..59b87ce 100755 Binary files a/src/app/widgets/data/black/8.png and b/src/app/widgets/data/black/8.png differ diff --git a/src/app/widgets/data/black/9.png b/src/app/widgets/data/black/9.png index e5e4f09..ea719da 100755 Binary files a/src/app/widgets/data/black/9.png and b/src/app/widgets/data/black/9.png differ diff --git a/src/app/widgets/data/black/flash.png b/src/app/widgets/data/black/flash.png index 412cbce..6dedec2 100644 Binary files a/src/app/widgets/data/black/flash.png and b/src/app/widgets/data/black/flash.png differ diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index 146e549..0c5e2a4 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -80,7 +80,7 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates, EventHandlerMixin) : self.add(c) def _initCursor(self) : - self.cursor = WarpingCursor() + self.cursor = WarpingCursor(blinkMode=True) self.add(self.cursor) @@ -129,7 +129,7 @@ class SongPlayingScreenTest(_PlayingScreenBase) : super(SongPlayingScreenTest, self).__init__([o]) -class Column(pygame.sprite.Sprite) : +class Column(pygame.sprite.Sprite, EventHandlerMixin) : def __init__(self, hue, rect) : pygame.sprite.Sprite.__init__(self) @@ -155,6 +155,15 @@ class Column(pygame.sprite.Sprite) : else : self.image = self.stateOff self.rect = self.rectOff + + @event_handler(pygame.MOUSEBUTTONDOWN) + def onMouseDown(self, event) : + if self.rect.collidepoint(*event.pos) : + self.update(True) + + @event_handler(pygame.MOUSEBUTTONUP) + def onMouseUp(self, event) : + self.update(False) def hls_to_rgba_8bits(h, l, s) : #convert to rgb ranging from 0 to 255