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,90)
54 self
.selectedPlayMode
= params
.get('playMode', 'NORMAL')
55 self
.displayNotes
= params
.get('displayNotes', True)
56 self
.selectedWiimoteIndex
= params
.get('wiimoteIndex', 0)
58 self
._initLocalListeners
()
62 # bouton pour browser de fichiers
64 st
= STYLE_LEFT_COL
.copy()
66 self
.td(self
.createLabel("Chanson :"), rowspan
=2, style
= st
)
67 self
.browseButton
= Button(self
.createLabel("Choisir..."))
68 self
.td(self
.browseButton
,colspan
=2, style
= STYLE_RIGHT_COL
)
71 caption
= '' if not self
.songFile
else FileOpenDialog
.getSongTitle(self
.songFile
)
72 self
.songTitle
= self
.createLabel(caption
, font
=pygame
.font
.Font(None,60))
73 st
= STYLE_RIGHT_COL
.copy()
75 self
.td(self
.songTitle
, style
= st
)
77 # choix du mode de jeu
79 self
.td(self
.createLabel("Mode :"), style
=STYLE_LEFT_COL
)
80 self
.modeSelect
= Select('NORMAL')
81 for k
, caption
in PLAYING_MODES
:
82 self
.modeSelect
.add(self
.createLabel(caption
), k
)
83 self
.td(self
.modeSelect
,colspan
=3, style
=STYLE_RIGHT_COL
)
85 # affichage / masquage des noms de notes
87 self
.td(self
.createLabel("Notes :"), style
=STYLE_LEFT_COL
)
88 self
.displayNotesSelect
= Select(True)
89 for k
, caption
in ((True, 'Oui'), (False, 'Non')) :
90 self
.displayNotesSelect
.add(self
.createLabel(caption
), k
)
91 self
.td(self
.displayNotesSelect
, style
=STYLE_RIGHT_COL
)
96 self
.td(self
.createLabel("Wiimote :", self
.font
), style
=STYLE_LEFT_COL
)
99 self
.selectedWiimote
= Group(name
='selectedWiimote', value
=0)
100 for i
in range(self
.nwiimotes
- 1):
101 r
= Radio(self
.selectedWiimote
, i
)
103 playerTable
.td(self
.createLabel(" %d " % (i
+1)))
104 self
.td(playerTable
, style
=STYLE_RIGHT_COL
)
106 # boutons jouer / quitter
108 self
.quitButton
= Button(self
.createLabel("Quitter"))
109 self
.td(self
.quitButton
, style
={'padding_top' : 50})
110 self
.playButton
= Button(self
.createLabel("Jouer"))
111 self
.td(self
.playButton
, style
={'padding_top' : 50})
114 def selectedPlayMode(self
) :
115 return self
.modeSelect
.value
117 @selectedPlayMode.setter
118 def selectedPlayMode(self
, value
) :
119 self
.modeSelect
.value
= value
120 if self
.selectedPlayMode
!= 'IMPRO' and \
122 self
.playButton
.disabled
= True
124 self
.playButton
.disabled
= False
127 def displayNotes(self
) :
128 return self
.displayNotesSelect
.value
131 def displayNotes(self
, value
) :
132 self
.displayNotesSelect
.value
= value
135 def selectedWiimoteIndex(self
) :
136 return self
.selectedWiimote
.value
138 @selectedWiimoteIndex.setter
139 def selectedWiimoteIndex(self
, value
) :
140 self
.selectedWiimote
.value
= value
142 def _initLocalListeners(self
) :
143 self
.browseButton
.connect(CLICK
, self
.open_file_browser
)
144 self
.quitButton
.connect(CLICK
, self
._exitApp
)
145 self
.playButton
.connect(CLICK
, self
._exitHome
)
146 self
.modeSelect
.connect(CHANGE
, self
._changeModeCB
)
148 def _changeModeCB(self
) :
149 if self
.selectedPlayMode
== 'IMPRO' :
150 self
.playButton
.disabled
= False
151 elif not self
.songFile
:
152 self
.playButton
.disabled
= True
154 def _exitApp(self
, data
=None) :
158 def _exitHome(self
, data
=None) :
162 def createLabel(self
,text
,font
= None):
165 w
,h
= self
.font
.size(text
)
166 label
= Label(text
,width
=w
,height
=h
,font
= font
)
169 def open_file_browser(self
):
170 dlg
= FileOpenDialog(self
.songPath
)
171 dlg
.connect(CHANGE
, self
.handle_file_browser_closed
, dlg
)
174 def handle_file_browser_closed(self
, dlg
) :
175 if dlg
.value
and os
.path
.isfile(dlg
.value
):
176 self
.remove(self
.songTitle
)
177 title
= FileOpenDialog
.getSongTitle(dlg
.value
)
178 self
.songTitle
= self
.createLabel(title
, font
= pygame
.font
.Font(None,60))
179 self
.td(self
.songTitle
, col
=1, row
=1, style
=STYLE_RIGHT_COL
)
180 self
.songFile
= dlg
.value
181 self
.playButton
.disabled
= False