Mercurial > libervia-web
diff browser_side/panels.py @ 264:2a93f8e6f989
browser_side: added class ToggleStackPanel
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 17 Nov 2013 17:41:54 +0100 |
parents | 3df0c3634c29 |
children | a76243c02074 |
line wrap: on
line diff
--- a/browser_side/panels.py Mon Nov 11 12:48:33 2013 +0100 +++ b/browser_side/panels.py Sun Nov 17 17:41:54 2013 +0100 @@ -24,7 +24,6 @@ from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel -from pyjamas.ui.DialogBox import DialogBox from pyjamas.ui.HTMLPanel import HTMLPanel from pyjamas.ui.Frame import Frame from pyjamas.ui.TextArea import TextArea @@ -33,6 +32,7 @@ from pyjamas.ui.HTML import HTML from pyjamas.ui.Image import Image from pyjamas.ui.PopupPanel import PopupPanel +from pyjamas.ui.StackPanel import StackPanel from pyjamas.ui.ClickListener import ClickHandler from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_UP, KEY_DOWN from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT @@ -1056,3 +1056,32 @@ def registerRightClickSender(self, sender): self.registerClickSender(sender, BUTTON_RIGHT) + + +class ToggleStackPanel(StackPanel): + """This is a pyjamas.ui.StackPanel with modified behavior. All sub-panels ca be + visible at the same time, clicking a sub-panel header will not display it and hide + the others but only toggle its own visibility. The argument 'visibleStack' is ignored. + Note that the argument 'visible' has been added to listener's 'onStackChanged' method. + """ + + def __init__(self, **kwargs): + StackPanel.__init__(self, **kwargs) + + def onBrowserEvent(self, event): + if DOM.eventGetType(event) == "click": + index = self.getDividerIndex(DOM.eventGetTarget(event)) + if index != -1: + self.toggleStack(index) + + def add(self, widget, stackText="", asHTML=False, visible=False): + StackPanel.add(self, widget, stackText, asHTML) + self.setStackVisible(self.getWidgetCount() - 1, visible) + + def toggleStack(self, index): + if index >= self.getWidgetCount(): + return + visible = not self.getWidget(index).getVisible() + self.setStackVisible(index, visible) + for listener in self.stackListeners: + listener.onStackChanged(self, index, visible)