changeset 218:4e6467efd6bf

browser_side: small improvements for parameters panel - auto-select the first tab - remove the parameters item if there's nothing to display
author souliane <souliane@mailoo.org>
date Sat, 07 Sep 2013 19:54:41 +0200
parents f7ec248192de
children 36673d19c87e
files browser_side/menu.py browser_side/panels.py browser_side/xmlui.py libervia.py libervia.tac
diffstat 5 files changed, 48 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/menu.py	Sun Sep 08 12:34:00 2013 +0200
+++ b/browser_side/menu.py	Sat Sep 07 19:54:41 2013 +0200
@@ -42,30 +42,33 @@
 import dialog
 import re
 
+
 class MenuCmd:
 
     def __init__(self, object, handler):
-        self._object  = object
+        self._object = object
         self._handler = handler
 
     def execute(self):
         handler = getattr(self._object, self._handler)
         handler()
 
+
 class LiberviaMenuBar(MenuBar):
 
     def __init__(self):
         MenuBar.__init__(self, vertical=False)
-    
+
     def doItemAction(self, item, fireCommand):
         MenuBar.doItemAction(self, item, fireCommand)
         if item == self.items[-1] and self.popup:
             self.popup.setPopupPosition(Window.getClientWidth() -
-               self.popup.getOffsetWidth() - 22,
-               self.getAbsoluteTop() +
-               self.getOffsetHeight() - 1)
+                                        self.popup.getOffsetWidth() - 22,
+                                        self.getAbsoluteTop() +
+                                        self.getOffsetHeight() - 1)
             self.popup.addStyleName('menuLastPopup')
 
+
 class AvatarUpload(FormPanel):
 
     def __init__(self, close_cb=None):
@@ -98,18 +101,18 @@
 
     def setCloseCb(self, close_cb):
         self.close_cb = close_cb
-   
+
     def onCloseBtnClick(self):
         if self.close_cb:
             self.close_cb()
         else:
             print ("WARNING: no close method defined")
-    
+
     def onSubmitBtnClick(self):
         self.message.setHTML('<strong>Submitting, please wait...</strong>')
         self.upload_btn.setEnabled(False)
         self.submit()
-    
+
     def onSubmit(self, event):
         pass
 
@@ -119,6 +122,7 @@
             Window.alert('Something went wrong while submitting file')
         self.close_cb()
 
+
 class Menu(SimplePanel):
 
     def __init__(self, host):
@@ -147,27 +151,29 @@
         menu_help = MenuBar(vertical=True)
         menu_help.addItem("Social contract", MenuCmd(self, "onSocialContract"))
         menu_help.addItem("About", MenuCmd(self, "onAbout"))
-    
-        menu_settings = MenuBar(vertical=True)
-        menu_settings.addItem("Parameters", MenuCmd(self, "onParameters"))
-        menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload")) # XXX: temporary, will change when a full profile will be managed in SàT
-        
+
+        self.menu_settings = MenuBar(vertical=True)
+        self.item_params = self.menu_settings.addItem("Parameters",
+                                                      MenuCmd(self, "onParameters"))
+        # XXX: temporary, will change when a full profile will be managed in SàT
+        self.menu_settings.addItem("Upload avatar", MenuCmd(self, "onAvatarUpload"))
+
         menubar = LiberviaMenuBar()
-        
+
         for _name, _icon, _menu in [('General', 'home', menu_general),
                                     ('Contacts', 'social', menu_contacts),
                                     ('Groups', 'social', menu_group),
                                     ('Games', 'games', menu_games)]:
             menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu))
-        
+
         _separator = MenuItem('', None)
         _separator.setStyleName('menuSeparator')
         menubar.addItem(_separator, None)
-        
+
         for _name, _icon, _menu in [('Help', 'help', menu_help),
-                                    ('Settings', 'settings', menu_settings)]:
+                                    ('Settings', 'settings', self.menu_settings)]:
             menubar.addItem(MenuItem(_item_tpl % (_icon, _name), True, _menu))
-        
+
         self.add(menubar)
 
     #General menu
@@ -175,7 +181,6 @@
         web_panel = panels.WebPanel(self.host, "http://www.goffi.org")
         self.host.addTab(web_panel, "Web widget")
 
-
     def onDisconnect(self):
         def confirm_cb(answer):
             if answer:
@@ -252,7 +257,7 @@
     def onRemoveContact(self):
         _dialog = None
         _contacts_list = ListBox()
-       
+
         def secondConfirmCb(confirm):
             if confirm:
                 for contact in _contacts_list.getSelectedValues():
