5 class Form(widget.Widget):
6 """A form that automatically will contain all named widgets.
8 After a form is created, all named widget that are subsequently created are
9 added to that form. You may use dict style access to access named widgets.
15 w = gui.Input("Phil",name="firstname")
16 w = gui.Input("Hassey",name="lastname")
22 print(f['firstname'].value)
23 print(f['lastname'].value)
27 # The current form instance
29 # The list of PGU widgets that are tracked by this form
31 # A mapping of PGU widgets tracked by this form (name -> instance)
33 # The dirty flag is set when a new widget is added to the form
37 widget.Widget.__init__(self,decorate=False)
41 # Register this form as the one used by new widgets
44 def add(self,e,name=None,value=None):
45 """Adds a PGU widget to this form"""
46 if name != None: e.name = name
47 if value != None: e.value = value
52 # Remove elements from our list if they no longer have an assigned name
53 for e in self._elist[:]:
54 if not hasattr(e,'name') or e.name == None:
56 # Update the name-to-widget mapping
59 self._emap[e.name] = e
62 def __getitem__(self,k):
63 """Returns the widget instance given the name of the widget"""
64 if self._dirty: self._clean()
67 def __contains__(self,k):
68 """Returns true if this form contains the named widget"""
69 if self._dirty: self._clean()
70 if k in self._emap: return True
74 """Return a dict of name, widget-value pairs."""
75 if self._dirty: self._clean()
78 # Make sure the widget has a 'value' (eg tables do not)
79 if (hasattr(e, "value")):
86 """Return a list of name, widget pairs."""
87 return self.results().items()