Package turbogears :: Package widgets :: Module base :: Class CompoundWidget

Class CompoundWidget

source code

object --+    
         |    
    Widget --+
             |
            CompoundWidget
Known Subclasses:

A widget that can contain other widgets.

A compound widget is a widget that can group several widgets to make a complex widget. Child widget names must be listed at their widget's ``member_widgets`` attribute.

Nested Classes

Inherited from Widget: __metaclass__

Instance Methods
 
__init__(self, *args, **kw)
Widget initialization.
source code
 
iter_member_widgets(self)
Iterates over all the widget's children
source code
 
display(self, value=None, **params)
Display the widget in a Genshi or Kid template.
source code
 
render(self, value=None, format='html', **params)
Exactly the same as display() but return serialized output instead.
source code
 
update_params(self, d)
Update the template parameters.
source code
 
value_for(self, item, value)
Get value for member widget.
source code
 
params_for(self, item, **params)
Get params for member widget.
source code
 
retrieve_javascript(self)
Get JavaScript for the member widgets.
source code
 
retrieve_css(self)
Get CSS for the member widgets.
source code

Inherited from Widget: __call__, __repr__, __setattr__, adjust_value

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __sizeof__, __str__, __subclasshook__

Class Variables
  compound = True
hash(x)
  member_widgets = []

Inherited from Widget: css, default, engine_name, javascript, name, params, params_doc, template

Properties

Inherited from Widget: is_named

Inherited from object: __class__

Method Details

__init__(self, *args, **kw)
(Constructor)

source code 
Widget initialization.

All initialization has to take place in this method.
It's not thread-safe to mutate widget's attributes outside this method
or anytime after widget's first display.

*Must* call super(MyWidget, self).__init__(*args, **kw) cooperatively,
unless, of course, you know what you're doing. Preferably this should
be done before any actual work is done in the method.

Parameters:

name:        The widget's name. In input widgets, this will also be the
             name of the variable that the form will send to the
             controller. This is the only param that is safe to pass as a
             positional argument to __init__.
template:    The template that the widget should use to display itself.
             Currently only Genshi and Kid templates are supported. You
             can both initialize with a template string or with the path
             to a file-base template: 'myapp.templates.widget_tmpl'
engine_name: The engine to be used for rendering the template, if not
             specified in the template already.
default:     Default value to display when no value is passed at display
             time.
**params:    Keyword arguments specific to your widget or to any of its
             bases. If listed at class attribute 'params' the will be
             bound automatically to the widget instance.

Note: Do not confuse these parameters with parameters listed at
"params". Some widgets accept parameters at the constructor which are
not listed params, these parameter won't be passed to the template, be
automatically called, etc.

Overrides: object.__init__
(inherited documentation)

display(self, value=None, **params)

source code 
Display the widget in a Genshi or Kid template.

Returns a Genshi Markup stream or an ElementTree node instance,
depending on the template in which the widget shall be displayed.
If you need serialized output in a string, call 'render' instead.

Probably you will not need to override or extend if inheriting from
Widget.

@params:

value   : The value to display in the widget.
**params: Extra parameters specific to the widget. All keyword params
          supplied will pass through the update_params method which
          will have a last chance to modify them before reaching the
          template.

Overrides: Widget.display
(inherited documentation)

render(self, value=None, format='html', **params)

source code 

Exactly the same as display() but return serialized output instead.

Useful for debugging or to display the widget in a template other than Genshi or Kid, like Cheetah, Mako, Nevow Stan, ...

Overrides: Widget.render
(inherited documentation)

update_params(self, d)

source code 

Update the template parameters.

This method will have the last chance to update the variables sent to the template for the specific request. All parameters listed at class attribute 'params' will be available at the 'params' dict this method receives.

*Must* call super(MyWidget, self).update_params(params) cooperatively, unless, of course, your know what you're doing. Preferably this should be done before any actual work is done in the method.

Overrides: Widget.update_params
(inherited documentation)

value_for(self, item, value)

source code 

Get value for member widget.

Pick up the value for a given member_widget 'item' from the value dict passed to this widget.

params_for(self, item, **params)

source code 

Get params for member widget.

Pick up the params for the given member_widget 'item' from the params dict passed to this widget.

retrieve_javascript(self)

source code 

Get JavaScript for the member widgets.

Retrieve the JavaScript for all the member widgets and get an ordered union of them.

Overrides: Widget.retrieve_javascript

retrieve_css(self)

source code 

Get CSS for the member widgets.

Retrieve the CSS for all the member widgets and get an ordered union of them.

Overrides: Widget.retrieve_css