Ajout d'un événement COLSTATECHANGE. Ajout de la position du curseur de la souris...
[minwii.git] / src / app / minwii.py
1 # -*- coding: utf-8 -*-
2 """
3 l'application winwii
4
5 $Id$
6 $URL$
7 """
8
9 import pygame
10 from pgu.gui import Desktop
11 from pgu.gui import QUIT
12 from widgets.launch import LaunchScreen
13 from widgets.home import Home
14 from widgets.playingscreen import SongPlayingScreen, PlayingScreen
15 from widgets.instrumentselector import InstrumentSelector
16 from synth import Synth
17 from eventutils import EventDispatcher
18 from musicxml import musicXml2Song
19 from config import SONG_FILE_PATH
20 from globals import PLAYING_MODES_DICT
21
22
23 class MinWii(object):
24
25 def __init__(self, wimoteSupport=True) :
26 LaunchScreen()
27 app = Desktop()
28 synth = Synth()
29
30 screenResolution = (1024,768)
31
32 if wimoteSupport :
33 from pywiiuse import pygame_wiimouse
34 pygame_wiimouse.init(4, 5, screenResolution) # look for 4, wait 5 seconds
35 nwiimotes = pygame_wiimouse.get_count()
36 print '%d wiimotes' % nwiimotes
37 WT = pygame_wiimouse.WT
38 WT.pause()
39 else :
40 nwiimotes = 0
41 class _WTFacade :
42 selectWimoteIndex = 0
43 def pause(self):
44 pass
45 def resume(self):
46 pass
47 def selectWiimote(self, i):
48 pass
49 WT = _WTFacade()
50
51 pygame.display.set_mode(screenResolution)
52 pygame.display.set_caption('MinWii')
53
54 while True :
55 # sélection de la chanson
56 home = Home(songPath=SONG_FILE_PATH,
57 nwiimotes=nwiimotes)
58 home.connect(QUIT, app.quit)
59 app.run(home)
60 app.close(home)
61 returnValue = home.returnValue
62 print 'home.selectedWiimoteIndex', home.selectedWiimoteIndex
63 if not returnValue :
64 break
65
66 WT.selectWiimote(home.selectedWiimoteIndex)
67 WT.resume()
68
69 # sélection de l'instrument
70 selector = InstrumentSelector()
71 selector.run()
72 selector.stop()
73 pygame.event.clear()
74 EventDispatcher.reset()
75 instrumentDescription = selector.selectedInstrument
76
77 # lancement du lecteur / clavier
78 songFile = home.songFile
79 playMode = home.modeSelect.value
80 playMode = PLAYING_MODES_DICT[playMode]
81 song = musicXml2Song(songFile)
82 bank, preset = instrumentDescription['bank'], instrumentDescription['preset']
83 octave = instrumentDescription.get('octave', 0)
84 synth.adjust_octave(0, octave)
85 synth.program_select(0, bank, preset)
86 playingScreen = SongPlayingScreen(synth, song, mode=playMode)
87 playingScreen.run()
88 pygame.event.clear()
89 EventDispatcher.reset()
90 WT.pause()