changeset 326:36927be51481

browser_side: fixed the behavior regarding "Enable unibox" parameter: - unibox is disabled by default - dynamic refresh of the concerned widgets - use the generic method refresh instead of setUniBox
author souliane <souliane@mailoo.org>
date Tue, 07 Jan 2014 15:36:18 +0100
parents d07b54fdc60a
children 6126bd24e7dd
files browser_side/panels.py libervia.py libervia.tac
diffstat 3 files changed, 68 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Tue Jan 07 15:39:16 2014 +0100
+++ b/browser_side/panels.py	Tue Jan 07 15:36:18 2014 +0100
@@ -70,12 +70,11 @@
         self.setStyleName('uniBoxPanel')
         self.unibox = None
 
-    def setUniBox(self, enable):
-        """Enable or disable the unibox widget.
-        @param enable: boolean
-        @return: UniBox instance or None if disabled
-        """
-        if enable:
+    def refresh(self):
+        """Enable or disable this panel. Contained widgets are created when necessary."""
+        enable = self.host.params_ui['unibox']['value']
+        self.setVisible(enable)
+        if enable and not self.unibox:
             self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
             self.button.setTitle('Open the rich text editor')
             self.button.addStyleName('uniBoxButton')
@@ -85,12 +84,6 @@
             self.setCellWidth(self.unibox, '100%')
             self.button.addClickListener(self.openRichTextEditor)
             self.unibox.addKey("@@: ")
-            return self.unibox
-        else:
-            if self.unibox:
-                self.remove(self.unibox)
-                self.unibox = None
-        return None
 
     def openRichTextEditor(self):
         """Open the rich text editor."""
@@ -624,16 +617,15 @@
         self.vpanel = VerticalPanel()
         self.vpanel.setStyleName('microblogPanel')
         self.setWidget(self.vpanel)
-        self.setUniBox(self.host.uni_box)
 
-    def setUniBox(self, enable=False):
-        """Enable or disable the unibox. If it is disabled,
+    def refresh(self):
+        """Refresh the display of this widget. If the unibox is disabled,
         display the 'New message' button on top of the panel"""
-        if enable:
-            return
+        enable_button = self.host.uni_box is None
         if hasattr(self, 'new_button'):
-            self.new_button.setVisible(True)
-        else:
+            self.new_button.setVisible(enable_button)
+            return
+        if enable_button:
             def addBox():
                 self.new_button.setVisible(False)
                 data = {'id': str(time()),
@@ -1040,16 +1032,6 @@
         self.addStyleName('chatPanel')
         self.setWidget(self.vpanel)
         self.state_machine = ChatStateMachine(self.host, str(self.target))
-        self.setUniBox(self.host.uni_box)
-
-    def setUniBox(self, enable):
-        """Enable or disable the unibox. If it is disabled,
-        display a message box below the panel."""
-        if enable:
-            return
-        message_box = MessageBox(self.host)
-        message_box.onSelectedChange(self)
-        self.vpanel.add(message_box)
 
     """def doDetachChildren(self):
         #We need to force the use of a panel subclass method here,
@@ -1075,10 +1057,20 @@
         return _new_panel
 
     def refresh(self):
-        """Refresh the display of this widget."""
+        """Refresh the display of this widget. If the unibox is disabled,
+        add a message box at the bottom of the panel"""
         self.host.contact_panel.setContactMessageWaiting(self.target.bare, False)
         self.content_scroll.scrollToBottom()
 
