diff browser_side/panels.py @ 309:05e264e96a1c

browser_side: make unibox optional
author souliane <souliane@mailoo.org>
date Sun, 29 Dec 2013 23:07:28 +0100
parents 44b46db7dfef
children 5d11ec1f2c22
line wrap: on
line diff
--- a/browser_side/panels.py	Fri Dec 27 13:59:06 2013 +0100
+++ b/browser_side/panels.py	Sun Dec 29 23:07:28 2013 +0100
@@ -71,17 +71,26 @@
         HorizontalPanel.__init__(self)
         self.host = host
         self.setStyleName('uniBoxPanel')
-
-        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')
-        self.add(self.button)
+        self.unibox = None
 
-        self.unibox = UniBox(host)
-        self.add(self.unibox)
-        self.setCellWidth(self.unibox, '100%')
-
-        self.button.addClickListener(self.openRichTextEditor)
+    def setUniBox(self, enable):
+        """Enable or disable the unibox widget.
+        @param enable: boolean
+        """
+        if enable:
+            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')
+            self.add(self.button)
+            self.unibox = UniBox(self.host)
+            self.add(self.unibox)
+            self.setCellWidth(self.unibox, '100%')
+            self.button.addClickListener(self.openRichTextEditor)
+            self.unibox.addKey("@@: ")
+        else:
+            if self.unibox:
+                self.remove(self.unibox)
+                self.unibox = None
 
     def openRichTextEditor(self):
         """Open the rich text editor."""
@@ -365,7 +374,7 @@
         self.comments = mblog_entry.comments
         self.pub_data = (mblog_entry.hash[0], mblog_entry.hash[1], mblog_entry.id)
 
-        self.editable_content = [mblog_entry.xhtml, const._SYNTAX_XHTML] if mblog_entry.xhtml else [mblog_entry.content, None]
+        self.editable_content = [mblog_entry.xhtml, const.SYNTAX_XHTML] if mblog_entry.xhtml else [mblog_entry.content, None]
 
         self.panel = FlowPanel()
         self.panel.setStyleName('mb_entry')
@@ -1148,8 +1157,7 @@
         self.menu = Menu(host)
 
         # unibox
-        unibox_panel = UniBoxPanel(host)
-        self.host.setUniBox(unibox_panel.unibox)
+        self.unibox_panel = UniBoxPanel(host)
 
         # status bar
         status = host.status_panel
@@ -1170,7 +1178,7 @@
 
         header = AbsolutePanel()
         header.add(self.menu)
-        header.add(unibox_panel)
+        header.add(self.unibox_panel)
         header.add(status)
         header.setStyleName('header')
         self.add(header)