comparison 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
comparison
equal deleted inserted replaced
493:636b6c477a87 494:5d8632a7bfde
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui.AbsolutePanel import AbsolutePanel 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel
25 from pyjamas.ui.VerticalPanel import VerticalPanel 25 from pyjamas.ui.VerticalPanel import VerticalPanel
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
27 from pyjamas.ui.ScrollPanel import ScrollPanel 26 from pyjamas.ui.ScrollPanel import ScrollPanel
28 from pyjamas.ui.FlexTable import FlexTable 27 from pyjamas.ui.FlexTable import FlexTable
29 from pyjamas.ui.TabPanel import TabPanel 28 from pyjamas.ui.TabPanel import TabPanel
30 from pyjamas.ui.HTMLPanel import HTMLPanel 29 from pyjamas.ui.HTMLPanel import HTMLPanel
31 from pyjamas.ui.Label import Label 30 from pyjamas.ui.Label import Label
32 from pyjamas.ui.Button import Button 31 from pyjamas.ui.Button import Button
33 from pyjamas.ui.Image import Image
34 from pyjamas.ui.Widget import Widget 32 from pyjamas.ui.Widget import Widget
35 from pyjamas.ui.DragWidget import DragWidget 33 from pyjamas.ui.DragWidget import DragWidget
36 from pyjamas.ui.DropWidget import DropWidget 34 from pyjamas.ui.DropWidget import DropWidget
37 from pyjamas.ui.ClickListener import ClickHandler 35 from pyjamas.ui.ClickListener import ClickHandler
38 from pyjamas.ui import HasAlignment 36 from pyjamas.ui import HasAlignment
39 from pyjamas import DOM 37 from pyjamas import DOM
40 from pyjamas import Window 38 from pyjamas import Window
39
41 from __pyjamas__ import doc 40 from __pyjamas__ import doc
42 41
43 import dialog 42 import dialog
43 import base_menu
44 44
45 45
46 class DragLabel(DragWidget): 46 class DragLabel(DragWidget):
47 47
48 def __init__(self, text, _type): 48 def __init__(self, text, _type):
163 td_elt = panel.getElement().parentNode 163 td_elt = panel.getElement().parentNode
164 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)""" 164 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)"""
165 #FIXME: delete object ? Check the right way with pyjamas 165 #FIXME: delete object ? Check the right way with pyjamas
166 166
167 167
168 class WidgetMenuBar(base_menu.GenericMenuBar):
169
170 ITEM_TPL = "<img src='media/icons/misc/%s.png' />"
171
172 def __init__(self, host, vertical=False):
173 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical)
174 self.setStyleName('widgetHeader_buttonGroup')
175
176 @classmethod
177 def getCategoryHTML(cls, type_, menu_name_i18n):
178 return cls.ITEM_TPL % type_
179
180
168 class WidgetHeader(AbsolutePanel, LiberviaDragWidget): 181 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
169 182
170 def __init__(self, parent, title): 183 def __init__(self, parent, host, title):
171 AbsolutePanel.__init__(self) 184 AbsolutePanel.__init__(self)
172 self.add(title) 185 self.add(title)
173 button_group_wrapper = SimplePanel() 186 button_group_wrapper = SimplePanel()
174 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') 187 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
175 button_group = HorizontalPanel() 188 button_group = WidgetMenuBar(host)
176 button_group.setStyleName('widgetHeader_buttonGroup') 189 parent.addCachedMenus(button_group)
177 setting_button = Image("media/icons/misc/settings.png") 190 button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting'))
178 setting_button.setStyleName('widgetHeader_settingButton') 191 button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose'))
179 setting_button.addClickListener(parent.onSetting)
180 close_button = Image("media/icons/misc/close.png")
181 close_button.setStyleName('widgetHeader_closeButton')
182 close_button.addClickListener(parent.onClose)
183 button_group.add(setting_button)
184 button_group.add(close_button)
185 button_group_wrapper.setWidget(button_group) 192 button_group_wrapper.setWidget(button_group)
186 self.add(button_group_wrapper) 193 self.add(button_group_wrapper)
187 self.addStyleName('widgetHeader') 194 self.addStyleName('widgetHeader')
188 LiberviaDragWidget.__init__(self, "", "WIDGET", parent) 195 LiberviaDragWidget.__init__(self, "", "WIDGET", parent)
189 196
204 self.__setting_button_id = HTMLPanel.createUniqueId() 211 self.__setting_button_id = HTMLPanel.createUniqueId()
205 self.__close_button_id = HTMLPanel.createUniqueId() 212 self.__close_button_id = HTMLPanel.createUniqueId()
206 self.__title = Label(title) 213 self.__title = Label(title)
207 self.__title.setStyleName('widgetHeader_title') 214 self.__title.setStyleName('widgetHeader_title')
208 self._close_listeners = [] 215 self._close_listeners = []
209 header = WidgetHeader(self, self.__title) 216 header = WidgetHeader(self, host, self.__title)
210 self.add(header) 217 self.add(header)
211 self.setSize('100%', '100%') 218 self.setSize('100%', '100%')
212 self.addStyleName('widget') 219 self.addStyleName('widget')
213 if self.__selectable: 220 if self.__selectable:
214 self.addClickListener(self) 221 self.addClickListener(self)
397 # We need to force the use of a panel subclass method here, else 404 # We need to force the use of a panel subclass method here, else
398 # the event will not propagate to children 405 # the event will not propagate to children
399 VerticalPanel.doAttachChildren(self) 406 VerticalPanel.doAttachChildren(self)
400 407
401 def matchEntity(self, entity): 408 def matchEntity(self, entity):
402 """This method should be overwritten by child classes.""" 409 """Check if this widget corresponds to the given entity.
410
411 This method should be overwritten by child classes.
412 @return: True if the widget matches the entity"""
403 raise NotImplementedError 413 raise NotImplementedError
414
415 def addCachedMenus(self, menu_bar):
416 """Add cached menus to the header.
417
418 This method can be overwritten by child classes.
419 @param menu_bar (GenericMenuBar): menu bar of the widget's header
420 """
421 pass
404 422
405 423
406 class ScrollPanelWrapper(SimplePanel): 424 class ScrollPanelWrapper(SimplePanel):
407 """Scroll Panel like component, wich use the full available space 425 """Scroll Panel like component, wich use the full available space
408 to work around percent size issue, it use some of the ideas found 426 to work around percent size issue, it use some of the ideas found