diff src/browser/sat_browser/base_widget.py @ 494:5d8632a7bfde

browser_side: refactorisation of menus and LiberviaWidget's header
author souliane <souliane@mailoo.org>
date Tue, 15 Jul 2014 18:43:55 +0200
parents 97c72fe4a5f2
children 60be99de3808
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py	Tue Jul 15 13:39:36 2014 +0200
+++ b/src/browser/sat_browser/base_widget.py	Tue Jul 15 18:43:55 2014 +0200
@@ -23,14 +23,12 @@
 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
 from pyjamas.ui.HTMLPanel import HTMLPanel
 from pyjamas.ui.Label import Label
 from pyjamas.ui.Button import Button
-from pyjamas.ui.Image import Image
 from pyjamas.ui.Widget import Widget
 from pyjamas.ui.DragWidget import DragWidget
 from pyjamas.ui.DropWidget import DropWidget
@@ -38,9 +36,11 @@
 from pyjamas.ui import HasAlignment
 from pyjamas import DOM
 from pyjamas import Window
+
 from __pyjamas__ import doc
 
 import dialog
+import base_menu
 
 
 class DragLabel(DragWidget):
@@ -165,23 +165,30 @@
         #FIXME: delete object ? Check the right way with pyjamas
 
 
+class WidgetMenuBar(base_menu.GenericMenuBar):
+
+    ITEM_TPL = "<img src='media/icons/misc/%s.png' />"
+
+    def __init__(self, host, vertical=False):
+        base_menu.GenericMenuBar.__init__(self, host, vertical=vertical)
+        self.setStyleName('widgetHeader_buttonGroup')
+
+    @classmethod
+    def getCategoryHTML(cls, type_, menu_name_i18n):
+        return cls.ITEM_TPL % type_
+
+
 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
 
-    def __init__(self, parent, title):
+    def __init__(self, parent, host, title):
         AbsolutePanel.__init__(self)
         self.add(title)
         button_group_wrapper = SimplePanel()
         button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
-        button_group = HorizontalPanel()
-        button_group.setStyleName('widgetHeader_buttonGroup')
-        setting_button = Image("media/icons/misc/settings.png")
-        setting_button.setStyleName('widgetHeader_settingButton')
-        setting_button.addClickListener(parent.onSetting)
-        close_button = Image("media/icons/misc/close.png")
-        close_button.setStyleName('widgetHeader_closeButton')
-        close_button.addClickListener(parent.onClose)
-        button_group.add(setting_button)
-        button_group.add(close_button)
+        button_group = WidgetMenuBar(host)
+        parent.addCachedMenus(button_group)
+        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)
         self.add(button_group_wrapper)
         self.addStyleName('widgetHeader')
@@ -206,7 +213,7 @@
         self.__title = Label(title)
         self.__title.setStyleName('widgetHeader_title')
         self._close_listeners = []
-        header = WidgetHeader(self, self.__title)
+        header = WidgetHeader(self, host, self.__title)
         self.add(header)
         self.setSize('100%', '100%')
         self.addStyleName('widget')
@@ -399,9 +406,20 @@
         VerticalPanel.doAttachChildren(self)
 
     def matchEntity(self, entity):
-        """This method should be overwritten by child classes."""
+        """Check if this widget corresponds to the given entity.
+
+        This method should be overwritten by child classes.
+        @return: True if the widget matches the entity"""
         raise NotImplementedError
 
+    def addCachedMenus(self, menu_bar):
+        """Add cached menus to the header.
+
+        This method can be overwritten by child classes.
+        @param menu_bar (GenericMenuBar): menu bar of the widget's header
+        """
+        pass
+
 
 class ScrollPanelWrapper(SimplePanel):
     """Scroll Panel like component, wich use the full available space