changeset 285:4f0c2fea358a

browser_side (plugin radiocol): use the status label to give more information
author souliane <souliane@mailoo.org>
date Tue, 26 Nov 2013 19:51:02 +0100
parents bee4719af9b9
children e76ec07be8e5
files browser_side/panels.py browser_side/radiocol.py libervia.py public/libervia.css
diffstat 4 files changed, 50 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Mon Nov 25 21:04:09 2013 +0100
+++ b/browser_side/panels.py	Tue Nov 26 19:51:02 2013 +0100
@@ -1029,7 +1029,7 @@
         self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml')))
         self.content_scroll.scrollToBottom()
 
-    def startGame(self, game_type, referee, players, waiting=False):
+    def startGame(self, game_type, waiting, referee, players, *args):
         """Configure the chat window to start a game"""
         classes = {"Tarot": CardPanel, "RadioCol": RadioColPanel}
         if game_type not in classes.keys():
@@ -1042,7 +1042,7 @@
         if hasattr(self, attr):
             return
         print ("%s Game Started \o/" % game_type)
-        panel = classes[game_type](self, referee, self.nick, players)
+        panel = classes[game_type](self, referee, self.nick, players, *args)
         setattr(self, attr, panel)
         self.vpanel.insert(panel, 0)
         self.vpanel.setCellHeight(panel, panel.getHeight())
--- a/browser_side/radiocol.py	Mon Nov 25 21:04:09 2013 +0100
+++ b/browser_side/radiocol.py	Tue Nov 26 19:51:02 2013 +0100
@@ -22,21 +22,17 @@
 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.FlexTable import FlexTable
 from pyjamas.ui.FormPanel import FormPanel
-from pyjamas.ui.NamedFrame import NamedFrame
 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.ui.Hidden import Hidden
 from pyjamas.ui.HTML import HTML
 from pyjamas import Window
 from pyjamas.Timer import Timer
 from __pyjamas__ import JS
 
-from jid import JID
 from tools import html_sanitize
 from tools import FilterFileUpload
 from sat_frontends.tools.misc import DEFAULT_MUC
@@ -79,13 +75,12 @@
 class ControlPanel(FormPanel):
     """Panel used to show controls to add a song, or vote for the current one"""
 
-    def __init__(self, referee):
+    def __init__(self, parent):
         FormPanel.__init__(self)
-        self._timer = Timer(notify=self._timeCb)
         self.setEncoding(FormPanel.ENCODING_MULTIPART)
         self.setMethod(FormPanel.METHOD_POST)
         self.setAction("upload_radiocol")
-        vPanel = VerticalPanel()
+        self._parent = parent
 
         hPanel = HorizontalPanel()
         hPanel.setSpacing(5)
@@ -99,19 +94,30 @@
         hPanel.add(self.upload_btn)
 
         self.status = Label()
+        self.updateStatus()
         hPanel.add(self.status)
 
-        vPanel.add(hPanel)
 
         #We need to know the referee
-        referee_field = Hidden('referee', referee)
-        vPanel.add(referee_field)
+        referee_field = Hidden('referee', self._parent.referee)
+        hPanel.add(referee_field)
 
-        self.add(vPanel)
+        self.add(hPanel)
         self.addFormHandler(self)
 
-    def _timeCb(self, timer):
-        self.status.setText('')
+    def updateStatus(self):
+        # TODO: the status should be different if a song is being played or not
+        queue = self._parent.getQueueSize()
+        queue_data = self._parent.queue_data
+        if queue < queue_data[0]:
+            left = queue_data[0] - queue
+            self.status.setText("[we need %d more song%s]" % (left, "s" if left > 1 else ""))
+        elif queue < queue_data[1]:
+            left = queue_data[1] - queue
+            self.status.setText("[%d available spot%s]" % (left, "s" if left > 1 else ""))
+        elif queue >= queue_data[1]:
+                self.status.setText("[The queue is currently full]")
+        self.status.setStyleName('radiocol_status')
 
     def onBtnClick(self):
         if self.file_upload.check():
@@ -130,16 +136,17 @@
         self.file_upload.setVisible(True)
         self.upload_btn.setEnabled(True)
 
+    def setTemporaryStatus(self, text, style):
+        self.status.setText(text)
+        self.status.setStyleName('radiocol_upload_status_%s' % style)
+        Timer(5000, self.updateStatus)
+
     def onSubmitComplete(self, event):
         result = event.getResults()
         if result == "OK":
-            self.status.setText('[Your song has been added to queue]')
-            self.status.setStyleName('radiocol_upload_status_ok')
-            self._timer.schedule(5000)
+            self.setTemporaryStatus('[Your song has been added to queue]', "ok")
         elif result == "KO":
