comparison browser_side/radiocol.py @ 243:63e9b680d3e7

browser_side, blog: better PEP8 compliance
author souliane <souliane@mailoo.org>
date Tue, 15 Oct 2013 17:19:03 +0200
parents 9763dec220ed
children a763b2ac5d41
comparison
equal deleted inserted replaced
242:a25aa882e09a 243:63e9b680d3e7
17 17
18 You should have received a copy of the GNU Affero General Public License 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/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
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 25 from pyjamas.ui.SimplePanel import SimplePanel
26 from pyjamas.ui.FlexTable import FlexTable 26 from pyjamas.ui.FlexTable import FlexTable
27 from pyjamas.ui.FormPanel import FormPanel 27 from pyjamas.ui.FormPanel import FormPanel
43 43
44 class MetadataPanel(FlexTable): 44 class MetadataPanel(FlexTable):
45 45
46 def __init__(self): 46 def __init__(self):
47 FlexTable.__init__(self) 47 FlexTable.__init__(self)
48 title_lbl = Label("title:") 48 title_lbl = Label("title:")
49 title_lbl.setStyleName('radiocol_metadata_lbl') 49 title_lbl.setStyleName('radiocol_metadata_lbl')
50 artist_lbl = Label("artist:") 50 artist_lbl = Label("artist:")
51 artist_lbl.setStyleName('radiocol_metadata_lbl') 51 artist_lbl.setStyleName('radiocol_metadata_lbl')
52 album_lbl = Label("album:") 52 album_lbl = Label("album:")
53 album_lbl.setStyleName('radiocol_metadata_lbl') 53 album_lbl.setStyleName('radiocol_metadata_lbl')
54 self.title = Label("") 54 self.title = Label("")
55 self.title.setStyleName('radiocol_metadata') 55 self.title.setStyleName('radiocol_metadata')
56 self.artist = Label("") 56 self.artist = Label("")
57 self.artist.setStyleName('radiocol_metadata') 57 self.artist.setStyleName('radiocol_metadata')
58 self.album = Label("") 58 self.album = Label("")
59 self.album.setStyleName('radiocol_metadata') 59 self.album.setStyleName('radiocol_metadata')
60 self.setWidget(0,0,title_lbl) 60 self.setWidget(0, 0, title_lbl)
61 self.setWidget(1,0,artist_lbl) 61 self.setWidget(1, 0, artist_lbl)
62 self.setWidget(2,0,album_lbl) 62 self.setWidget(2, 0, album_lbl)
63 self.setWidget(0,1,self.title) 63 self.setWidget(0, 1, self.title)
64 self.setWidget(1,1,self.artist) 64 self.setWidget(1, 1, self.artist)
65 self.setWidget(2,1,self.album) 65 self.setWidget(2, 1, self.album)
66 self.setStyleName("radiocol_metadata_pnl") 66 self.setStyleName("radiocol_metadata_pnl")
67 67
68 def setTitle(self, title): 68 def setTitle(self, title):
69 self.title.setText(title) 69 self.title.setText(title)
70 70
71 def setArtist(self, artist): 71 def setArtist(self, artist):
72 self.artist.setText(artist) 72 self.artist.setText(artist)
73 73
74 def setAlbum(self, album): 74 def setAlbum(self, album):
75 self.album.setText(album) 75 self.album.setText(album)
76
76 77
77 class ControlPanel(FormPanel): 78 class ControlPanel(FormPanel):
78 """Panel used to show controls to add a song, or vote for the current one""" 79 """Panel used to show controls to add a song, or vote for the current one"""
79 80
80 def __init__(self, referee): 81 def __init__(self, referee):
96 97
97 self.status = Label() 98 self.status = Label()
98 hPanel.add(self.status) 99 hPanel.add(self.status)
99 100
100 vPanel.add(hPanel) 101 vPanel.add(hPanel)
101 102
102 #We need to know the referee 103 #We need to know the referee
103 referee_field = Hidden('referee', referee) 104 referee_field = Hidden('referee', referee)
104 vPanel.add(referee_field) 105 vPanel.add(referee_field)
105 106
106 self.add(vPanel) 107 self.add(vPanel)
107 self.addFormHandler(self) 108 self.addFormHandler(self)
108 109
109 def _timeCb(self, timer): 110 def _timeCb(self, timer):
110 self.status.setText('') 111 self.status.setText('')
111 112
112 def onBtnClick(self): 113 def onBtnClick(self):
113 self.submit() 114 self.submit()
114 115
115 def onSubmit(self, event): 116 def onSubmit(self, event):
116 pass 117 pass
117 118
118 def blockUpload(self): 119 def blockUpload(self):
119 self.file_upload.setVisible(False) 120 self.file_upload.setVisible(False)
120 self.upload_btn.setEnabled(False) 121 self.upload_btn.setEnabled(False)
121 122
122 def unblockUpload(self): 123 def unblockUpload(self):
123 self.file_upload.setVisible(True) 124 self.file_upload.setVisible(True)
124 self.upload_btn.setEnabled(True) 125 self.upload_btn.setEnabled(True)
125
126 126
127 def onSubmitComplete(self, event): 127 def onSubmitComplete(self, event):
128 result = event.getResults() 128 result = event.getResults()
129 if result == "OK": 129 if result == "OK":
130 self.status.setText('[Your song has been added to queue]') 130 self.status.setText('[Your song has been added to queue]')
134 self.status.setText('[Something went wrong during your song upload]') 134 self.status.setText('[Something went wrong during your song upload]')
135 self.status.setStyleName('radiocol_upload_status_ko') 135 self.status.setStyleName('radiocol_upload_status_ko')
136 else: 136 else:
137 Window.alert('Submit error: %s' % result) 137 Window.alert('Submit error: %s' % result)
138 138
139
139 class Player(HTML): 140 class Player(HTML):
140 141
141 def __init__(self, player_id, metadata_panel): 142 def __init__(self, player_id, metadata_panel):
142 HTML.__init__(self) 143 HTML.__init__(self)
143 self._id = player_id 144 self._id = player_id
144 self.metadata = metadata_panel 145 self.metadata = metadata_panel
145 self.title="" 146 self.title = ""
146 self.artist="" 147 self.artist = ""
147 self.album="" 148 self.album = ""
148 self.filename = None 149 self.filename = None
149 self.played = False #True when song is playing/played, become False on preload 150 self.played = False # True when song is playing/played, become False on preload
150 151
151 def preload(self, filename, title, artist, album): 152 def preload(self, filename, title, artist, album):
152 """preload the song but doesn't play it""" 153 """preload the song but doesn't play it"""
153 self.filename = filename 154 self.filename = filename
154 self.title = title 155 self.title = title
155 self.artist = artist 156 self.artist = artist
156 self.album = album 157 self.album = album
157 self.played = False 158 self.played = False
158 self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename))) 159 self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename)))
159 print "preloading %s in %s" % (title, self._id) 160 print "preloading %s in %s" % (title, self._id)
160 161
161 def play(self): 162 def play(self):
162 """actually play the song""" 163 """actually play the song"""
163 self.played = True 164 self.played = True
164 self.metadata.setTitle(self.title) 165 self.metadata.setTitle(self.title)
165 self.metadata.setArtist(self.artist) 166 self.metadata.setArtist(self.artist)
167 168
168 JS(""" 169 JS("""
169 var player = top.document.getElementById(this._id); 170 var player = top.document.getElementById(this._id);
170 player.play(); 171 player.play();
171 """) 172 """)
172
173 173
174 174
175 class RadioColPanel(HorizontalPanel, ClickHandler): 175 class RadioColPanel(HorizontalPanel, ClickHandler):
176 176
177 def __init__(self, parent, referee, player_nick): 177 def __init__(self, parent, referee, player_nick):
179 ClickHandler.__init__(self) 179 ClickHandler.__init__(self)
180 self._parent = parent 180 self._parent = parent
181 self.referee = referee 181 self.referee = referee
182 self.setStyleName("radiocolPanel") 182 self.setStyleName("radiocolPanel")
183 self.setHeight('30%') 183 self.setHeight('30%')
184 184
185 # Now we set up the layout 185 # Now we set up the layout
186 self.left_panel = VerticalPanel() 186 self.left_panel = VerticalPanel()
187 self.left_panel.setStyleName("radiocol_left_panel") 187 self.left_panel.setStyleName("radiocol_left_panel")
188 self.left_panel.setHeight('100%') 188 self.left_panel.setHeight('100%')
189 self.add(self.left_panel) 189 self.add(self.left_panel)
212 """Remove the first song of next songs list 212 """Remove the first song of next songs list
213 should be called when the song is played""" 213 should be called when the song is played"""
214 #FIXME: should check that the song we remove is the one we play 214 #FIXME: should check that the song we remove is the one we play
215 next_song = self.next_songs.pop(0) 215 next_song = self.next_songs.pop(0)
216 self.left_panel.remove(next_song) 216 self.left_panel.remove(next_song)
217 217
218 def radiocolPreload(self, filename, title, artist, album): 218 def radiocolPreload(self, filename, title, artist, album):
219 preloaded = False 219 preloaded = False
220 for player in self.players: 220 for player in self.players:
221 if not player.filename or \ 221 if not player.filename or \
222 (player.played and player != self.current_player): 222 (player.played and player != self.current_player):
227 break 227 break
228 if not preloaded: 228 if not preloaded:
229 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")
230 else: 230 else:
231 self.pushNextSong(title) 231 self.pushNextSong(title)
232 232
233 def radiocolPlay(self, filename): 233 def radiocolPlay(self, filename):
234 for player in self.players: 234 for player in self.players:
235 if player.filename == filename: 235 if player.filename == filename:
236 player.play() 236 player.play()
237 self.popNextSong() 237 self.popNextSong()
245 def radiocolUploadOk(self): 245 def radiocolUploadOk(self):
246 self.control_panel.unblockUpload() 246 self.control_panel.unblockUpload()
247 247
248 def radiocolSongRejected(self, reason): 248 def radiocolSongRejected(self, reason):
249 Window.alert("Song rejected: %s" % reason) 249 Window.alert("Song rejected: %s" % reason)
250