fichiers .ini dans les svn:ignore.
[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 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('NORMAL')
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 @property
93 def selectedWiimoteIndex(self) :
94 return self.selectedWiimote.value
95
96 def _initLocalListeners(self) :
97 self.browseButton.connect(CLICK, self.open_file_browser)
98 self.quitButton.connect(CLICK, self._exitApp)
99 self.playButton.connect(CLICK, self._exitHome)
100
101 def _exitApp(self, data=None) :
102 self.exitApp = True
103 self.send(QUIT)
104
105 def _exitHome(self, data=None) :
106 self.exitApp = False
107 self.send(QUIT)
108
109 def createLabel(self,text,font = None):
110 if font == None :
111 font = self.font
112 w,h = self.font.size(text)
113 label = Label(text,width=w,height=h,font = font)
114 return(label)
115
116 def open_file_browser(self):
117 dlg = FileOpenDialog(self.songPath)
118 dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
119 dlg.open()
120
121 def handle_file_browser_closed(self, dlg) :
122 if dlg.value and os.path.isfile(dlg.value):
123 self.songFile = dlg.value
124 self.playButton.disabled = False
125
126
127