-            self.status.setText('[Something went wrong during your song upload]')
-            self.status.setStyleName('radiocol_upload_status_ko')
-            self._timer.schedule(5000)
+            self.setTemporaryStatus('[Something went wrong during your song upload]', "ko")
         else:
             Window.alert('Submit error: %s' % result)
             self.status.setText('')
@@ -182,11 +189,12 @@
 
 class RadioColPanel(HorizontalPanel, ClickHandler):
 
-    def __init__(self, parent, referee, player_nick, players=None):
+    def __init__(self, parent, referee, player_nick, players, queue_data):
         HorizontalPanel.__init__(self)
         ClickHandler.__init__(self)
         self._parent = parent
         self.referee = referee
+        self.queue_data = queue_data
         self.setStyleName("radiocolPanel")
         self.setHeight('30%')
 
@@ -198,7 +206,7 @@
         self.right_panel = VerticalPanel()
         self.metadata_panel = MetadataPanel()
         self.right_panel.add(self.metadata_panel)
-        self.control_panel = ControlPanel(self.referee)
+        self.control_panel = ControlPanel(self)
         self.right_panel.add(self.control_panel)
         self.add(self.right_panel)
         #self.right_panel.setBorderWidth(1)
@@ -231,6 +239,9 @@
         next_song = self.next_songs.pop(0)
         self.left_panel.remove(next_song)
 
+    def getQueueSize(self):
+        return len(self.left_panel.getChildren())
+
     def radiocolPreload(self, filename, title, artist, album):
         preloaded = False
         for player in self.players:
@@ -252,6 +263,7 @@
                 player.play()
                 self.popNextSong()
                 self.current_player = player
+                self.control_panel.updateStatus()
                 return
         print("WARNING: Song not found in queue, can't play it. This should not happen")
 
--- a/libervia.py	Mon Nov 25 21:04:09 2013 +0100
+++ b/libervia.py	Tue Nov 26 19:51:02 2013 +0100
@@ -369,9 +369,9 @@
         elif name == 'newAlert':
             self._newAlert(*args)
         elif name == 'tarotGamePlayers':
-            self._tarotGameStartedCb(*args, waiting=True)
+            self._tarotGameStartedCb(True, *args)
         elif name == 'tarotGameStarted':
-            self._tarotGameStartedCb(*args)
+            self._tarotGameStartedCb(False, *args)
         elif name == 'tarotGameNew' or \
              name == 'tarotGameChooseContrat' or \
              name == 'tarotGameShowCards' or \
@@ -381,9 +381,9 @@
              name == 'tarotGameScore':
             self._tarotGameGenericCb(name, args[0], args[1:])
         elif name == 'radiocolPlayers':
-            self._radioColStartedCb(*args, waiting=True)
+            self._radioColStartedCb(True, *args)
         elif name == 'radiocolStarted':
-            self._radioColStartedCb(*args)
+            self._radioColStartedCb(False, *args)
         elif name == 'radiocolPreload':
             self._radioColGenericCb(name, args[0], args[1:])
         elif name == 'radiocolPlay':
@@ -639,20 +639,20 @@
             if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 lib_wid.userLeft(user_nick, user_data)
 
-    def _tarotGameStartedCb(self, room_jid_s, referee, players, waiting=False):
+    def _tarotGameStartedCb(self, waiting, room_jid_s, referee, players):
         for lib_wid in self.libervia_widgets:
             if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
-                lib_wid.startGame("Tarot", referee, players, waiting)
+                lib_wid.startGame("Tarot", waiting, referee, players)
 
     def _tarotGameGenericCb(self, event_name, room_jid_s, args):
         for lib_wid in self.libervia_widgets:
             if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 getattr(lib_wid.getGame("Tarot"), event_name)(*args)
 
-    def _radioColStartedCb(self, room_jid_s, referee, players, waiting=False):
+    def _radioColStartedCb(self, waiting, room_jid_s, referee, players, queue_data):
         for lib_wid in self.libervia_widgets:
             if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
-                lib_wid.startGame("RadioCol", referee, players, waiting)
+                lib_wid.startGame("RadioCol", waiting, referee, players, queue_data)
 
     def _radioColGenericCb(self, event_name, room_jid_s, args):
         for lib_wid in self.libervia_widgets:
--- a/public/libervia.css	Mon Nov 25 21:04:09 2013 +0100
+++ b/public/libervia.css	Tue Nov 26 19:51:02 2013 +0100
@@ -962,6 +962,13 @@
     font-style:italic;
 }
 
+.radiocol_status {
+    margin-left: 10px;
+    margin-right: 10px;
+    font-weight: bold;
+	color: black;
+}
+
 .radiocol_upload_status_ok {
     margin-left: 10px;
     margin-right: 10px;