diff src/browser/sat_browser/base_widget.py @ 536:048ae7314156

browser_side: temporary way to display the OTR state in the LiberviaWidget header
author souliane <souliane@mailoo.org>
date Sun, 07 Sep 2014 16:40:33 +0200
parents 4c6d7db9b45c
children d02335553b5d
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py	Fri Sep 05 19:29:35 2014 +0200
+++ b/src/browser/sat_browser/base_widget.py	Sun Sep 07 16:40:33 2014 +0200
@@ -23,6 +23,7 @@
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
 from pyjamas.ui.ScrollPanel import ScrollPanel
 from pyjamas.ui.FlexTable import FlexTable
 from pyjamas.ui.TabPanel import TabPanel
@@ -199,15 +200,26 @@
 
 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
 
-    def __init__(self, parent, host, title):
+    def __init__(self, parent, host, title, info=None):
+        """
+        @param parent (LiberviaWidget): LiberWidget instance
+        @param host (SatWebFrontend): SatWebFrontend instance
+        @param title (Widget): text widget instance
+        @param info (Widget): text widget instance
+        """
         AbsolutePanel.__init__(self)
         self.add(title)
-        button_group_wrapper = SimplePanel()
+        if info:
+            # FIXME: temporary design to display the info near the menu
+            button_group_wrapper = HorizontalPanel()
+            button_group_wrapper.add(info)
+        else:
+            button_group_wrapper = SimplePanel()
         button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
         button_group = WidgetMenuBar(parent, host)
         button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting'))
         button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose'))
-        button_group_wrapper.setWidget(button_group)
+        button_group_wrapper.add(button_group)
         self.add(button_group_wrapper)
         self.addStyleName('widgetHeader')
         LiberviaDragWidget.__init__(self, "", "WIDGET", parent)
@@ -216,11 +228,12 @@
 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler):
     """Libervia's widget which can replace itself with a dropped widget on DnD"""
 
-    def __init__(self, host, title='', selectable=False):
+    def __init__(self, host, title='', info='', selectable=False):
         """Init the widget
-        @param host: SatWebFrontend object
-        @param title: title show in the header of the widget
-        @param selectable: True is widget can be selected by user"""
+        @param host (SatWebFrontend): SatWebFrontend instance
+        @param title (str): title shown in the header of the widget
+        @param info (str): info shown in the header of the widget
+        @param selectable (bool): True is widget can be selected by user"""
         VerticalPanel.__init__(self)
         DropCell.__init__(self, host)
         ClickHandler.__init__(self)
@@ -230,8 +243,13 @@
         self.__close_button_id = HTMLPanel.createUniqueId()
         self.__title = Label(title)
         self.__title.setStyleName('widgetHeader_title')
+        if info:
+            self.__info = Label(info)
+            self.__info.setStyleName('widgetHeader_info')
+        else:
+            self.__info = None
         self._close_listeners = []
-        header = WidgetHeader(self, host, self.__title)
+        header = WidgetHeader(self, host, self.__title, self.__info)
         self.add(header)
         self.setSize('100%', '100%')
         self.addStyleName('widget')
@@ -370,6 +388,14 @@
         @param text: text of the new title"""
         self.__title.setText(text)
 
+    def setHeaderInfo(self, text):
+        """change the info in the header of the widget
+        @param text: text of the new title"""
+        try:
+            self.__info.setText(text)
+        except AttributeError:
+            log.error("LiberviaWidget.setInfo: info widget has not been initialized!")
+
     def isSelectable(self):
         return self.__selectable