diff browser_side/base_panels.py @ 346:82f9e92379b0

browser_side: move TitlePanel from richtext.py to base_panels.py
author souliane <souliane@mailoo.org>
date Fri, 07 Feb 2014 20:08:28 +0100
parents 44491e963eee
children f1ba38043d78
line wrap: on
line diff
--- a/browser_side/base_panels.py	Wed Feb 05 16:37:31 2014 +0100
+++ b/browser_side/base_panels.py	Fri Feb 07 20:08:28 2014 +0100
@@ -26,6 +26,7 @@
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.PopupPanel import PopupPanel
 from pyjamas.ui.StackPanel import StackPanel
+from pyjamas.ui.TextArea import TextArea
 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT
 from pyjamas import DOM
 
@@ -35,6 +36,7 @@
 from tools import html_sanitize, inlineRoot
 
 from sat_frontends.tools.strings import addURLToText
+from sat.core.i18n import _
 
 
 class ChatText(HTMLPanel):
@@ -261,3 +263,25 @@
         self.setStackVisible(index, visible)
         for listener in self.stackListeners:
             listener.onStackChanged(self, index, visible)
+
+
+class TitlePanel(ToggleStackPanel):
+    """A toggle panel to set the message title"""
+    def __init__(self):
+        ToggleStackPanel.__init__(self, Width="100%")
+        self.text_area = TextArea()
+        self.add(self.text_area, _("Title"))
+        self.addStackChangeListener(self)
+
+    def onStackChanged(self, sender, index, visible=None):
+        if visible is None:
+            visible = sender.getWidget(index).getVisible()
+        text = self.text_area.getText()
+        suffix = "" if (visible or not text) else (": %s" % text)
+        sender.setStackText(index, _("Title") + suffix)
+
+    def getText(self):
+        return self.text_area.getText()
+
+    def setText(self, text):
+        self.text_area.setText(text)