diff browser_side/panels.py @ 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 0b7934e75e76
children 9c6be29c714a
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()