annotate browser_side/radiocol.py @ 128:2849ec993d89

basic radio collective
author Goffi <goffi@goffi.org>
date Mon, 23 Jan 2012 00:15:19 +0100
parents e19a8de8b3de
children dd0d39ae7d24
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2011 Jérôme Poisson <goffi@goffi.org>
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import pyjd # this is dummy in pyjs
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.FormPanel import FormPanel
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.NamedFrame import NamedFrame
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.FileUpload import FileUpload
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.Label import Label
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.Button import Button
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.ClickListener import ClickHandler
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas.ui.MouseListener import MouseHandler
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
33 from pyjamas.ui.Hidden import Hidden
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
34 from pyjamas.ui.HTML import HTML
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from pyjamas import Window
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from jid import JID
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from tools import html_sanitize
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 class MetadataPanel(VerticalPanel):
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 def __init__(self):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 VerticalPanel.__init__(self)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
45 self.title = Label("title:")
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.artist = Label("artist:")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.album = Label("album:")
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
48 self.add(self.title)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.add(self.artist)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.add(self.album)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 class ControlPanel(FormPanel):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 """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
54
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
55 def __init__(self, referee):
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 FormPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.setEncoding(FormPanel.ENCODING_MULTIPART)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.setMethod(FormPanel.METHOD_POST)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.setAction("upload") # set this as appropriate
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 vPanel = VerticalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 hPanel = HorizontalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 hPanel.setSpacing(5)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.field = FileUpload()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.field.setName("song")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 hPanel.add(self.field)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 hPanel.add(Button("Upload song", getattr(self, "onBtnClick")))
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 vPanel.add(hPanel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
71
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
72 #We need to know the referee
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
73 referee_field = Hidden('referee', referee)
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
74 vPanel.add(referee_field)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.add(vPanel)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.addFormHandler(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def onBtnClick(self):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.submit()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def onSubmit(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 pass
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 def onSubmitComplete(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 result = event.getResults()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 if result == "OK":
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 Window.alert('Your song has been added to queue')
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 elif result == "KO":
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 Window.alert('Something went wrong during your song upload')
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 else:
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 Window.alert('Submit error: %s' % result)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 class RadioColPanel(HorizontalPanel, ClickHandler):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 def __init__(self, parent, referee, player_nick):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 HorizontalPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 ClickHandler.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self._parent = parent
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.referee = referee
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.setStyleName("radiocolPanel")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 # Now we set up the layout
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.left_panel = VerticalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.add(self.left_panel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
106 self.right_panel = VerticalPanel()
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.metadata_panel = MetadataPanel()
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
108 self.right_panel.add(self.metadata_panel)
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
109 self.control_panel = ControlPanel(self.referee)
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
110 self.right_panel.add(self.control_panel)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.add(self.right_panel)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
112 #self.right_panel.setBorderWidth(1)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.left_panel.add(Label("Musique 1"))
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.left_panel.add(Label("Musique 2"))
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
115 self.audio = HTML("")
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
116 self.right_panel.add(self.audio)
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.addClickListener(self)
128
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
120
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
121 def radiocolPreload(self, filename, title, artist, album):
2849ec993d89 basic radio collective
Goffi <goffi@goffi.org>
parents: 127
diff changeset
122 self.audio.setHTML('<audio preload="auto" controls="controls" src="radiocol/%s" />' % html_sanitize(filename))
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123