qq bidouilles de l'ordre de l'expérimentation.
[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 globals import PLAYING_MODES
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 k, caption in PLAYING_MODES :
58 self.modeSelect.add(self.createLabel(caption), k)
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"), disabled=True)
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._exitApp)
92 self.playButton.connect(CLICK, self._exitHome)
93
94 def _exitApp(self, data=None) :
95 self.returnValue = False
96 self.send(QUIT)
97
98 def _exitHome(self, data=None) :
99 self.returnValue = True
100 self.send(QUIT)
101
102 def createLabel(self,text,font = None):
103 if font == None :
104 font = self.font
105 w,h = self.font.size(text)
106 label = Label(text,width=w,height=h,font = font)
107 return(label)
108
109 def open_file_browser(self):
110 dlg = FileOpenDialog(self.songPath)
111 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
112 dlg.open()
113
114 def handle_file_browser_closed(self, dlg) :
115 if dlg.value and os.path.isfile(dlg.value):
116 self.songFile = dlg.value
117 self.playButton.disabled = False
118
119
120