18e1c6f7ee92a4987a1d26813849c6fe9b75a3ba
[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 STYLE_RIGHT_COL = {'border_right' : 2,
28 'border_left' : 2,
29 'align' : -1}
30
31
32 class Home(Table) :
33 """
34 Écran de démarrage de minwii
35 """
36
37 def __init__(self,**params):
38 style = {'valign' : 0,
39 'width' : pygame.display.get_surface().get_width(),
40 'height' : pygame.display.get_surface().get_height()}
41 print style
42 params['style'] = style
43 Table.__init__(self,**params)
44 self.songPath = params.get('songPath', '.')
45 self.nwiimotes = params.get('nwiimotes', 0)
46 self.songFile = None
47 self.spaceSize = (100,100)
48 self.font = pygame.font.Font(None,70)
49 self._fill()
50 #self._initLocalListeners()
51
52
53 def _fill(self):
54 #self.tr()
55 #self.td(Spacer(*self.spaceSize))
56
57
58 # bouton pour browser de fichiers
59 self.tr()
60 self.td(self.createLabel("Chanson :"), style = STYLE_LEFT_COL)
61 self.browseButton = Button(self.createLabel("Choisir..."))
62 self.td(self.browseButton,colspan=2, style = STYLE_RIGHT_COL)
63
64 # self.tr()
65 # self.songTitle = self.createLabel(u' ')
66 # self.td(self.songTitle, colspan=2, style = STYLE)
67 #
68 # # choix du niveau
69 # self.tr()
70 # self.td(self.createLabel("Niveau :"))
71 # self.modeSelect = Select('NORMAL')
72 # for k, caption in PLAYING_MODES :
73 # self.modeSelect.add(self.createLabel(caption), k)
74 # self.td(self.modeSelect,colspan=3)
75 #
76 # #self.tr()
77 # #self.td(Spacer(*self.spaceSize))
78 #
79 # # choix des wiimotes
80 # self.tr()
81 # self.td(self.createLabel("Wiimote :", self.font))
82 # playerTable = Table()
83 #
84 # self.selectedWiimote = Group(name='selectedWiimote', value=0)
85 # for i in range(self.nwiimotes):
86 # r = Radio(self.selectedWiimote, i)
87 # playerTable.td(r)
88 # playerTable.td(self.createLabel(" %d " % (i+1)))
89 # self.td(playerTable,colspan = 3)
90 #
91 # #self.tr()
92 # #self.td(Spacer(*self.spaceSize))
93 #
94 # # boutons jouer / quitter
95 # self.tr()
96 # self.quitButton = Button(self.createLabel("Quitter"))
97 # self.td(self.quitButton)
98 # self.playButton = Button(self.createLabel("Jouer"), disabled=True)
99 # self.td(self.playButton,colspan=3)
100
101 #self.tr()
102 #self.td(Spacer(500,500))
103
104 @property
105 def selectedWiimoteIndex(self) :
106 return self.selectedWiimote.value
107
108 def _initLocalListeners(self) :
109 self.browseButton.connect(CLICK, self.open_file_browser)
110 self.quitButton.connect(CLICK, self._exitApp)
111 self.playButton.connect(CLICK, self._exitHome)
112
113 def _exitApp(self, data=None) :
114 self.exitApp = True
115 self.send(QUIT)
116
117 def _exitHome(self, data=None) :
118 self.exitApp = False
119 self.send(QUIT)
120
121 def createLabel(self,text,font = None):
122 if font == None :
123 font = self.font
124 w,h = self.font.size(text)
125 label = Label(text,width=w,height=h,font = font)
126 return(label)
127
128 def open_file_browser(self):
129 dlg = FileOpenDialog(self.songPath)
130 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
131 dlg.open()
132
133 def handle_file_browser_closed(self, dlg) :
134 if dlg.value and os.path.isfile(dlg.value):
135 self.remove(self.songTitle)
136 self.songTitle = self.createLabel(os.path.basename(dlg.value))
137 self.td(self.songTitle, col=0, row=1, colspan=2, style={'align':1})
138 self.songFile = dlg.value
139 self.playButton.disabled = False
140
141
142