annotate browser_side/radiocol.py @ 127:e19a8de8b3de

radio collective first draft
author Goffi <goffi@goffi.org>
date Sun, 22 Jan 2012 19:38:05 +0100
parents
children 2849ec993d89
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.DockPanel import DockPanel
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
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from pyjamas import Window
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from jid import JID
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from tools import html_sanitize
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
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 class MetadataPanel(VerticalPanel):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def __init__(self):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 VerticalPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.artist = Label("artist:")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.album = Label("album:")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.title = Label("title:")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.add(self.artist)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.add(self.album)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.add(self.title)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class ControlPanel(FormPanel):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 """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
53
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def __init__(self):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 FormPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.setEncoding(FormPanel.ENCODING_MULTIPART)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.setMethod(FormPanel.METHOD_POST)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.setAction("upload") # set this as appropriate
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 #self.setTarget("results")
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)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 results = NamedFrame("results")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 vPanel.add(results)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.add(vPanel)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.addFormHandler(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def onBtnClick(self):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.submit()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def onSubmit(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 pass
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def onSubmitComplete(self, event):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 result = event.getResults()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 if result == "OK":
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 Window.alert('Your song has been added to queue')
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 elif result == "KO":
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 Window.alert('Something went wrong during your song upload')
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 else:
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 Window.alert('Submit error: %s' % result)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 class RadioColPanel(HorizontalPanel, ClickHandler):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def __init__(self, parent, referee, player_nick):
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 HorizontalPanel.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 ClickHandler.__init__(self)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 self._parent = parent
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self.referee = referee
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.setStyleName("radiocolPanel")
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 # Now we set up the layout
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 self.left_panel = VerticalPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.add(self.left_panel)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.right_panel = DockPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.metadata_panel = MetadataPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.right_panel.add(self.metadata_panel, DockPanel.CENTER)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.control_panel = ControlPanel()
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.right_panel.add(self.control_panel, DockPanel.SOUTH)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 self.add(self.right_panel)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.right_panel.setBorderWidth(1)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.left_panel.add(Label("Musique 1"))
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.left_panel.add(Label("Musique 2"))
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.left_panel.add(Label("Musique 3"))
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.left_panel.add(Label("Musique 4"))
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.left_panel.add(Label("Musique 5"))
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)
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120