comparison browser_side/radiocol.py @ 285:4f0c2fea358a

browser_side (plugin radiocol): use the status label to give more information
author souliane <souliane@mailoo.org>
date Tue, 26 Nov 2013 19:51:02 +0100
parents bee4719af9b9
children e76ec07be8e5
comparison
equal deleted inserted replaced
284:bee4719af9b9 285:4f0c2fea358a
20 """ 20 """
21 21
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.VerticalPanel import VerticalPanel 23 from pyjamas.ui.VerticalPanel import VerticalPanel
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel 24 from pyjamas.ui.HorizontalPanel import HorizontalPanel
25 from pyjamas.ui.SimplePanel import SimplePanel
26 from pyjamas.ui.FlexTable import FlexTable 25 from pyjamas.ui.FlexTable import FlexTable
27 from pyjamas.ui.FormPanel import FormPanel 26 from pyjamas.ui.FormPanel import FormPanel
28 from pyjamas.ui.NamedFrame import NamedFrame
29 from pyjamas.ui.Label import Label 27 from pyjamas.ui.Label import Label
30 from pyjamas.ui.Button import Button 28 from pyjamas.ui.Button import Button
31 from pyjamas.ui.ClickListener import ClickHandler 29 from pyjamas.ui.ClickListener import ClickHandler
32 from pyjamas.ui.MouseListener import MouseHandler
33 from pyjamas.ui.Hidden import Hidden 30 from pyjamas.ui.Hidden import Hidden
34 from pyjamas.ui.HTML import HTML 31 from pyjamas.ui.HTML import HTML
35 from pyjamas import Window 32 from pyjamas import Window
36 from pyjamas.Timer import Timer 33 from pyjamas.Timer import Timer
37 from __pyjamas__ import JS 34 from __pyjamas__ import JS
38 35
39 from jid import JID
40 from tools import html_sanitize 36 from tools import html_sanitize
41 from tools import FilterFileUpload 37 from tools import FilterFileUpload
42 from sat_frontends.tools.misc import DEFAULT_MUC 38 from sat_frontends.tools.misc import DEFAULT_MUC
43 39
44 40
77 73
78 74
79 class ControlPanel(FormPanel): 75 class ControlPanel(FormPanel):
80 """Panel used to show controls to add a song, or vote for the current one""" 76 """Panel used to show controls to add a song, or vote for the current one"""
81 77
82 def __init__(self, referee): 78 def __init__(self, parent):
83 FormPanel.__init__(self) 79 FormPanel.__init__(self)
84 self._timer = Timer(notify=self._timeCb)
85 self.setEncoding(FormPanel.ENCODING_MULTIPART) 80 self.setEncoding(FormPanel.ENCODING_MULTIPART)
86 self.setMethod(FormPanel.METHOD_POST) 81 self.setMethod(FormPanel.METHOD_POST)
87 self.setAction("upload_radiocol") 82 self.setAction("upload_radiocol")
88 vPanel = VerticalPanel() 83 self._parent = parent
89 84
90 hPanel = HorizontalPanel() 85 hPanel = HorizontalPanel()
91 hPanel.setSpacing(5) 86 hPanel.setSpacing(5)
92 types = [('audio/ogg', '*.ogg', 'Ogg Vorbis Audio'), 87 types = [('audio/ogg', '*.ogg', 'Ogg Vorbis Audio'),
93 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'), 88 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'),
97 92
98 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) 93 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick"))
99 hPanel.add(self.upload_btn) 94 hPanel.add(self.upload_btn)
100 95
101 self.status = Label() 96 self.status = Label()
97 self.updateStatus()
102 hPanel.add(self.status) 98 hPanel.add(self.status)
103 99
104 vPanel.add(hPanel)
105 100
106 #We need to know the referee 101 #We need to know the referee
107 referee_field = Hidden('referee', referee) 102 referee_field = Hidden('referee', self._parent.referee)
108 vPanel.add(referee_field) 103 hPanel.add(referee_field)
109 104
110 self.add(vPanel) 105 self.add(hPanel)
111 self.addFormHandler(self) 106 self.addFormHandler(self)
112 107
113 def _timeCb(self, timer): 108 def updateStatus(self):
114 self.status.setText('') 109 # TODO: the status should be different if a song is being played or not
110 queue = self._parent.getQueueSize()
111 queue_data = self._parent.queue_data
112 if queue < queue_data[0]:
113 left = queue_data[0] - queue
114 self.status.setText("[we need %d more song%s]" % (left, "s" if left > 1 else ""))
115 elif queue < queue_data[1]:
116 left = queue_data[1] - queue
117 self.status.setText("[%d available spot%s]" % (left, "s" if left > 1 else ""))
118 elif queue >= queue_data[1]:
119 self.status.setText("[The queue is currently full]")
120 self.status.setStyleName('radiocol_status')
115 121
116 def onBtnClick(self): 122 def onBtnClick(self):
117 if self.file_upload.check(): 123 if self.file_upload.check():
118 self.submit() 124 self.submit()
119 self.file_upload.setFilename("") 125 self.file_upload.setFilename("")
128 134
129 def unblockUpload(self): 135 def unblockUpload(self):
130 self.file_upload.setVisible(True) 136 self.file_upload.setVisible(True)
131 self.upload_btn.setEnabled(True) 137 self.upload_btn.setEnabled(True)
132 138
139 def setTemporaryStatus(self, text, style):
140 self.status.setText(text)
141 self.status.setStyleName('radiocol_upload_status_%s' % style)
142 Timer(5000, self.updateStatus)
143
133 def onSubmitComplete(self, event): 144 def onSubmitComplete(self, event):
134 result = event.getResults() 145 result = event.getResults()
135 if result == "OK": 146 if result == "OK":
136 self.status.setText('[Your song has been added to queue]') 147 self.setTemporaryStatus('[Your song has been added to queue]', "ok")
137 self.status.setStyleName('radiocol_upload_status_ok')
138 self._timer.schedule(5000)
139 elif result == "KO": 148 elif result == "KO":
140 self.status.setText('[Something went wrong during your song upload]') 149 self.setTemporaryStatus('[Something went wrong during your song upload]', "ko")
141 self.status.setStyleName('radiocol_upload_status_ko')
142 self._timer.schedule(5000)
143 else: 150 else:
144 Window.alert('Submit error: %s' % result) 151 Window.alert('Submit error: %s' % result)
145 self.status.setText('') 152 self.status.setText('')
146 153
147 154
180 """) 187 """)
181 188
182 189
183 class RadioColPanel(HorizontalPanel, ClickHandler): 190 class RadioColPanel(HorizontalPanel, ClickHandler):
184 191
185 def __init__(self, parent, referee, player_nick, players=None): 192 def __init__(self, parent, referee, player_nick, players, queue_data):
186 HorizontalPanel.__init__(self) 193 HorizontalPanel.__init__(self)
187 ClickHandler.__init__(self) 194 ClickHandler.__init__(self)
188 self._parent = parent 195 self._parent = parent
189 self.referee = referee 196 self.referee = referee
197 self.queue_data = queue_data
190 self.setStyleName("radiocolPanel") 198 self.setStyleName("radiocolPanel")
191 self.setHeight('30%') 199 self.setHeight('30%')
192 200
193 # Now we set up the layout 201 # Now we set up the layout
194 self.left_panel = VerticalPanel() 202 self.left_panel = VerticalPanel()
196 self.left_panel.setHeight('100%') 204 self.left_panel.setHeight('100%')
197 self.add(self.left_panel) 205 self.add(self.left_panel)
198 self.right_panel = VerticalPanel() 206 self.right_panel = VerticalPanel()
199 self.metadata_panel = MetadataPanel() 207 self.metadata_panel = MetadataPanel()
200 self.right_panel.add(self.metadata_panel) 208 self.right_panel.add(self.metadata_panel)
201 self.control_panel = ControlPanel(self.referee) 209 self.control_panel = ControlPanel(self)
202 self.right_panel.add(self.control_panel) 210 self.right_panel.add(self.control_panel)
203 self.add(self.right_panel) 211 self.add(self.right_panel)
204 #self.right_panel.setBorderWidth(1) 212 #self.right_panel.setBorderWidth(1)
205 self.next_songs = [] 213 self.next_songs = []
206 self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)] 214 self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)]
228 """Remove the first song of next songs list 236 """Remove the first song of next songs list
229 should be called when the song is played""" 237 should be called when the song is played"""
230 #FIXME: should check that the song we remove is the one we play 238 #FIXME: should check that the song we remove is the one we play
231 next_song = self.next_songs.pop(0) 239 next_song = self.next_songs.pop(0)
232 self.left_panel.remove(next_song) 240 self.left_panel.remove(next_song)
241
242 def getQueueSize(self):
243 return len(self.left_panel.getChildren())
233 244
234 def radiocolPreload(self, filename, title, artist, album): 245 def radiocolPreload(self, filename, title, artist, album):
235 preloaded = False 246 preloaded = False
236 for player in self.players: 247 for player in self.players:
237 if not player.filename or \ 248 if not player.filename or \
250 for player in self.players: 261 for player in self.players:
251 if player.filename == filename: 262 if player.filename == filename:
252 player.play() 263 player.play()
253 self.popNextSong() 264 self.popNextSong()
254 self.current_player = player 265 self.current_player = player
266 self.control_panel.updateStatus()
255 return 267 return
256 print("WARNING: Song not found in queue, can't play it. This should not happen") 268 print("WARNING: Song not found in queue, can't play it. This should not happen")
257 269
258 def radiocolNoUpload(self): 270 def radiocolNoUpload(self):
259 self.control_panel.blockUpload() 271 self.control_panel.blockUpload()