86d6ab4362e4e05215c1f7d2d5685f1388e5f4c6
[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 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 globals import PLAYING_MODES
21 from songfilebrowser import FileOpenDialog
22 import os.path
23
24 class Home(Table) :
25 """
26 Écran de démarrage de minwii
27 """
28
29 def __init__(self,**params):
30 Table.__init__(self,**params)
31 self.songPath = params.get('songPath', '.')
32 self.nwiimotes = params.get('nwiimotes', 0)
33 self.songFile = None
34 self.spaceSize = (100,100)
35 self.font = pygame.font.Font(None,70)
36 self._fill()
37 self._initLocalListeners()
38
39
40 def _fill(self):
41 self.tr()
42 self.td(Spacer(*self.spaceSize))
43
44
45 # bouton pour browser de fichiers
46 self.tr()
47 self.td(self.createLabel("Chanson :"))
48 self.browseButton = Button(self.createLabel("Choisir..."))
49 self.td(self.browseButton,colspan=2)
50 self.songSwitch = Switch(False)
51 self.td(self.songSwitch)
52
53 self.tr()
54 self.td(Spacer(*self.spaceSize))
55
56 # choix du niveau
57 self.tr()
58 self.td(self.createLabel("Niveau :"))
59 self.modeSelect = Select('EASY')
60 for k, caption in PLAYING_MODES :
61 self.modeSelect.add(self.createLabel(caption), k)
62 self.td(self.modeSelect,colspan=3)
63
64 self.tr()
65 self.td(Spacer(*self.spaceSize))
66
67 # choix des wiimotes
68 self.tr()
69 self.td(self.createLabel("Wiimote :", self.font))
70 playerTable = Table()
71
72 self.selectedWiimote = Group(name='selectedWiimote', value=0)
73 for i in range(self.nwiimotes):
74 r = Radio(self.selectedWiimote, i)
75 playerTable.td(r)
76 playerTable.td(self.createLabel(" %d " % (i+1)))
77 self.td(playerTable,colspan = 3)
78
79 self.tr()
80 self.td(Spacer(*self.spaceSize))
81
82 # boutons jouer / quitter
83 self.tr()
84 self.quitButton = Button(self.createLabel("Quitter"))
85 self.td(self.quitButton)
86 self.playButton = Button(self.createLabel("Jouer"), disabled=True)
87 self.td(self.playButton,colspan=3)
88
89 self.tr()
90 self.td(Spacer(500,500))
91
92 def _initLocalListeners(self) :
93 self.browseButton.connect(CLICK, self.open_file_browser)
94 self.quitButton.connect(CLICK, self._exitApp)
95 self.playButton.connect(CLICK, self._exitHome)
96
97 def _exitApp(self, data=None) :
98 self.returnValue = False
99 self.send(QUIT)
100
101 def _exitHome(self, data=None) :
102 self.returnValue = True
103 self.send(QUIT)
104
105 def createLabel(self,text,font = None):
106 if font == None :
107 font = self.font
108 w,h = self.font.size(text)
109 label = Label(text,width=w,height=h,font = font)
110 return(label)
111
112 def open_file_browser(self):
113 dlg = FileOpenDialog(self.songPath)
114 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
115 dlg.open()
116
117 def handle_file_browser_closed(self, dlg) :
118 if dlg.value and os.path.isfile(dlg.value):
119 self.songFile = dlg.value
120 self.playButton.disabled = False
121
122
123