Package pyjamas :: Package ui :: Module BuilderPanel
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.ui.BuilderPanel

  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   
20 -class BuilderPanel(BuilderWidget):
21
22 - def __init__(self, **kwargs):
23 self.panel_instance_name = None 24 BuilderWidget.__init__(self, **kwargs)
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
69 - def __iter__(self):
70 return self.b.__iter__()
71
72 - def getChildren(self):
73 return self.b.getChildren()
74
75 - def setPanelInstanceName(self, panel_instance_name):
76 self.panel_instance_name = panel_instance_name
77
78 - def getPanel(self):
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 # these next three functions are part of the standard Builder API 85 # and are required for panels to be manageable by PyJsGlade.
86 - def addIndexedItem(self, index, instance_name):
87 widget = self.b.createInstance(child_instance_name, self.event_receiver) 88 self.getPanel().addIndexedItem(index, widget)
89
90 - def getIndexedChild(self, index):
91 return self.getPanel().getIndexedChild(index)
92
93 - def getWidgetIndex(self, widget):
94 return self.getPanel().getWidgetIndex(widget)
95
96 - def getWidget(self, *args):
97 return self.getPanel().getWidget(*args)
98
99 - def getWidgetCount(self):
100 return self.getPanel().getWidgetCount()
101
102 - def setWidgetPosition(self, *args):
103 return self.getPanel().setWidgetPosition(*args)
104