+        enable_box = self.host.uni_box is None
+        if hasattr(self, 'message_box'):
+            self.message_box.setVisible(enable_box)
+            return
+        if enable_box:
+            self.message_box = MessageBox(self.host)
+            self.message_box.onSelectedChange(self)
+            self.vpanel.add(self.message_box)
+
     def matchEntity(self, entity):
         """
         @param entity: target jid as a string or JID instance.
@@ -1308,10 +1300,6 @@
         ideal_height = Window.getClientHeight() - tab_bar_h
         self.setHeight("%s%s" % (ideal_height, "px"))
 
-    def setUniBoxPanel(self, enable):
-        """Enable or disable the unibox
-        @param enable: boolean
-        @return: UniBox instance or None if disabled
-        """
-        self.unibox_panel.setVisible(enable)
-        return self.unibox_panel.setUniBox(enable)
+    def refresh(self):
+        """Refresh the main panel"""
+        self.unibox_panel.refresh()
--- a/libervia.py	Tue Jan 07 15:39:16 2014 +0100
+++ b/libervia.py	Tue Jan 07 15:36:18 2014 +0100
@@ -186,6 +186,13 @@
         self._register.call('isRegistered', self._isRegisteredCB)
         self.initialised = False
         self.init_cache = []  # used to cache events until initialisation is done
+        # define here the parameters that have an incidende to UI refresh
+        self.params_ui = {"unibox": {"name": Const.ENABLE_UNIBOX_PARAM,
+                                     "category": Const.ENABLE_UNIBOX_KEY,
+                                     "cast": lambda value: value == 'true',
+                                     "value": None
+                                     }
+                          }
 
     def addSelectedListener(self, callback):
         self._selected_listeners.add(callback)
@@ -264,11 +271,16 @@
         except KeyError:
             print ('WARNING: trying to remove a non registered Widget:', wid.getDebugName())
 
-    def _setUniBox(self, enable):
-        """Enable or disable the unibox widget.
-        @param enable: boolean
-        """
-        self.uni_box = self.panel.setUniBoxPanel(enable == 'true')
+    def refresh(self):
+        """Refresh the general display."""
+        self.panel.refresh()
+        if self.params_ui['unibox']['value']:
+            self.uni_box = self.panel.unibox_panel.unibox
+        else:
+            self.uni_box = None
+        for lib_wid in self.libervia_widgets:
+            lib_wid.refresh()
+        self.resize()
 
     def addTab(self, label, wid, select=True):
         """Create a new tab and eventually add a widget in
@@ -328,13 +340,18 @@
             self._defaultDomain = "libervia.org"
 
         self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb))
+        self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
 
-        def unibox_cb(enable):
-            self._setUniBox(enable)
-            self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
-            self.resize()  # resize after all the UI elements have been attached
+        # get ui params and refresh the display
+        count = 0  # used to do something similar to DeferredList
 
-        self.bridge.call('asyncGetParamA', unibox_cb, Const.ENABLE_UNIBOX_PARAM, Const.ENABLE_UNIBOX_KEY)
+        def params_ui_cb(param, value=None):
+            count += 1
+            refresh = count == len(self.params_ui)
+            self._paramUpdate(param['name'], value, param['category'], refresh)
+        for param in self.params_ui:
+            self.bridge.call('asyncGetParamA', lambda value: params_ui_cb(self.params_ui[param], value),
+                             self.params_ui[param]['name'], self.params_ui[param]['category'])
 
     def _tryAutoConnect(self):
         """This method retrieve the eventual URL parameters to auto-connect the user."""
@@ -395,6 +412,8 @@
             self._newMessageCb(*args)
         elif name == 'presenceUpdate':
             self._presenceUpdateCb(*args)
+        elif name == 'paramUpdate':
+            self._paramUpdate(*args)
         elif name == 'roomJoined':
             self._roomJoinedCb(*args)
         elif name == 'roomLeft':
@@ -785,6 +804,18 @@
     def _newAlert(self, message, title, alert_type):
         dialog.InfoDialog(title, message).show()
 
+    def _paramUpdate(self, name, value, category, refresh=True):
+        """This is called when the paramUpdate signal is received, but also
+        during initialization when the UI parameters values are retrieved.
+        @param refresh: set to True to refresh the general UI
+        """
+        for param in self.params_ui:
+            if name == self.params_ui[param]['name']:
+                self.params_ui[param]['value'] = self.params_ui[param]['cast'](value)
+                if refresh:
+                    self.refresh()
+                break
+
     def sendError(self, errorData):
         dialog.InfoDialog("Error while sending message",
                           "Your message can't be sent", Width="400px").center()
--- a/libervia.tac	Tue Jan 07 15:39:16 2014 +0100
+++ b/libervia.tac	Tue Jan 07 15:36:18 2014 +0100
@@ -728,7 +728,7 @@
         <params>
         <individual>
         <category name="%(category_name)s" label="%(category_label)s">
-            <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" security="0"/>
+            <param name="%(param_name)s" label="%(param_label)s" value="false" type="bool" security="0"/>
          </category>
         </individual>
         </params>
@@ -955,7 +955,7 @@
         self.bridge.register("connectionError", self.signal_handler.connectionError)
         self.bridge.register("actionResult", self.action_handler.actionResultCb)
         #core
-        for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert']:
+        for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']:
             self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
         #plugins
         for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',