view 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
line wrap: on
line source

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Libervia: a Salut à Toi frontend
Copyright (C) 2011  Jérôme Poisson <goffi@goffi.org>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import pyjd # this is dummy in pyjs
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.SimplePanel import SimplePanel
from pyjamas.ui.FormPanel import FormPanel
from pyjamas.ui.DockPanel import DockPanel
from pyjamas.ui.NamedFrame import NamedFrame
from pyjamas.ui.FileUpload import FileUpload
from pyjamas.ui.Label import Label
from pyjamas.ui.Button import Button
from pyjamas.ui.ClickListener import ClickHandler
from pyjamas.ui.MouseListener import MouseHandler
from pyjamas import Window

from jid import JID
from tools import html_sanitize


class MetadataPanel(VerticalPanel):

    def __init__(self):
        VerticalPanel.__init__(self)
        self.artist = Label("artist:")
        self.album = Label("album:")
        self.title = Label("title:")
        self.add(self.artist)
        self.add(self.album)
        self.add(self.title)

class ControlPanel(FormPanel):
    """Panel used to show controls to add a song, or vote for the current one"""

    def __init__(self):
        FormPanel.__init__(self)
        self.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.setMethod(FormPanel.METHOD_POST)
        self.setAction("upload") # set this as appropriate
        #self.setTarget("results")
        vPanel = VerticalPanel()

        hPanel = HorizontalPanel()
        hPanel.setSpacing(5)
        self.field = FileUpload()
        self.field.setName("song")
        hPanel.add(self.field)

        hPanel.add(Button("Upload song", getattr(self, "onBtnClick")))

        vPanel.add(hPanel)

        results = NamedFrame("results")
        vPanel.add(results)

        self.add(vPanel)
        self.addFormHandler(self)

    def onBtnClick(self):
        self.submit()
    
    def onSubmit(self, event):
        pass

    def onSubmitComplete(self, event):
        result = event.getResults()
        if result == "OK":
            Window.alert('Your song has been added to queue')
        elif result == "KO":
            Window.alert('Something went wrong during your song upload')
        else:
            Window.alert('Submit error: %s' % result)

class RadioColPanel(HorizontalPanel, ClickHandler):

    def __init__(self, parent, referee, player_nick):
        HorizontalPanel.__init__(self)
        ClickHandler.__init__(self)
        self._parent = parent
        self.referee = referee
        self.setStyleName("radiocolPanel")
        
        # Now we set up the layout
        self.left_panel = VerticalPanel()
        self.add(self.left_panel)
        self.right_panel = DockPanel()
        self.metadata_panel = MetadataPanel()
        self.right_panel.add(self.metadata_panel, DockPanel.CENTER)
        self.control_panel = ControlPanel()
        self.right_panel.add(self.control_panel, DockPanel.SOUTH)
        self.add(self.right_panel)
        self.right_panel.setBorderWidth(1)
        self.left_panel.add(Label("Musique 1"))
        self.left_panel.add(Label("Musique 2"))
        self.left_panel.add(Label("Musique 3"))
        self.left_panel.add(Label("Musique 4"))
        self.left_panel.add(Label("Musique 5"))

        
        self.addClickListener(self)