X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/a08d887d02d2ba5f61f3c7b0eeb8dae1ba4deddf..a1cb64098e2a34d115378fdced1044da37e94395:/src/app/widgets/playingscreen.py?ds=sidebyside diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index 955a3ab..23f2643 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -9,6 +9,8 @@ $URL$ import pygame from colorsys import hls_to_rgb from gradients import gradients +from cursors import WarpingCursor +from eventutils import event_handler, EventHandlerMixin from math import floor import types # TODO : positionner cette constance en fonction de la résolution d'affichage @@ -23,27 +25,7 @@ ON_SATURATION = 1 ON_COLUMN_OVERSIZING = 1.5 -def rename_method(newName) : - def doRename(m) : - m.__name__ = newName - return m - return doRename - - -class MetaRenamer(type): - def __new__(mcs, name, bases, dict) : - for k, v in dict.items() : - if isinstance(v, types.FunctionType) : - if k != v.__name__ : - print 'renommage de %s en %s' % (k, v.__name__) - dict[v.__name__] = v - del dict[k] - return type.__new__(mcs, name, bases, dict) - - -class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : - - __metaclass__ = MetaRenamer +class _PlayingScreenBase(pygame.sprite.OrderedUpdates, EventHandlerMixin) : def __init__(self, distinctNotes=[]) : """ @@ -54,9 +36,12 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : self.distinctNotes = distinctNotes self.keyboardLength = 0 self.keyboardRects = [] + self.cursor = None self._initRects() self._initColumns() self._running = False + self.draw(pygame.display.get_surface()) + self._initCursor() @@ -94,7 +79,11 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : print hue c = Column(hue, rect) self.add(c) - + + def _initCursor(self) : + self.cursor = WarpingCursor() + #self.add(self.cursor) + def highlightColumn(self, index) : for i, sprite in enumerate(self.sprites()) : @@ -113,7 +102,7 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : handler = getattr(self, 'eventHandler%s' % event.type, lambda e:None) handler(event) - @rename_method('eventHandler%s' % pygame.KEYDOWN) + @event_handler(pygame.KEYDOWN) def handleKeyDown(self, event) : if event.key == pygame.K_q: self._running = False @@ -121,6 +110,10 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : if uni.isdigit() and int(uni) <=8 : self.highlightColumn(int(uni)) + + @event_handler(pygame.MOUSEMOTION) + def handleMouseMotion(self, event) : + pass