1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from pyjamas import DOM
16 from pyjamas import Factory
17 from __pyjamas__ import console
18
19 from Composite import Composite
20 from DeckPanel import DeckPanel
21 from VerticalPanel import VerticalPanel
22 from TabBar import TabBar
23
25 - def __init__(self, tabBar=None, **kwargs):
26 self.tab_children = []
27 self.deck = DeckPanel(StyleName="gwt-TabPanelBottom")
28 if tabBar is None:
29 self.tabBar = TabBar()
30 else:
31 self.tabBar = tabBar
32 self.tabListeners = []
33
34
35
36 element = None
37 if kwargs.has_key('Element'):
38 element = kwargs.pop('Element')
39
40 panel = VerticalPanel(Element=element)
41 panel.add(self.tabBar)
42 panel.add(self.deck)
43
44 panel.setCellHeight(self.deck, "100%")
45 self.tabBar.setWidth("100%")
46 self.tabBar.addTabListener(self)
47
48 if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-TabPanel"
49
50 Composite.__init__(self, panel, **kwargs)
51
52 - def add(self, widget, tabText=None, asHTML=False):
53 """ tabText=None now means insert a spacer, pushed out at 100%
54 width so that any subsequent tabs added will be pushed to
55 the right hand side
56 """
57 self.insert(widget, tabText, asHTML, self.getWidgetCount())
58
60 self.tabListeners.append(listener)
61
65
68
71
74
77
80
81 - def insert(self, widget, tabText, asHTML=False, beforeIndex=None):
82 if beforeIndex is None:
83 beforeIndex = asHTML
84 asHTML = False
85
86 self.tab_children.insert(beforeIndex, widget)
87 self.tabBar.insertTab(tabText, asHTML, beforeIndex)
88 self.deck.insert(widget, beforeIndex)
89
92
94 for listener in self.tabListeners:
95 if not listener.onBeforeTabSelected(sender, tabIndex):
96 return False
97 return True
98
100 self.deck.showWidget(tabIndex)
101 for listener in self.tabListeners:
102 listener.onTabSelected(sender, tabIndex)
103
105 if isinstance(widget, int):
106 widget = self.getWidget(widget)
107
108 index = self.getWidgetIndex(widget)
109 if index == -1:
110 return False
111
112 self.tab_children.remove(widget)
113 self.tabBar.removeTab(index)
114 self.deck.remove(widget)
115 return True
116
118 self.tabListeners.remove(listener)
119
122
123 Factory.registerClass('pyjamas.ui.TabPanel', TabPanel)
124