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