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
()
59 #self.td(Spacer(*self.spaceSize))
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 self
.songTitle
= self
.createLabel(u
'bonjour le monde !')
72 st
= STYLE_RIGHT_COL
.copy()
74 self
.td(self
.songTitle
, style
= st
)
78 self
.td(self
.createLabel("Niveau :"), 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
)
86 self
.td(self
.createLabel("Wiimote :", self
.font
), style
=STYLE_LEFT_COL
)
89 self
.selectedWiimote
= Group(name
='selectedWiimote', value
=0)
90 for i
in range(self
.nwiimotes
):
91 r
= Radio(self
.selectedWiimote
, i
)
93 playerTable
.td(self
.createLabel(" %d " % (i
+1)))
94 self
.td(playerTable
, style
=STYLE_RIGHT_COL
)
96 # boutons jouer / quitter
98 self
.quitButton
= Button(self
.createLabel("Quitter"))
99 self
.td(self
.quitButton
, style
={'padding_top' : 50})
100 self
.playButton
= Button(self
.createLabel("Jouer"), disabled
=True)
101 self
.td(self
.playButton
, style
={'padding_top' : 50})
104 def selectedWiimoteIndex(self
) :
105 return self
.selectedWiimote
.value
107 def _initLocalListeners(self
) :
108 self
.browseButton
.connect(CLICK
, self
.open_file_browser
)
109 self
.quitButton
.connect(CLICK
, self
._exitApp
)
110 self
.playButton
.connect(CLICK
, self
._exitHome
)
112 def _exitApp(self
, data
=None) :
116 def _exitHome(self
, data
=None) :
120 def createLabel(self
,text
,font
= None):
123 w
,h
= self
.font
.size(text
)
124 label
= Label(text
,width
=w
,height
=h
,font
= font
)
127 def open_file_browser(self
):
128 dlg
= FileOpenDialog(self
.songPath
)
129 dlg
.connect(CHANGE
, self
.handle_file_browser_closed
, dlg
)
132 def handle_file_browser_closed(self
, dlg
) :
133 if dlg
.value
and os
.path
.isfile(dlg
.value
):
134 self
.remove(self
.songTitle
)
135 self
.songTitle
= self
.createLabel(os
.path
.basename(dlg
.value
))
136 self
.td(self
.songTitle
, col
=1, row
=1, style
=STYLE_RIGHT_COL
)
137 self
.songFile
= dlg
.value
138 self
.playButton
.disabled
= False