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