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
= os
.path
.basename(self
.songFile
)
70 self
.songTitle
= self
.createLabel(caption
)
71 st
= STYLE_RIGHT_COL
.copy()
73 self
.td(self
.songTitle
, style
= st
)
77 self
.td(self
.createLabel("Niveau :"), 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"), disabled
=not self
.songFile
)
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
111 def selectedWiimoteIndex(self
) :
112 return self
.selectedWiimote
.value
114 @selectedWiimoteIndex.setter
115 def selectedWiimoteIndex(self
, value
) :
116 self
.selectedWiimote
.value
= value
118 def _initLocalListeners(self
) :
119 self
.browseButton
.connect(CLICK
, self
.open_file_browser
)
120 self
.quitButton
.connect(CLICK
, self
._exitApp
)
121 self
.playButton
.connect(CLICK
, self
._exitHome
)
123 def _exitApp(self
, data
=None) :
127 def _exitHome(self
, data
=None) :
131 def createLabel(self
,text
,font
= None):
134 w
,h
= self
.font
.size(text
)
135 label
= Label(text
,width
=w
,height
=h
,font
= font
)
138 def open_file_browser(self
):
139 dlg
= FileOpenDialog(self
.songPath
)
140 dlg
.connect(CHANGE
, self
.handle_file_browser_closed
, dlg
)
143 def handle_file_browser_closed(self
, dlg
) :
144 if dlg
.value
and os
.path
.isfile(dlg
.value
):
145 self
.remove(self
.songTitle
)
146 self
.songTitle
= self
.createLabel(os
.path
.basename(dlg
.value
))
147 self
.td(self
.songTitle
, col
=1, row
=1, style
=STYLE_RIGHT_COL
)
148 self
.songFile
= dlg
.value
149 self
.playButton
.disabled
= False