1 """
2 Pyjamas UI BuilderPanel: takes a PyJsGlade builder spec and adds widgets
3 requested using the methods just like in any other Panel class.
4
5 Copyright (C) 2010 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
6
7 The purpose of this class is to be able to set up a Panel of any type
8 that can be dynamically created using Builder, and then add child widgets
9 once again by their name as specified in the Builder spec file.
10
11 This class therefore has all of the usual Panel functions (add,
12 remove, insert, __iter__, getWidget) as well as those required
13 for it to be instantiable via Builder itself (!) such as
14 addIndexedItem, getIndex and getIndexedChild.
15
16 """
17
18 from pyjamas.ui.BuilderWidget import BuilderWidget
19
21
25
26 - def add(self, child_instance_name, *args, **kwargs):
27 """ versatile adding-function, copes with:
28 HTMLPanel.add(widget, id)
29 HTMLTable.add(item, row, col)
30 HorizontalPanel.add(item)
31 VerticalPanel.add(item)
32 VerticalSplitPanel.add(item)
33 HorizontalSplitPanel.add(item)
34 DeckPanel.add(item)
35 TabPanel.add(item)
36 DockPanel.add(widget, direction)
37 StackPanel.add(widget, stackText, asHTML)
38 AbsolutePanel.add(widget, left, top)
39 FlowPanel.add(widget)
40 CaptionPanel.add(widget)
41 ScrollPanel.add(widget)
42 """
43 widget = self.b.createInstance(child_instance_name, self.event_receiver)
44 self.getPanel().add(widget, *args, **kwargs)
45 return widget
46
47 - def insert(self, child_instance_name, *args, **kwargs):
48 widget = self.b.createInstance(child_instance_name, self.event_receiver)
49 self.getPanel().insert(widget, *args, **kwargs)
50 return widget
51
52 - def remove(self, widget, *args, **kwargs):
53 """ versatile removing-function, copes with:
54 HTMLPanel.remove(widget) # if it had one
55 HTMLTable.remove(item)
56 HorizontalPanel.remove(item)
57 VerticalPanel.remove(item)
58 VerticalSplitPanel.remove(item) # if it had one
59 HorizontalSplitPanel.remove(item) # if it had one
60 DeckPanel.remove(item)
61 TabPanel.remove(item)
62 DockPanel.remove(item)
63 StackPanel.remove(item, index=None)
64 AbsolutePanel.remove(item)
65 FlowPanel.add(widget)
66 """
67 self.getPanel().remove(widget, *args, **kwargs)
68
71
74
76 self.panel_instance_name = panel_instance_name
77
79 if self.panel_instance_name is None:
80 return self.widget
81 wids = self.b.widget_instances[self.instance_name]
82 return wids[self.panel_instance_name]
83
84
85
89
92
95
98
101
104