Changement des photos de la guitare et du violon.
[minwii.git] / src / app / 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 Select
14 from pgu.gui import CLICK
15 from pgu.gui import QUIT
16 from pgu.gui import CHANGE
17 import pygame
18 from gui.constants import reversedReadabilityDict, modeDict
19 from songfilebrowser import FileOpenDialog
20 import os.path
21
22 class Home(Table) :
23 """
24 Écran de démarrage de minwii
25 """
26
27 def __init__(self,**params):
28 Table.__init__(self,**params)
29 self.songPath = params.get('songPath', '.')
30 self.songFile = None
31 self.spaceSize = (100,100)
32 self.font = pygame.font.Font(None,70)
33 self._fill()
34 self._initLocalListeners()
35
36
37 def _fill(self):
38 self.tr()
39 self.td(Spacer(*self.spaceSize))
40
41
42 # bouton pour browser de fichiers
43 self.tr()
44 self.td(self.createLabel("Chanson :"))
45 self.browseButton = Button(self.createLabel("Choisir..."))
46 self.td(self.browseButton,colspan=2)
47 self.songSwitch = Switch(False)
48 self.td(self.songSwitch)
49
50 self.tr()
51 self.td(Spacer(*self.spaceSize))
52
53 # choix du niveau
54 self.tr()
55 self.td(self.createLabel("Niveau :"))
56 self.modeSelect = Select('easy')
57 for key in modeDict.keys() :
58 self.modeSelect.add(self.createLabel(reversedReadabilityDict[key]),key)
59 self.td(self.modeSelect,colspan=3)
60
61 self.tr()
62 self.td(Spacer(*self.spaceSize))
63
64 # choix des wiimotes
65 self.tr()
66 self.td(self.createLabel("Joueurs :", self.font))
67 playerTable = Table()
68 self.activeWiimoteSwitches = []
69 for i in range(4):
70 s = Switch(False)
71 playerTable.td(s)
72 playerTable.td(self.createLabel(" %d " % (i+1)))
73 self.activeWiimoteSwitches.append(s)
74 self.td(playerTable,colspan = 3)
75
76 self.tr()
77 self.td(Spacer(*self.spaceSize))
78
79 # boutons jouer / quitter
80 self.tr()
81 self.quitButton = Button(self.createLabel("Quitter"))
82 self.td(self.quitButton)
83 self.playButton = Button(self.createLabel("Jouer"))
84 self.td(self.playButton,colspan=3)
85
86 self.tr()
87 self.td(Spacer(500,500))
88
89 def _initLocalListeners(self) :
90 self.browseButton.connect(CLICK, self.open_file_browser)
91 self.quitButton.connect(CLICK, self._exitHome)
92
93 def _exitHome(self, data=None) :
94 self.send(QUIT)
95
96 def createLabel(self,text,font = None):
97 if font == None :
98 font = self.font
99 w,h = self.font.size(text)
100 label = Label(text,width=w,height=h,font = font)
101 return(label)
102
103 def open_file_browser(self):
104 dlg = FileOpenDialog(self.songPath)
105 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
106 dlg.open()
107
108 def handle_file_browser_closed(self, dlg) :
109 if dlg.value and os.path.isfile(dlg.value):
110 self.songFile = dlg.value
111
112
113