diff src/browser/sat_browser/panels.py @ 510:db3436c85fb1

browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
author souliane <souliane@mailoo.org>
date Thu, 21 Aug 2014 16:44:39 +0200
parents ec3f30253040
children 3d8e8f693576
line wrap: on
line diff
--- a/src/browser/sat_browser/panels.py	Thu Aug 21 16:18:51 2014 +0200
+++ b/src/browser/sat_browser/panels.py	Thu Aug 21 16:44:39 2014 +0200
@@ -52,6 +52,7 @@
 import jid
 import html_tools
 import base_panels
+import base_menu
 import card_game
 import radiocol
 import menu
@@ -1039,30 +1040,40 @@
         self.display.setHTML(addURLToText(status))
 
 
+class PresenceStatusMenuBar(base_widget.WidgetMenuBar):
+    def __init__(self, parent):
+        styles = {'menu_bar': 'presence-button'}
+        base_widget.WidgetMenuBar.__init__(self, None, parent.host, styles=styles)
+        self.button = self.addCategory(u"◉", u"◉", '')
+        for presence, presence_i18n in C.PRESENCE.items():
+            html = u'<span class="%s">◉</span> %s' % (contact.buildPresenceStyle(presence), presence_i18n)
+            self.addMenuItem([u"◉", presence], [u"◉", html], '', base_menu.MenuCmd(self, 'changePresenceCb', presence), asHTML=True)
+        self.parent_panel = parent
+
+    def changePresenceCb(self, presence):
+        """Callback to notice the backend of a new presence set by the user.
+        @param presence (str): the new presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
+        """
+        self.host.bridge.call('setStatus', None, presence, self.parent_panel.status_panel.status)
+
+    @classmethod
+    def getCategoryHTML(cls, menu_name_i18n, type_):
+        return menu_name_i18n
+
+
 class PresenceStatusPanel(HorizontalPanel, ClickHandler):
 
     def __init__(self, host, presence="", status=""):
         self.host = host
         HorizontalPanel.__init__(self, Width='100%')
-        self.presence_button = Label(u"◉")
-        self.presence_button.setStyleName("presence-button")
+        self.menu = PresenceStatusMenuBar(self)
         self.status_panel = StatusPanel(host, status=status)
         self.setPresence(presence)
-        entries = {}
-        for value in C.PRESENCE.keys():
-            entries.update({C.PRESENCE[value]: {"value": value}})
-
-        def callback(sender, key):
-            self.setPresence(entries[key]["value"])  # order matters
-            self.host.send([("STATUS", None)], self.status_panel.status)
-
-        self.presence_list = base_panels.PopupMenuPanel(entries, callback=callback, style={"menu": "gwt-ListBox"})
-        self.presence_list.registerClickSender(self.presence_button)
 
         panel = HorizontalPanel()
-        panel.add(self.presence_button)
+        panel.add(self.menu)
         panel.add(self.status_panel)
-        panel.setCellVerticalAlignment(self.presence_button, 'baseline')
+        panel.setCellVerticalAlignment(self.menu, 'baseline')
         panel.setCellVerticalAlignment(self.status_panel, 'baseline')
         panel.setStyleName("marginAuto")
         self.add(panel)
@@ -1082,7 +1093,7 @@
 
     def setPresence(self, presence):
         self._presence = presence
-        contact.setPresenceStyle(self.presence_button, self._presence)
+        contact.setPresenceStyle(self.menu.button, self._presence)
 
     def setStatus(self, status):
         self.status_panel.setContent({'text': status})