Correction des liaisons entre les syllabes.
[minwii.git] / src / minwii / widgets / home.py
1 # -*- coding: utf-8 -*-
2 """
3 Écran de démarrage minwii.
4
5 $Id$
6 $URL$
7 """
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
19 import pygame
20 from minwii.globals import PLAYING_MODES
21 from songfilebrowser import FileOpenDialog
22 import os.path
23
24 STYLE_LEFT_COL = {#'border_right' : 2,
25 #'border_left' : 2,
26 'align' : 1,
27 'padding_top' : 30,
28 'padding_right' : 10}
29
30 STYLE_RIGHT_COL = {#'border_right' : 2,
31 #'border_left' : 2,
32 'align' : -1,
33 'padding_top' : 30,
34 'padding_left' : 20}
35
36
37 class Home(object, Table) :
38 """
39 Écran de démarrage de minwii
40 """
41
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)
53 self._fill()
54 self.selectedPlayMode = params.get('playMode', 'NORMAL')
55 self.selectedWiimoteIndex = params.get('wiimoteIndex', 0)
56 self._initLocalListeners()
57
58
59 def _fill(self):
60 # bouton pour browser de fichiers
61 self.tr()
62 st = STYLE_LEFT_COL.copy()
63 st['valign'] = -1
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)
67
68 self.tr()
69 caption = '' if not self.songFile else FileOpenDialog.getSongTitle(self.songFile)
70 self.songTitle = self.createLabel(caption)
71 st = STYLE_RIGHT_COL.copy()
72 del st['padding_top']
73 self.td(self.songTitle, style = st)
74
75 # choix du niveau
76 self.tr()
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)
82
83 # choix des wiimotes
84 self.tr()
85 self.td(self.createLabel("Wiimote :", self.font), style=STYLE_LEFT_COL)
86 playerTable = Table()
87
88 self.selectedWiimote = Group(name='selectedWiimote', value=0)
89 for i in range(self.nwiimotes):
90 r = Radio(self.selectedWiimote, i)
91 playerTable.td(r)
92 playerTable.td(self.createLabel(" %d " % (i+1)))
93 self.td(playerTable, style=STYLE_RIGHT_COL)
94
95 # boutons jouer / quitter
96 self.tr()
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})
101
102 @property
103 def selectedPlayMode(self) :
104 return self.modeSelect.value
105
106 @selectedPlayMode.setter
107 def selectedPlayMode(self, value) :
108 self.modeSelect.value = value
109
110 @property
111 def selectedWiimoteIndex(self) :
112 return self.selectedWiimote.value
113
114 @selectedWiimoteIndex.setter
115 def selectedWiimoteIndex(self, value) :
116 self.selectedWiimote.value = value
117
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)
122
123 def _exitApp(self, data=None) :
124 self.exitApp = True
125 self.send(QUIT)
126
127 def _exitHome(self, data=None) :
128 self.exitApp = False
129 self.send(QUIT)
130
131 def createLabel(self,text,font = None):
132 if font == None :
133 font = self.font
134 w,h = self.font.size(text)
135 label = Label(text,width=w,height=h,font = font)
136 return(label)
137
138 def open_file_browser(self):
139 dlg = FileOpenDialog(self.songPath)
140 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
141 dlg.open()
142
143 def handle_file_browser_closed(self, dlg) :
144 if dlg.value and os.path.isfile(dlg.value):
145 self.remove(self.songTitle)
146 title = FileOpenDialog.getSongTitle(dlg.value)
147 self.songTitle = self.createLabel(title)
148 self.td(self.songTitle, col=1, row=1, style=STYLE_RIGHT_COL)
149 self.songFile = dlg.value
150 self.playButton.disabled = False
151
152
153