@@ -303,7 +308,7 @@
         _dialog.setHTML('Group discussions')
         _dialog.setWidget(_main_panel)
         _dialog.show()
-    
+
     def onCollectiveRadio(self):
         def onContactsSelected(contacts):
             print("let's go :)")
@@ -326,7 +331,8 @@
 
     def onParameters(self):
         def gotParams(xmlui):
-            # TODO: don't display the dialog if xmlui contains no param node
+            if not xmlui:
+                return
             body = XMLUI(self.host, xmlui)
             _dialog = dialog.GenericDialog("Parameters", body, options=['NO_CLOSE'])
             body.setCloseCb(_dialog.close) 
@@ -334,6 +340,10 @@
             _dialog.show()
         self.host.bridge.call('getParamsUI', gotParams)
 
+    def removeItemParams(self):
+        """Remove the Parameters item from the Settings menu bar."""
+        self.menu_settings.removeItem(self.item_params)
+
     def onAvatarUpload(self):
         body = AvatarUpload()
         _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE'])
--- a/browser_side/panels.py	Sun Sep 08 12:34:00 2013 +0200
+++ b/browser_side/panels.py	Sat Sep 07 19:54:41 2013 +0200
@@ -772,7 +772,7 @@
         AbsolutePanel.__init__(self)
 
         #menu
-        menu = Menu(host)
+        self.menu = Menu(host)
 
         #unibox
         unibox_panel = UniBoxPanel(host)
@@ -796,7 +796,7 @@
         self.tab_panel.selectTab(0)
 
         header = AbsolutePanel()
-        header.add(menu)
+        header.add(self.menu)
         header.add(unibox_panel)
         header.add(status)
         header.setStyleName('header')
--- a/browser_side/xmlui.py	Sun Sep 08 12:34:00 2013 +0200
+++ b/browser_side/xmlui.py	Sat Sep 07 19:54:41 2013 +0200
@@ -147,13 +147,15 @@
             if node.nodeName == "layout":
                 node_type = node.getAttribute('type')
                 if node_type == "tabs":
-                    tab_cont = TabPanel() 
+                    tab_cont = TabPanel()
                     tab_cont.setStyleName('liberviaTabPanel')
                     tab_cont.setHeight('100%')
                     self.__parseChilds(current, node, ['category'], tab_cont)
                     current.append(tab_cont)
                     if isinstance(current, CellPanel):
                         current.setCellHeight(tab_cont, '100%')
+                    if len(tab_cont.getChildren()) > 0:
+                        tab_cont.selectTab(0)
                 elif node_type == "vertical":
                     self.__parseElems(node, current)
                 elif node_type == "pairs":
--- a/libervia.py	Sun Sep 08 12:34:00 2013 +0200
+++ b/libervia.py	Sat Sep 07 19:54:41 2013 +0200
@@ -287,6 +287,7 @@
 
         #it's time to fill the page
         self.bridge.call('getContacts', self._getContactsCB)
+        self.bridge.call('getParamsUI', self._getParamsUICB)
         self.bridge_signals.call('getSignals', self._getSignalsCB)
         #We want to know our own jid
         self.bridge.call('getProfileJid', self._getProfileJidCB)
@@ -345,6 +346,11 @@
         elif name == 'chatStateReceived':
             self._chatStateReceivedCb(*args)
 
+    def _getParamsUICB(self, xmlui):
+        """Hide the parameters item if there's nothing to display"""
+        if not xmlui:
+            self.panel.menu.removeItemParams()
+
     def _ownBlogsFills(self, mblogs):
         #put our own microblogs in cache, then fill all panels with them
         for publisher in mblogs:
--- a/libervia.tac	Sun Sep 08 12:34:00 2013 +0200
+++ b/libervia.tac	Sat Sep 07 19:54:41 2013 +0200
@@ -371,11 +371,14 @@
                     params = cat.getElementsByTagName("param")
                     params_list = [param.getAttribute("name") for param in params]
                     self.authorized_params[cat.getAttribute("name")] = params_list
-            return d
+            if self.authorized_params:
+                return d
+            else:
+                return None
         d.addCallback(setAuthorizedParams)
 
         from sat.tools.xml_tools import paramsXml2xmlUI
-        d.addCallback(lambda d: paramsXml2xmlUI(d))
+        d.addCallback(lambda d: paramsXml2xmlUI(d) if d else "")
 
         self.sat_host.bridge.getParams(SECURITY_LIMIT, profile, callback=d.callback, errback=d.errback)
         return d