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,
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)
51 self
.spaceSize
= (100,100)
52 self
.font
= pygame
.font
.Font(None,70)
54 self
._initLocalListeners
()
58 # bouton pour browser de fichiers
60 st
= STYLE_LEFT_COL
.copy()
62 self
.td(self
.createLabel("Chanson :"), rowspan
=2, style
= st
)
63 self
.browseButton
= Button(self
.createLabel("Choisir..."))
64 self
.td(self
.browseButton
,colspan
=2, style
= STYLE_RIGHT_COL
)
67 self
.songTitle
= self
.createLabel(u
' ')
68 st
= STYLE_RIGHT_COL
.copy()
70 self
.td(self
.songTitle
, style
= st
)
74 self
.td(self
.createLabel("Niveau :"), style
=STYLE_LEFT_COL
)
75 self
.modeSelect
= Select('NORMAL')
76 for k
, caption
in PLAYING_MODES
:
77 self
.modeSelect
.add(self
.createLabel(caption
), k
)
78 self
.td(self
.modeSelect
,colspan
=3, style
=STYLE_RIGHT_COL
)
82 self
.td(self
.createLabel("Wiimote :", self
.font
), style
=STYLE_LEFT_COL
)
85 self
.selectedWiimote
= Group(name
='selectedWiimote', value
=0)
86 for i
in range(self
.nwiimotes
):
87 r
= Radio(self
.selectedWiimote
, i
)
89 playerTable
.td(self
.createLabel(" %d " % (i
+1)))
90 self
.td(playerTable
, style
=STYLE_RIGHT_COL
)
92 # boutons jouer / quitter
94 self
.quitButton
= Button(self
.createLabel("Quitter"))
95 self
.td(self
.quitButton
, style
={'padding_top' : 50})
96 self
.playButton
= Button(self
.createLabel("Jouer"), disabled
=True)
97 self
.td(self
.playButton
, style
={'padding_top' : 50})
100 def selectedWiimoteIndex(self
) :
101 return self
.selectedWiimote
.value
103 def _initLocalListeners(self
) :
104 self
.browseButton
.connect(CLICK
, self
.open_file_browser
)
105 self
.quitButton
.connect(CLICK
, self
._exitApp
)
106 self
.playButton
.connect(CLICK
, self
._exitHome
)
108 def _exitApp(self
, data
=None) :
112 def _exitHome(self
, data
=None) :
116 def createLabel(self
,text
,font
= None):
119 w
,h
= self
.font
.size(text
)
120 label
= Label(text
,width
=w
,height
=h
,font
= font
)
123 def open_file_browser(self
):
124 dlg
= FileOpenDialog(self
.songPath
)
125 dlg
.connect(CHANGE
, self
.handle_file_browser_closed
, dlg
)
128 def handle_file_browser_closed(self
, dlg
) :
129 if dlg
.value
and os
.path
.isfile(dlg
.value
):
130 self
.remove(self
.songTitle
)
131 self
.songTitle
= self
.createLabel(os
.path
.basename(dlg
.value
))
132 self
.td(self
.songTitle
, col
=1, row
=1, style
=STYLE_RIGHT_COL
)
133 self
.songFile
= dlg
.value
134 self
.playButton
.disabled
= False