debug--
[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(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 = None
51 self.spaceSize = (100,100)
52 self.font = pygame.font.Font(None,70)
53 self._fill()
54 self._initLocalListeners()
55
56
57 def _fill(self):
58 # bouton pour browser de fichiers
59 self.tr()
60 st = STYLE_LEFT_COL.copy()
61 st['valign'] = -1
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)
65
66 self.tr()
67 self.songTitle = self.createLabel(u' ')
68 st = STYLE_RIGHT_COL.copy()
69 del st['padding_top']
70 self.td(self.songTitle, style = st)
71
72 # choix du niveau
73 self.tr()
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)
79
80 # choix des wiimotes
81 self.tr()
82 self.td(self.createLabel("Wiimote :", self.font), style=STYLE_LEFT_COL)
83 playerTable = Table()
84
85 self.selectedWiimote = Group(name='selectedWiimote', value=0)
86 for i in range(self.nwiimotes):
87 r = Radio(self.selectedWiimote, i)
88 playerTable.td(r)
89 playerTable.td(self.createLabel(" %d " % (i+1)))
90 self.td(playerTable, style=STYLE_RIGHT_COL)
91
92 # boutons jouer / quitter
93 self.tr()
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})
98
99 @property
100 def selectedWiimoteIndex(self) :
101 return self.selectedWiimote.value
102
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)
107
108 def _exitApp(self, data=None) :
109 self.exitApp = True
110 self.send(QUIT)
111
112 def _exitHome(self, data=None) :
113 self.exitApp = False
114 self.send(QUIT)
115
116 def createLabel(self,text,font = None):
117 if font == None :
118 font = self.font
119 w,h = self.font.size(text)
120 label = Label(text,width=w,height=h,font = font)
121 return(label)
122
123 def open_file_browser(self):
124 dlg = FileOpenDialog(self.songPath)
125 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
126 dlg.open()
127
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
135
136
137