annotate browser_side/radiocol.py @ 275:a763b2ac5d41

bridge + browser_side: bridge signals for games and their callbacks: - added radiocolPlayers and tarotGamePlayers to get the list of players - added roomLeft to remove the muc from the host's room list - display symbols to identify the players in a muc - factorization of ChatPanel.startGame
author souliane <souliane@mailoo.org>
date Thu, 21 Nov 2013 16:13:14 +0100
parents 63e9b680d3e7
children 0eba1c4f9c6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 151
diff changeset
6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org>
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.VerticalPanel import VerticalPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.SimplePanel import SimplePanel
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
26 from pyjamas.ui.FlexTable import FlexTable
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.FormPanel import FormPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.NamedFrame import NamedFrame
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.FileUpload import FileUpload
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.Label import Label
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.Button import Button
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas.ui.ClickListener import ClickHandler
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from pyjamas.ui.MouseListener import MouseHandler
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
34 from pyjamas.ui.Hidden import Hidden
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
35 from pyjamas.ui.HTML import HTML
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from pyjamas import Window
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
37 from pyjamas.Timer import Timer
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
38 from __pyjamas__ import JS
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from jid import JID
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 from tools import html_sanitize
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
44 class MetadataPanel(FlexTable):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def __init__(self):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
47 FlexTable.__init__(self)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
48 title_lbl = Label("title:")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
49 title_lbl.setStyleName('radiocol_metadata_lbl')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
50 artist_lbl = Label("artist:")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
51 artist_lbl.setStyleName('radiocol_metadata_lbl')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
52 album_lbl = Label("album:")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
53 album_lbl.setStyleName('radiocol_metadata_lbl')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
54 self.title = Label("")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
55 self.title.setStyleName('radiocol_metadata')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
56 self.artist = Label("")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
57 self.artist.setStyleName('radiocol_metadata')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
58 self.album = Label("")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
59 self.album.setStyleName('radiocol_metadata')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
60 self.setWidget(0, 0, title_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
61 self.setWidget(1, 0, artist_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
62 self.setWidget(2, 0, album_lbl)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
63 self.setWidget(0, 1, self.title)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
64 self.setWidget(1, 1, self.artist)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
65 self.setWidget(2, 1, self.album)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
66 self.setStyleName("radiocol_metadata_pnl")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
67
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
68 def setTitle(self, title):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
69 self.title.setText(title)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
70
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
71 def setArtist(self, artist):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
72 self.artist.setText(artist)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
73
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
74 def setAlbum(self, album):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
75 self.album.setText(album)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
77
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 class ControlPanel(FormPanel):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 """Panel used to show controls to add a song, or vote for the current one"""
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
81 def __init__(self, referee):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 FormPanel.__init__(self)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
83 self._timer = Timer(notify=self._timeCb)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.setEncoding(FormPanel.ENCODING_MULTIPART)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.setMethod(FormPanel.METHOD_POST)
151
a159cc29b556 server side: file upload is now more generic:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
86 self.setAction("upload_radiocol")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 vPanel = VerticalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 hPanel = HorizontalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 hPanel.setSpacing(5)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
91 self.file_upload = FileUpload()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
92 self.file_upload.setName("song")
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
93 hPanel.add(self.file_upload)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
95 self.upload_btn = Button("Upload song", getattr(self, "onBtnClick"))
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
96 hPanel.add(self.upload_btn)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
98 self.status = Label()
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
99 hPanel.add(self.status)
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
100
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 vPanel.add(hPanel)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
102
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
103 #We need to know the referee
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
104 referee_field = Hidden('referee', referee)
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
105 vPanel.add(referee_field)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.add(vPanel)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.addFormHandler(self)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
109
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
110 def _timeCb(self, timer):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
111 self.status.setText('')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def onBtnClick(self):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.submit()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
115
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 def onSubmit(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 pass
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
119 def blockUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
120 self.file_upload.setVisible(False)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
121 self.upload_btn.setEnabled(False)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
122
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
123 def unblockUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
124 self.file_upload.setVisible(True)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
125 self.upload_btn.setEnabled(True)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
126
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 def onSubmitComplete(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 result = event.getResults()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 if result == "OK":
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
130 self.status.setText('[Your song has been added to queue]')
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
131 self.status.setStyleName('radiocol_upload_status_ok')
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
132 self._timer.schedule(5000)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 elif result == "KO":
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
134 self.status.setText('[Something went wrong during your song upload]')
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
135 self.status.setStyleName('radiocol_upload_status_ko')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 else:
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 Window.alert('Submit error: %s' % result)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
139
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
140 class Player(HTML):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
141
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
142 def __init__(self, player_id, metadata_panel):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
143 HTML.__init__(self)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
144 self._id = player_id
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
145 self.metadata = metadata_panel
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
146 self.title = ""
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
147 self.artist = ""
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
148 self.album = ""
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
149 self.filename = None
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
150 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
151
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
152 def preload(self, filename, title, artist, album):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
153 """preload the song but doesn't play it"""
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
154 self.filename = filename
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
155 self.title = title
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
156 self.artist = artist
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
157 self.album = album
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
158 self.played = False
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
159 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
160 print "preloading %s in %s" % (title, self._id)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
161
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
162 def play(self):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
163 """actually play the song"""
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
164 self.played = True
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
165 self.metadata.setTitle(self.title)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
166 self.metadata.setArtist(self.artist)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
167 self.metadata.setAlbum(self.album)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
168
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
169 JS("""
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
170 var player = top.document.getElementById(this._id);
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
171 player.play();
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
172 """)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
173
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
174
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175 class RadioColPanel(HorizontalPanel, ClickHandler):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 243
diff changeset
177 def __init__(self, parent, referee, player_nick, players=None):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 HorizontalPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 ClickHandler.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self._parent = parent
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.referee = referee
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 self.setStyleName("radiocolPanel")
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
183 self.setHeight('30%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
184
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185 # Now we set up the layout
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 self.left_panel = VerticalPanel()
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
187 self.left_panel.setStyleName("radiocol_left_panel")
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
188 self.left_panel.setHeight('100%')
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.add(self.left_panel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
190 self.right_panel = VerticalPanel()
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191 self.metadata_panel = MetadataPanel()
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
192 self.right_panel.add(self.metadata_panel)
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
193 self.control_panel = ControlPanel(self.referee)
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
194 self.right_panel.add(self.control_panel)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self.add(self.right_panel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
196 #self.right_panel.setBorderWidth(1)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
197 self.next_songs = []
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
198 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
199 self.current_player = None
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
200 for player in self.players:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
201 self.right_panel.add(player)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self.addClickListener(self)
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
203
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
204 def pushNextSong(self, title):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
205 """Add a song to the left panel's next songs queue"""
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
206 next_song = Label(title)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
207 next_song.setStyleName("radiocol_next_song")
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
208 self.next_songs.append(next_song)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
209 self.left_panel.append(next_song)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
210
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
211 def popNextSong(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
212 """Remove the first song of next songs list
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
213 should be called when the song is played"""
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
214 #FIXME: should check that the song we remove is the one we play
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
215 next_song = self.next_songs.pop(0)
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
216 self.left_panel.remove(next_song)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
217
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
218 def radiocolPreload(self, filename, title, artist, album):
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
219 preloaded = False
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
220 for player in self.players:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
221 if not player.filename or \
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
222 (player.played and player != self.current_player):
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
223 #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
224 #we use it to preload the next one
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
225 player.preload(filename, title, artist, album)
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
226 preloaded = True
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
227 break
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
228 if not preloaded:
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
229 print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once")
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
230 else:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
231 self.pushNextSong(title)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 165
diff changeset
232
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
233 def radiocolPlay(self, filename):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
234 for player in self.players:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
235 if player.filename == filename:
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
236 player.play()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
237 self.popNextSong()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
238 self.current_player = player
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
239 return
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
240 print("WARNING: Song not found in queue, can't play it. This should not happen")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
241
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
242 def radiocolNoUpload(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
243 self.control_panel.blockUpload()
129
dd0d39ae7d24 RadioCol: song preloading + fonctionnal players
Goffi <goffi@goffi.org>
parents: 128
diff changeset
244
130
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
245 def radiocolUploadOk(self):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
246 self.control_panel.unblockUpload()
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
247
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
248 def radiocolSongRejected(self, reason):
6576c5a90060 Working Radio Collective \o/
Goffi <goffi@goffi.org>
parents: 129
diff changeset
249 Window.alert("Song rejected: %s" % reason)