From 2feaf292e83d3c06e228ea81b4cd0a018d50de36 Mon Sep 17 00:00:00 2001 From: pin Date: Fri, 16 Apr 2010 12:25:51 +0000 Subject: [PATCH 1/1] =?utf8?q?modifications=20pour=20code=20auto-document?= =?utf8?q?=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@145 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/config.py | 2 +- src/app/log.py | 4 +- src/app/minwii.py | 135 ++++++++++++++++++++++++---------------- src/app/start.py | 11 ++-- src/app/widgets/home.py | 4 +- 5 files changed, 95 insertions(+), 61 deletions(-) diff --git a/src/app/config.py b/src/app/config.py index eb10ceb..a8410d2 100755 --- a/src/app/config.py +++ b/src/app/config.py @@ -21,7 +21,7 @@ pygame.font.init() # playingscreen -FRAMERATE = 50 +FRAMERATE = 100 BORDER = 0 # 5px FIRST_HUE = 0.6 OFF_LUMINANCE = 0.2 diff --git a/src/app/log.py b/src/app/log.py index b2cd407..f270b8d 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -26,8 +26,10 @@ class EventLoggerAdapter(logging.LoggerAdapter) : return pp(msg), kwargs #logging.basicConfig(level=logging.DEBUG, stream = sys.stdout) - console = logging.getLogger('minwii.console') +console.setLevel(logging.DEBUG) +console.addHandler(logging.StreamHandler()) + _eventLogger = logging.getLogger('minwii.events') _eventLogger.setLevel(logging.INFO) _eventHandler = logging.StreamHandler() diff --git a/src/app/minwii.py b/src/app/minwii.py index d75dd5e..c5961af 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -18,73 +18,104 @@ from eventutils import EventDispatcher from musicxml import musicXml2Song from config import SONG_FILE_PATH from globals import PLAYING_MODES_DICT +from log import console class MinWii(object): - def __init__(self, wimoteSupport=True) : + def __init__(self, wiimoteSupport=True) : + self.wiimoteSupport = wiimoteSupport LaunchScreen() - app = Desktop() - synth = Synth() - - screenResolution = (1024,768) - - if wimoteSupport : + self.app = Desktop() + self.synth = Synth() + self.screenResolution = (1024,768) + self.nwiimotes = 0 + self.initWiimotes() + + def initWiimotes(self) : + if self.wiimoteSupport : from pywiiuse import pygame_wiimouse pygame_wiimouse.init(4, 5, screenResolution) # look for 4, wait 5 seconds - nwiimotes = pygame_wiimouse.get_count() - print '%d wiimotes' % nwiimotes - WT = pygame_wiimouse.WT + self.nwiimotes = nwiimotes = pygame_wiimouse.get_count() + console.debug('%d wiimotes found', nwiimotes) + self.WT = WT = pygame_wiimouse.WT WT.pause() else : - nwiimotes = 0 - class _WTFacade : - selectWimoteIndex = 0 - def pause(self): - pass - def resume(self): - pass - def selectWiimote(self, i): - pass - WT = _WTFacade() + self.WT = _WTFacade() + + def run(self) : + "manage the screen sequence display" - pygame.display.set_mode(screenResolution) + pygame.display.set_mode(self.screenResolution) pygame.display.set_caption('MinWii') + WT = self.WT while True : - # sélection de la chanson - home = Home(songPath=SONG_FILE_PATH, - nwiimotes=nwiimotes) - home.connect(QUIT, app.quit) - app.run(home) - app.close(home) - returnValue = home.returnValue - print 'home.selectedWiimoteIndex', home.selectedWiimoteIndex - if not returnValue : - break + + exit, songFile, playMode, selectedWiimoteIndex = self.selectSongAndOptions() + if exit : break - WT.selectWiimote(home.selectedWiimoteIndex) + WT.selectWiimote(selectedWiimoteIndex) + console.info('wiimote sélectionnée : %d', selectedWiimoteIndex) WT.resume() - # sélection de l'instrument - selector = InstrumentSelector() - selector.run() - selector.stop() - pygame.event.clear() - EventDispatcher.reset() - instrumentDescription = selector.selectedInstrument + instrumentDescription = self.selectInstrument() + self.runPlayingScreen(songFile, playMode, instrumentDescription) - # lancement du lecteur / clavier - songFile = home.songFile - playMode = home.modeSelect.value - playMode = PLAYING_MODES_DICT[playMode] - song = musicXml2Song(songFile) - bank, preset = instrumentDescription['bank'], instrumentDescription['preset'] - octave = instrumentDescription.get('octave', 0) - synth.adjust_octave(0, octave) - synth.program_select(0, bank, preset) - playingScreen = SongPlayingScreen(synth, song, mode=playMode) - playingScreen.run() - pygame.event.clear() - EventDispatcher.reset() WT.pause() + + + def selectSongAndOptions(self) : + """ lance l'écran de paramétrage et retourne un tuple comportant : + - drapeau de sortie de l'application (booléen) + - chemin du fichier de la chanson + - mode (entier) + - wiimote sélectionnée (entier) + """ + home = Home(songPath=SONG_FILE_PATH, + nwiimotes=self.nwiimotes) + app = self.app + home.connect(QUIT, app.quit) + app.run(home) + app.close(home) + #console.debug('wiimote selected: %d', home.selecctedWiimoteIndex) + return (home.exitApp, + home.songFile, + home.modeSelect.value, + home.selectedWiimote.value) + + def selectInstrument(self) : + """ lance l'écran de sélection de l'instrument et retourne + un dictionnaire comportant la description de l'instrument + """ + selector = InstrumentSelector() + selector.run() + selector.stop() + pygame.event.clear() + EventDispatcher.reset() + return selector.selectedInstrument + + def runPlayingScreen(self, songFile, playMode, instrumentDescription) : + """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode' + avec l'instrument midi 'instrumentDescription'. + """ + playMode = PLAYING_MODES_DICT[playMode] + song = musicXml2Song(songFile) + bank, preset = instrumentDescription['bank'], instrumentDescription['preset'] + octave = instrumentDescription.get('octave', 0) + self.synth.adjust_octave(0, octave) + self.synth.program_select(0, bank, preset) + playingScreen = SongPlayingScreen(self.synth, song, mode=playMode) + playingScreen.run() + pygame.event.clear() + EventDispatcher.reset() + + +class _WTFacade : + selectWimoteIndex = 0 + def pause(self): + pass + def resume(self): + pass + def selectWiimote(self, i): + pass diff --git a/src/app/start.py b/src/app/start.py index d1dc009..3f5f247 100755 --- a/src/app/start.py +++ b/src/app/start.py @@ -9,7 +9,7 @@ $URL$ -def main(wimoteSupport) : +def main(wiimoteSupport) : import pygame from minwii import MinWii @@ -17,7 +17,8 @@ def main(wimoteSupport) : #modeResolution = (1024,768) #modeResolution = (600,480) #pygame.display.set_mode(modeResolution, pygame.NOFRAME)#, pygame.FULLSCREEN) - MinWii(wimoteSupport=wimoteSupport) + minwii = MinWii(wiimoteSupport=wiimoteSupport) + minwii.run() # from gui.PGUConfiguration import PGUConfiguration # pygame.init() # modeResolution = (1024,768) @@ -33,17 +34,17 @@ if __name__ == "__main__" : usage = "%prog instance_home products_conf_file [options]" op = OptionParser(usage) - op.add_option("--no-wii", dest="wimoteSupport" + op.add_option("--no-wii", dest="wiimoteSupport" , action="store_false" , default=True , help = u"désactivation du support des wiimotes" u" [%default]") options, args = op.parse_args() - wimoteSupport = options.wimoteSupport + wiimoteSupport = options.wiimoteSupport minwiipath = realpath(__file__).split(sep) minwiipath = minwiipath[:-2] minwiipath = sep.join(minwiipath) sys.path.insert(1, minwiipath) - main(wimoteSupport) \ No newline at end of file + main(wiimoteSupport) \ No newline at end of file diff --git a/src/app/widgets/home.py b/src/app/widgets/home.py index 381ec68..44d96fe 100755 --- a/src/app/widgets/home.py +++ b/src/app/widgets/home.py @@ -99,11 +99,11 @@ class Home(Table) : self.playButton.connect(CLICK, self._exitHome) def _exitApp(self, data=None) : - self.returnValue = False + self.exitApp = True self.send(QUIT) def _exitHome(self, data=None) : - self.returnValue = True + self.exitApp = False self.send(QUIT) def createLabel(self,text,font = None): -- 2.20.1