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
.selectedWiimoteIndex
= params
.get('wiimoteIndex', 0)
56 self
._initLocalListeners
()
60 # bouton pour browser de fichiers
62 st
= STYLE_LEFT_COL
.copy()
64 self
.td(self
.createLabel("Chanson :"), rowspan
=2, style
= st
)
65 self
.browseButton
= Button(self
.createLabel("Choisir..."))
66 self
.td(self
.browseButton
,colspan
=2, style
= STYLE_RIGHT_COL
)
69 caption
= '' if not self
.songFile
else FileOpenDialog
.getSongTitle(self
.songFile
)
70 self
.songTitle
= self
.createLabel(caption
)
71 st
= STYLE_RIGHT_COL
.copy()
73 self
.td(self
.songTitle
, style
= st
)
75 # choix du mode de jeu
77 self
.td(self
.createLabel("Mode :"), style
=STYLE_LEFT_COL
)
78 self
.modeSelect
= Select('NORMAL')
79 for k
, caption
in PLAYING_MODES
:
80 self
.modeSelect
.add(self
.createLabel(caption
), k
)
81 self
.td(self
.modeSelect
,colspan
=3, style
=STYLE_RIGHT_COL
)
85 self
.td(self
.createLabel("Wiimote :", self
.font
), style
=STYLE_LEFT_COL
)
88 self
.selectedWiimote
= Group(name
='selectedWiimote', value
=0)
89 for i
in range(self
.nwiimotes
):
90 r
= Radio(self
.selectedWiimote
, i
)
92 playerTable
.td(self
.createLabel(" %d " % (i
+1)))
93 self
.td(playerTable
, style
=STYLE_RIGHT_COL
)
95 # boutons jouer / quitter
97 self
.quitButton
= Button(self
.createLabel("Quitter"))
98 self
.td(self
.quitButton
, style
={'padding_top' : 50})
99 self
.playButton
= Button(self
.createLabel("Jouer"))
100 self
.td(self
.playButton
, style
={'padding_top' : 50})
103 def selectedPlayMode(self
) :
104 return self
.modeSelect
.value
106 @selectedPlayMode.setter
107 def selectedPlayMode(self
, value
) :
108 self
.modeSelect
.value
= value
109 if self
.selectedPlayMode
!= 'IMPRO' and \
111 self
.playButton
.disabled
= True
113 self
.playButton
.disabled
= False
116 def selectedWiimoteIndex(self
) :
117 return self
.selectedWiimote
.value
119 @selectedWiimoteIndex.setter
120 def selectedWiimoteIndex(self
, value
) :
121 self
.selectedWiimote
.value
= value
123 def _initLocalListeners(self
) :
124 self
.browseButton
.connect(CLICK
, self
.open_file_browser
)
125 self
.quitButton
.connect(CLICK
, self
._exitApp
)
126 self
.playButton
.connect(CLICK
, self
._exitHome
)
127 self
.modeSelect
.connect(CHANGE
, self
._changeModeCB
)
129 def _changeModeCB(self
) :
130 if self
.selectedPlayMode
== 'IMPRO' :
131 self
.playButton
.disabled
= False
132 elif not self
.songFile
:
133 self
.playButton
.disabled
= True
135 def _exitApp(self
, data
=None) :
139 def _exitHome(self
, data
=None) :
143 def createLabel(self
,text
,font
= None):
146 w
,h
= self
.font
.size(text
)
147 label
= Label(text
,width
=w
,height
=h
,font
= font
)
150 def open_file_browser(self
):
151 dlg
= FileOpenDialog(self
.songPath
)
152 dlg
.connect(CHANGE
, self
.handle_file_browser_closed
, dlg
)
155 def handle_file_browser_closed(self
, dlg
) :
156 if dlg
.value
and os
.path
.isfile(dlg
.value
):
157 self
.remove(self
.songTitle
)
158 title
= FileOpenDialog
.getSongTitle(dlg
.value
)
159 self
.songTitle
= self
.createLabel(title
)
160 self
.td(self
.songTitle
, col
=1, row
=1, style
=STYLE_RIGHT_COL
)
161 self
.songFile
= dlg
.value
162 self
.playButton
.disabled
= False