Mercurial > libervia-web
annotate browser_side/radiocol.py @ 286:e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 27 Nov 2013 13:33:56 +0100 |
parents | 4f0c2fea358a |
children | 7a1dc69112b8 |
rev | line source |
---|---|
127 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
127 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
127 | 23 from pyjamas.ui.VerticalPanel import VerticalPanel |
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
25 from pyjamas.ui.FlexTable import FlexTable |
127 | 26 from pyjamas.ui.FormPanel import FormPanel |
27 from pyjamas.ui.Label import Label | |
28 from pyjamas.ui.Button import Button | |
29 from pyjamas.ui.ClickListener import ClickHandler | |
128 | 30 from pyjamas.ui.Hidden import Hidden |
31 from pyjamas.ui.HTML import HTML | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
32 from pyjamas.ui.CaptionPanel import CaptionPanel |
127 | 33 from pyjamas import Window |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
34 from pyjamas.Timer import Timer |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
35 from __pyjamas__ import JS |
127 | 36 |
37 from tools import html_sanitize | |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
38 from tools import FilterFileUpload |
284
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
39 from sat_frontends.tools.misc import DEFAULT_MUC |
127 | 40 |
41 | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
42 class MetadataPanel(FlexTable): |
127 | 43 |
44 def __init__(self): | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
45 FlexTable.__init__(self) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
46 title_lbl = Label("title:") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
47 title_lbl.setStyleName('radiocol_metadata_lbl') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
48 artist_lbl = Label("artist:") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
49 artist_lbl.setStyleName('radiocol_metadata_lbl') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
50 album_lbl = Label("album:") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
51 album_lbl.setStyleName('radiocol_metadata_lbl') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
52 self.title = Label("") |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
53 self.title.setStyleName('radiocol_metadata') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
54 self.artist = Label("") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
55 self.artist.setStyleName('radiocol_metadata') |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
56 self.album = Label("") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
57 self.album.setStyleName('radiocol_metadata') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
58 self.setWidget(0, 0, title_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
59 self.setWidget(1, 0, artist_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
60 self.setWidget(2, 0, album_lbl) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
61 self.setWidget(0, 1, self.title) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
62 self.setWidget(1, 1, self.artist) |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
63 self.setWidget(2, 1, self.album) |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
64 self.setStyleName("radiocol_metadata_pnl") |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
65 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
66 def setTitle(self, title): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
67 self.title.setText(title) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
68 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
69 def setArtist(self, artist): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
70 self.artist.setText(artist) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
71 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
72 def setAlbum(self, album): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
73 self.album.setText(album) |
127 | 74 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
75 |
127 | 76 class ControlPanel(FormPanel): |
77 """Panel used to show controls to add a song, or vote for the current one""" | |
78 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
79 def __init__(self, parent): |
127 | 80 FormPanel.__init__(self) |
81 self.setEncoding(FormPanel.ENCODING_MULTIPART) | |
82 self.setMethod(FormPanel.METHOD_POST) | |
151
a159cc29b556
server side: file upload is now more generic:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
83 self.setAction("upload_radiocol") |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
84 self._parent = parent |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
85 vPanel = VerticalPanel() |
127 | 86 |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
87 types = [('audio/ogg', '*.ogg', 'Ogg Vorbis Audio'), |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
88 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'), |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
89 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex')] |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
90 self.file_upload = FilterFileUpload("song", 5, types) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
91 vPanel.add(self.file_upload) |
127 | 92 |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
93 hPanel = HorizontalPanel() |
130 | 94 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick")) |
95 hPanel.add(self.upload_btn) | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
96 self.status = Label() |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
97 self.updateStatus() |
130 | 98 hPanel.add(self.status) |
128 | 99 #We need to know the referee |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
100 referee_field = Hidden('referee', self._parent.referee) |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
101 hPanel.add(referee_field) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
102 vPanel.add(hPanel) |
127 | 103 |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
104 self.add(vPanel) |
127 | 105 self.addFormHandler(self) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
106 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
107 def updateStatus(self): |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
108 # TODO: the status should be different if a song is being played or not |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
109 queue = self._parent.getQueueSize() |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
110 queue_data = self._parent.queue_data |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
111 if queue < queue_data[0]: |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
112 left = queue_data[0] - queue |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
113 self.status.setText("[we need %d more song%s]" % (left, "s" if left > 1 else "")) |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
114 elif queue < queue_data[1]: |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
115 left = queue_data[1] - queue |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
116 self.status.setText("[%d available spot%s]" % (left, "s" if left > 1 else "")) |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
117 elif queue >= queue_data[1]: |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
118 self.status.setText("[The queue is currently full]") |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
119 self.status.setStyleName('radiocol_status') |
127 | 120 |
121 def onBtnClick(self): | |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
122 if self.file_upload.check(): |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
123 self.submit() |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
124 self.file_upload.setFilename("") |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
125 self.status.setText('[Submitting, please wait...]') |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
126 |
127 | 127 def onSubmit(self, event): |
128 pass | |
129 | |
130 | 130 def blockUpload(self): |
131 self.file_upload.setVisible(False) | |
132 self.upload_btn.setEnabled(False) | |
133 | |
134 def unblockUpload(self): | |
135 self.file_upload.setVisible(True) | |
136 self.upload_btn.setEnabled(True) | |
137 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
138 def setTemporaryStatus(self, text, style): |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
139 self.status.setText(text) |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
140 self.status.setStyleName('radiocol_upload_status_%s' % style) |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
141 Timer(5000, self.updateStatus) |
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
142 |
127 | 143 def onSubmitComplete(self, event): |
144 result = event.getResults() | |
145 if result == "OK": | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
146 self.setTemporaryStatus('[Your song has been added to queue]', "ok") |
127 | 147 elif result == "KO": |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
148 self.setTemporaryStatus('[Something went wrong during your song upload]', "ko") |
127 | 149 else: |
150 Window.alert('Submit error: %s' % result) | |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
275
diff
changeset
|
151 self.status.setText('') |
127 | 152 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
153 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
154 class Player(HTML): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
155 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
156 def __init__(self, player_id, metadata_panel): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
157 HTML.__init__(self) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
158 self._id = player_id |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
159 self.metadata = metadata_panel |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
160 self.title = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
161 self.artist = "" |
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
162 self.album = "" |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
163 self.filename = None |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
164 self.played = False # True when song is playing/played, become False on preload |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
165 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
166 def preload(self, filename, title, artist, album): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
167 """preload the song but doesn't play it""" |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
168 self.filename = filename |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
169 self.title = title |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
170 self.artist = artist |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
171 self.album = album |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
172 self.played = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
173 self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename))) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
174 print "preloading %s in %s" % (title, self._id) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
175 |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
176 def play(self): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
177 """actually play the song""" |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
178 self.played = True |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
179 self.metadata.setTitle(self.title) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
180 self.metadata.setArtist(self.artist) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
181 self.metadata.setAlbum(self.album) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
182 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
183 JS(""" |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
184 var player = top.document.getElementById(this._id); |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
185 player.play(); |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
186 """) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
187 |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
188 |
127 | 189 class RadioColPanel(HorizontalPanel, ClickHandler): |
190 | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
191 def __init__(self, parent, referee, player_nick, players, queue_data): |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
192 # We need to set it here and not in the CSS :( |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
193 HorizontalPanel.__init__(self, Height="90px") |
127 | 194 ClickHandler.__init__(self) |
195 self._parent = parent | |
196 self.referee = referee | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
197 self.queue_data = queue_data |
127 | 198 self.setStyleName("radiocolPanel") |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
199 |
127 | 200 # Now we set up the layout |
201 self.metadata_panel = MetadataPanel() | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
202 self.add(CaptionPanel("Now playing", self.metadata_panel)) |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
203 self.playlist_panel = VerticalPanel() |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
204 self.add(CaptionPanel("Songs queue", self.playlist_panel)) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
205 self.control_panel = ControlPanel(self) |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
206 self.add(CaptionPanel("Controls", self.control_panel)) |
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
207 |
130 | 208 self.next_songs = [] |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
209 self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)] |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
210 self.current_player = None |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
211 for player in self.players: |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
212 self.add(player) |
127 | 213 self.addClickListener(self) |
130 | 214 |
284
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
215 help_msg = HTML("""- This radio plays Ogg Vorbis files.<br /> |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
216 - What's that? I only know MP3!<br /> |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
217 - Click <a style="color: red;">here</a> if you need some support :) |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
218 """) |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
219 help_msg.setStyleName('chatTextInfo-link') |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
220 help_msg.addClickListener(lambda: self._parent.host.bridge.call('joinMUC', None, DEFAULT_MUC, self._parent.nick)) |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
221 self._parent.content.add(help_msg) |
bee4719af9b9
browser_side (plugin radiocol): info message when you start the radiocol
souliane <souliane@mailoo.org>
parents:
283
diff
changeset
|
222 |
130 | 223 def pushNextSong(self, title): |
224 """Add a song to the left panel's next songs queue""" | |
225 next_song = Label(title) | |
226 next_song.setStyleName("radiocol_next_song") | |
227 self.next_songs.append(next_song) | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
228 self.playlist_panel.append(next_song) |
130 | 229 |
230 def popNextSong(self): | |
231 """Remove the first song of next songs list | |
232 should be called when the song is played""" | |
233 #FIXME: should check that the song we remove is the one we play | |
234 next_song = self.next_songs.pop(0) | |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
235 self.playlist_panel.remove(next_song) |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
236 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
237 def getQueueSize(self): |
286
e76ec07be8e5
browser_side (plugin radiocol): the UI uses CaptionPanel
souliane <souliane@mailoo.org>
parents:
285
diff
changeset
|
238 return len(self.playlist_panel.getChildren()) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
239 |
128 | 240 def radiocolPreload(self, filename, title, artist, album): |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
241 preloaded = False |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
242 for player in self.players: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
243 if not player.filename or \ |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
244 (player.played and player != self.current_player): |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
245 #if player has no file loaded, or it has already played its song |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
246 #we use it to preload the next one |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
247 player.preload(filename, title, artist, album) |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
248 preloaded = True |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
249 break |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
250 if not preloaded: |
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
251 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once") |
130 | 252 else: |
253 self.pushNextSong(title) | |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
165
diff
changeset
|
254 |
130 | 255 def radiocolPlay(self, filename): |
256 for player in self.players: | |
257 if player.filename == filename: | |
258 player.play() | |
259 self.popNextSong() | |
260 self.current_player = player | |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
284
diff
changeset
|
261 self.control_panel.updateStatus() |
130 | 262 return |
263 print("WARNING: Song not found in queue, can't play it. This should not happen") | |
127 | 264 |
130 | 265 def radiocolNoUpload(self): |
266 self.control_panel.blockUpload() | |
129
dd0d39ae7d24
RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents:
128
diff
changeset
|
267 |
130 | 268 def radiocolUploadOk(self): |
269 self.control_panel.unblockUpload() | |
270 | |
271 def radiocolSongRejected(self, reason): | |
272 Window.alert("Song rejected: %s" % reason) |