Home | Trees | Indices | Help |
|
---|
|
1 # Copyright 2006 James Tauber and contributors 2 # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 from pyjamas import DOM 16 from pyjamas import Factory 17 from Composite import Composite 18 from pyjamas.ui import Event 19 from HTML import HTML 20 from Label import Label 21 from FlowPanel import FlowPanel 22 from ClickDelegatePanel import ClickDelegatePanel 23 from pyjamas.ui import HasAlignment 2426 27 STYLENAME_DEFAULT = "gwt-TabBarItem" 28186 187 Factory.registerClass('pyjamas.ui.FlowTabBar', FlowTabBar) 18830 31 if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-TabBar" 32 33 # this is awkward: FlowPanel is the composite, 34 # so we either the element here, and pass it in to FlowPanel. 35 element = None 36 if kwargs.has_key('Element'): 37 element = kwargs.pop('Element') 38 39 self.panel = FlowPanel(Element=element) 40 self.selectedTab = None 41 self.tabListeners = [] 42 43 #self.panel.setVerticalAlignment(HasAlignment.ALIGN_BOTTOM) 44 45 first = HTML(" ", True) 46 rest = HTML(" ", True) 47 first.setStyleName("gwt-TabBarFirst") 48 rest.setStyleName("gwt-TabBarRest") 49 first.setHeight("100%") 50 rest.setHeight("100%") 51 52 self.panel.add(first) 53 self.panel.add(rest) 54 first.setHeight("100%") 55 #self.panel.setCellHeight(first, "100%") 56 #self.panel.setCellWidth(rest, "100%") 57 58 Composite.__init__(self, self.panel, **kwargs) 59 self.sinkEvents(Event.ONCLICK)60 6365 self.tabListeners.append(listener)6668 if self.selectedTab is None: 69 return -1 70 return self.panel.getWidgetIndex(self.selectedTab) - 17173 return self.panel.getWidgetCount() - 27476 if index >= self.getTabCount(): 77 return None 78 delPanel = self.panel.getWidget(index + 1) 79 focusablePanel = delPanel.getFocusablePanel() 80 widget = focusablePanel.getWidget() 81 if hasattr(widget, "getHTML"): 82 return widget.getHTML() 83 elif hasattr(widget, "getText"): # assume it's a Label if it has getText 84 return widget.getText() 85 else: 86 fpe = DOM.getParent(self.focusablePanel.getElement()) 87 return DOM.getInnerHTML(fpe)88 9193 """ 1st arg can, instead of being 'text', be a widget 94 """ 95 if beforeIndex is None: 96 beforeIndex = asHTML 97 asHTML = False 98 99 if (beforeIndex < 0) or (beforeIndex > self.getTabCount()): 100 #throw new IndexOutOfBoundsException(); 101 pass 102 103 if isinstance(text, str): 104 if asHTML: 105 item = HTML(text) 106 else: 107 item = Label(text) 108 item.setWordWrap(False) 109 else: 110 # passing in a widget, it's expected to have its own style 111 item = text 112 113 self.insertTabWidget(item, beforeIndex)114116 117 delWidget = ClickDelegatePanel(self, widget, self, self) 118 delWidget.setStyleName(self.STYLENAME_DEFAULT) 119 120 focusablePanel = delWidget.getFocusablePanel() 121 self.panel.insert(delWidget, self.panel.getElement(), beforeIndex + 1) 122 123 parent = DOM.getParent(delWidget.getElement()) 124 #DOM.setStyleAttribute(parent, "flow", "left") 125 #DOM.setStyleAttribute(parent, "display", "inline") 126 self.setStyleName(parent, 127 self.STYLENAME_DEFAULT + "-wrapper", True)128 129 #print "insertTabWidget", DOM.getParent(delWidget.getElement()), DOM.getAttribute(DOM.getParent(delWidget.getElement()), "className") 130 131133 for i in range(1, self.panel.getWidgetCount() - 1): 134 if DOM.isOrHasChild(self.panel.getWidget(i).getElement(), 135 sender.getElement()): 136 return self.selectTab(i - 1) 137 return False138140 self.checkTabIndex(index) 141 142 toRemove = self.panel.getWidget(index + 1) 143 if toRemove == self.selectedTab: 144 self.selectedTab = None 145 self.panel.remove(toRemove)146148 self.tabListeners.remove(listener)149151 self.checkTabIndex(index) 152 153 for listener in self.tabListeners: 154 if not listener.onBeforeTabSelected(self, index): 155 return False 156 157 self.setSelectionStyle(self.selectedTab, False) 158 if index == -1: 159 self.selectedTab = None 160 return True 161 162 self.selectedTab = self.panel.getWidget(index + 1) 163 self.setSelectionStyle(self.selectedTab, True) 164 165 for listener in self.tabListeners: 166 listener.onTabSelected(self, index) 167 168 return True169171 if (index < -1) or (index >= self.getTabCount()): 172 #throw new IndexOutOfBoundsException(); 173 pass174176 if item is not None: 177 if selected: 178 item.addStyleName("gwt-TabBarItem-selected") 179 self.setStyleName(DOM.getParent(item.getElement()), 180 "gwt-TabBarItem-wrapper-selected", True) 181 182 else: 183 item.removeStyleName("gwt-TabBarItem-selected") 184 self.setStyleName(DOM.getParent(item.getElement()), 185 "gwt-TabBarItem-wrapper-selected", False)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jun 16 12:42:33 2010 | http://epydoc.sourceforge.net |