Prise en charge de la touche « esc » pour quitter les écrans de sélectien d'instrumen...
[minwii.git] / src / minwii / widgets / playingscreen.py
index 0735825..66c4776 100755 (executable)
@@ -7,22 +7,23 @@ $Id$
 $URL$
 """
 import pygame
-from cursors import WarpingCursor
-from column import Column
-import events
-from eventutils import event_handler, EventDispatcher, EventHandlerMixin
 import types
-from musicxml import Tone
 
-from config import FRAMERATE
-from config import FIRST_HUE
-from config import MIDI_VELOCITY_RANGE
-from config import MIDI_PAN_RANGE
-from config import MIDI_VELOCITY_WRONG_NOTE_ATTN
+import minwii.events as events
+from minwii.log import eventLogger
+from minwii.eventutils import event_handler, EventDispatcher, EventHandlerMixin
+from minwii.musicxml import Tone
+from minwii.config import FRAMERATE
+from minwii.config import FIRST_HUE
+from minwii.config import MIDI_VELOCITY_RANGE
+from minwii.config import MIDI_PAN_RANGE
+from minwii.config import MIDI_VELOCITY_WRONG_NOTE_ATTN
+from minwii.globals import BACKGROUND_LAYER
+from minwii.globals import CURSOR_LAYER
+from minwii.globals import PLAYING_MODES_DICT
 
-from globals import BACKGROUND_LAYER
-from globals import CURSOR_LAYER
-from globals import PLAYING_MODES_DICT
+from cursors import WarpingCursor
+from column import Column
 
 class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
 
@@ -99,7 +100,9 @@ class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
 
     @event_handler(pygame.KEYDOWN)       
     def handleKeyDown(self, event) :
-        if event.key == pygame.K_q or event.unicode == u'q':
+        if event.key == pygame.K_q or \
+            event.unicode == u'q' or \
+            pygame.K_ESCAPE:
             self.stop()
     
     @event_handler(pygame.MOUSEBUTTONDOWN)
@@ -292,8 +295,17 @@ class SongPlayingScreen(PlayingScreenBase) :
     def displayNext(self, event=None) :
         if self.currentColumn:
             self.currentColumn.update(False)
-        note, verseIndex = self.noteIterator.next()
-        syllabus = note.lyrics[verseIndex].syllabus()
+        try :
+            note, verseIndex = self.noteIterator.next()
+        except StopIteration :
+            self.noteIterator = self.song.iterNotes()
+            note, verseIndex = self.noteIterator.next()
+            eventLogger.info(pygame.event.Event(events.SONGEND))
+        try :
+            syllabus = note.lyrics[verseIndex].syllabus()
+        except IndexError :
+            syllabus = u'…'
+        
         column = self.columns[note.midi]
         column.update(True, syllabus)
         self.currentColumn = column