1 # -*- coding: utf-8 -*-
3 Écran de démarrage minwii.
8 from pgu
.gui
import Table
9 from pgu
.gui
import Spacer
10 from pgu
.gui
import Label
11 from pgu
.gui
import Button
12 from pgu
.gui
import Switch
13 from pgu
.gui
import Radio
14 from pgu
.gui
import Group
15 from pgu
.gui
import Select
16 from pgu
.gui
import CLICK
17 from pgu
.gui
import QUIT
18 from pgu
.gui
import CHANGE
20 from minwii
.globals import PLAYING_MODES
21 from songfilebrowser
import FileOpenDialog
24 STYLE_LEFT_COL
= {#'border_right' : 2,
30 STYLE_RIGHT_COL
= {#'border_right' : 2,
37 class Home(object, Table
) :
39 Écran de démarrage de minwii
42 def __init__(self
,**params
):
43 style
= {'valign' : 0,
44 'width' : pygame
.display
.get_surface().get_width(),
45 'height' : pygame
.display
.get_surface().get_height()}
46 params
['style'] = style
47 Table
.__init
__(self
,**params
)
48 self
.songPath
= params
.get('songPath', '.')
49 self
.nwiimotes
= params
.get('nwiimotes', 0)
50 self
.songFile
= params
.get('songFile', '')
51 self
.spaceSize
= (100,100)
52 self
.font
= pygame
.font
.Font(None,70)
54 self
.selectedPlayMode
= params
.get('playMode', 'NORMAL')
55 self
.displayNotes
= params
.get('displayNotes', True)
56 self
.selectedWiimoteIndex
= params
.get('wiimoteIndex', 0)
57 self
._initLocalListeners
()
61 # bouton pour browser de fichiers
63 st
= STYLE_LEFT_COL
.copy()
65 self
.td(self
.createLabel("Chanson :"), rowspan
=2, style
= st
)
66 self
.browseButton
= Button(self
.createLabel("Choisir..."))
67 self
.td(self
.browseButton
,colspan
=2, style
= STYLE_RIGHT_COL
)
70 caption
= '' if not self
.songFile
else FileOpenDialog
.getSongTitle(self
.songFile
)
71 self
.songTitle
= self
.createLabel(caption
)
72 st
= STYLE_RIGHT_COL
.copy()
74 self
.td(self
.songTitle
, style
= st
)
76 # choix du mode de jeu
78 self
.td(self
.createLabel("Mode :"), style
=STYLE_LEFT_COL
)
79 self
.modeSelect
= Select('NORMAL')
80 for k
, caption
in PLAYING_MODES
:
81 self
.modeSelect
.add(self
.createLabel(caption
), k
)
82 self
.td(self
.modeSelect
,colspan
=3, style
=STYLE_RIGHT_COL
)
84 # affichage / masquage des noms de notes
86 self
.td(self
.createLabel("Notes :"), style
=STYLE_LEFT_COL
)
87 self
.displayNotesSelect
= Select(True)
88 for k
, caption
in ((True, 'Oui'), (False, 'Non')) :
89 self
.displayNotesSelect
.add(self
.createLabel(caption
), k
)
90 self
.td(self
.displayNotesSelect
, style
=STYLE_RIGHT_COL
)
95 self
.td(self
.createLabel("Wiimote :", self
.font
), style
=STYLE_LEFT_COL
)
98 self
.selectedWiimote
= Group(name
='selectedWiimote', value
=0)
99 for i
in range(self
.nwiimotes
- 1):
100 r
= Radio(self
.selectedWiimote
, i
)
102 playerTable
.td(self
.createLabel(" %d " % (i
+1)))
103 self
.td(playerTable
, style
=STYLE_RIGHT_COL
)
105 # boutons jouer / quitter
107 self
.quitButton
= Button(self
.createLabel("Quitter"))
108 self
.td(self
.quitButton
, style
={'padding_top' : 50})
109 self
.playButton
= Button(self
.createLabel("Jouer"))
110 self
.td(self
.playButton
, style
={'padding_top' : 50})
113 def selectedPlayMode(self
) :
114 return self
.modeSelect
.value
116 @selectedPlayMode.setter
117 def selectedPlayMode(self
, value
) :
118 self
.modeSelect
.value
= value
119 if self
.selectedPlayMode
!= 'IMPRO' and \
121 self
.playButton
.disabled
= True
123 self
.playButton
.disabled
= False
126 def displayNotes(self
) :
127 return self
.displayNotesSelect
.value
130 def displayNotes(self
, value
) :
131 self
.displayNotesSelect
.value
= value
134 def selectedWiimoteIndex(self
) :
135 return self
.selectedWiimote
.value
137 @selectedWiimoteIndex.setter
138 def selectedWiimoteIndex(self
, value
) :
139 self
.selectedWiimote
.value
= value
141 def _initLocalListeners(self
) :
142 self
.browseButton
.connect(CLICK
, self
.open_file_browser
)
143 self
.quitButton
.connect(CLICK
, self
._exitApp
)
144 self
.playButton
.connect(CLICK
, self
._exitHome
)
145 self
.modeSelect
.connect(CHANGE
, self
._changeModeCB
)
147 def _changeModeCB(self
) :
148 if self
.selectedPlayMode
== 'IMPRO' :
149 self
.playButton
.disabled
= False
150 elif not self
.songFile
:
151 self
.playButton
.disabled
= True
153 def _exitApp(self
, data
=None) :
157 def _exitHome(self
, data
=None) :
161 def createLabel(self
,text
,font
= None):
164 w
,h
= self
.font
.size(text
)
165 label
= Label(text
,width
=w
,height
=h
,font
= font
)
168 def open_file_browser(self
):
169 dlg
= FileOpenDialog(self
.songPath
)
170 dlg
.connect(CHANGE
, self
.handle_file_browser_closed
, dlg
)
173 def handle_file_browser_closed(self
, dlg
) :
174 if dlg
.value
and os
.path
.isfile(dlg
.value
):
175 self
.remove(self
.songTitle
)
176 title
= FileOpenDialog
.getSongTitle(dlg
.value
)
177 self
.songTitle
= self
.createLabel(title
)
178 self
.td(self
.songTitle
, col
=1, row
=1, style
=STYLE_RIGHT_COL
)
179 self
.songFile
= dlg
.value
180 self
.playButton
.disabled
= False