Mercurial > libervia-web
comparison browser_side/radiocol.py @ 130:6576c5a90060
Working Radio Collective \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 Jan 2012 02:56:21 +0100 |
parents | dd0d39ae7d24 |
children | ddfcc4cb6cee |
comparison
equal
deleted
inserted
replaced
129:dd0d39ae7d24 | 130:6576c5a90060 |
---|---|
85 self.setAction("upload") # set this as appropriate | 85 self.setAction("upload") # set this as appropriate |
86 vPanel = VerticalPanel() | 86 vPanel = VerticalPanel() |
87 | 87 |
88 hPanel = HorizontalPanel() | 88 hPanel = HorizontalPanel() |
89 hPanel.setSpacing(5) | 89 hPanel.setSpacing(5) |
90 self.field = FileUpload() | 90 self.file_upload = FileUpload() |
91 self.field.setName("song") | 91 self.file_upload.setName("song") |
92 hPanel.add(self.field) | 92 hPanel.add(self.file_upload) |
93 | 93 |
94 hPanel.add(Button("Upload song", getattr(self, "onBtnClick"))) | 94 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) |
95 hPanel.add(self.upload_btn) | |
95 | 96 |
96 self.status = Label() | 97 self.status = Label() |
98 hPanel.add(self.status) | |
97 | 99 |
98 vPanel.add(hPanel) | 100 vPanel.add(hPanel) |
99 | 101 |
100 #We need to know the referee | 102 #We need to know the referee |
101 referee_field = Hidden('referee', referee) | 103 referee_field = Hidden('referee', referee) |
111 self.submit() | 113 self.submit() |
112 | 114 |
113 def onSubmit(self, event): | 115 def onSubmit(self, event): |
114 pass | 116 pass |
115 | 117 |
118 def blockUpload(self): | |
119 self.file_upload.setVisible(False) | |
120 self.upload_btn.setEnabled(False) | |
121 | |
122 def unblockUpload(self): | |
123 self.file_upload.setVisible(True) | |
124 self.upload_btn.setEnabled(True) | |
125 | |
126 | |
116 def onSubmitComplete(self, event): | 127 def onSubmitComplete(self, event): |
117 result = event.getResults() | 128 result = event.getResults() |
118 if result == "OK": | 129 if result == "OK": |
119 self.status.setText('Your song has been added to queue') | 130 self.status.setText('[Your song has been added to queue]') |
120 self.status.setStyleName('radiocol_upload_status_ok') | 131 self.status.setStyleName('radiocol_upload_status_ok') |
121 self._timer.schedule(5000) | 132 self._timer.schedule(5000) |
122 elif result == "KO": | 133 elif result == "KO": |
123 self.status.setText('Something went wrong during your song upload') | 134 self.status.setText('[Something went wrong during your song upload]') |
124 self.status.setStyleName('radiocol_upload_status_ko') | 135 self.status.setStyleName('radiocol_upload_status_ko') |
125 else: | 136 else: |
126 Window.alert('Submit error: %s' % result) | 137 Window.alert('Submit error: %s' % result) |
127 | 138 |
128 class Player(HTML): | 139 class Player(HTML): |
181 self.right_panel.add(self.metadata_panel) | 192 self.right_panel.add(self.metadata_panel) |
182 self.control_panel = ControlPanel(self.referee) | 193 self.control_panel = ControlPanel(self.referee) |
183 self.right_panel.add(self.control_panel) | 194 self.right_panel.add(self.control_panel) |
184 self.add(self.right_panel) | 195 self.add(self.right_panel) |
185 #self.right_panel.setBorderWidth(1) | 196 #self.right_panel.setBorderWidth(1) |
186 self.next_song_1 = Label() | 197 self.next_songs = [] |
187 self.next_song_1.setStyleName("radiocol_next_song") | |
188 self.next_song_2 = Label() | |
189 self.next_song_2.setStyleName("radiocol_next_song") | |
190 self.left_panel.add(self.next_song_1) | |
191 self.left_panel.add(self.next_song_2) | |
192 self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)] | 198 self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)] |
193 self.current_player = None | 199 self.current_player = None |
194 for player in self.players: | 200 for player in self.players: |
195 self.right_panel.add(player) | 201 self.right_panel.add(player) |
196 self.addClickListener(self) | 202 self.addClickListener(self) |
203 | |
204 def pushNextSong(self, title): | |
205 """Add a song to the left panel's next songs queue""" | |
206 next_song = Label(title) | |
207 next_song.setStyleName("radiocol_next_song") | |
208 self.next_songs.append(next_song) | |
209 self.left_panel.append(next_song) | |
210 | |
211 def popNextSong(self): | |
212 """Remove the first song of next songs list | |
213 should be called when the song is played""" | |
214 #FIXME: should check that the song we remove is the one we play | |
215 next_song = self.next_songs.pop(0) | |
216 self.left_panel.remove(next_song) | |
197 | 217 |
198 def radiocolPreload(self, filename, title, artist, album): | 218 def radiocolPreload(self, filename, title, artist, album): |
199 self.next_song_1.setText(self.next_song_2.getText()) | |
200 self.next_song_2.setText(title) | |
201 preloaded = False | 219 preloaded = False |
202 for player in self.players: | 220 for player in self.players: |
203 if not player.filename or \ | 221 if not player.filename or \ |
204 (player.played and player != self.current_player): | 222 (player.played and player != self.current_player): |
205 #if player has no file loaded, or it has already played its song | 223 #if player has no file loaded, or it has already played its song |
207 player.preload(filename, title, artist, album) | 225 player.preload(filename, title, artist, album) |
208 preloaded = True | 226 preloaded = True |
209 break | 227 break |
210 if not preloaded: | 228 if not preloaded: |
211 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once") | 229 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once") |
212 | 230 else: |
213 | 231 self.pushNextSong(title) |
232 | |
233 def radiocolPlay(self, filename): | |
234 for player in self.players: | |
235 if player.filename == filename: | |
236 player.play() | |
237 self.popNextSong() | |
238 self.current_player = player | |
239 return | |
240 print("WARNING: Song not found in queue, can't play it. This should not happen") | |
241 | |
242 def radiocolNoUpload(self): | |
243 self.control_panel.blockUpload() | |
244 | |
245 def radiocolUploadOk(self): | |
246 self.control_panel.unblockUpload() | |
247 | |
248 def radiocolSongRejected(self, reason): | |
249 Window.alert("Song rejected: %s" % reason) | |
250 |