Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.calendars.CalendarDatePicker
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Takes care of post-initialization of InputWidgets.
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.calendars.CalendarDateTimePicker
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Takes care of post-initialization of InputWidgets.
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.fields.InputField
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Takes care of post-initialization of InputWidgets.
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
alias of StringBool
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.datagrid.DataGrid
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Return Column with specified name.
Raises KeyError if no such column exists.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
Return a function to access the fields of table by row, col.
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.fields.TableForm
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.calendars.CalendarDateTimePicker
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Takes care of post-initialization of InputWidgets.
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.fields.MultipleSelectField, sprox.widgets.widgets.PropertyMixin
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
alias of DefaultValidator
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.forms.fields.SingleSelectField, sprox.widgets.widgets.PropertyMixin
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Validation error for current request.
If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
Takes care of post-initialization of InputWidgets.
Prepares the dict sent to the template with functions to access the children’s errors if any.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.
Fetches values from the dict and inserts the in the attrs dict.
This is useful when you want to avoid boiler-place at the template:
Instead of:
<foo bar='$bar' zoo='$zoo' />
Do:
<foo py:attrs="attrs" />
And inside update_params:
self.update_attrs(d, 'bar', 'zoo')
(‘bar’ and ‘zoo’ need to be listed at params)
Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.
If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.
alias of DefaultValidator
Value being validated in current request.
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
Bases: tw.core.base.Widget
Adapt object value for rendering in this widget. Should return one of: * A list of objects for repeated widgets. * A dict for widgets with children, keyed by the children’s ids. * Any other object the widget understands.
Adds a tw.api.js_function() call that will be made when the widget is rendered.
Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.
Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.
Where the widget is being displayed on
Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value
The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
Returns an iterator for all children applying a filter to them.
>>> class Widgets(WidgetsList):
... aa = Widget()
... ab = Widget()
... ba = Widget()
... bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
True if the widget doesn’t have a parent
A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.
Example:
>>> A = Widget("A", children=[
... Widget("B", children=[
... Widget("C")
... ])
... ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
Iterates a walk from this widget to the root of the tree
This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.
Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.
Register the resources required by this Widget with tw.framework for inclusion in the page.
This method is called whenever a Widget is rendered
Renders a widget as an unicode string.
The root of this widget tree
Updates the dict sent to the template for the current request.
It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.
Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.
Any parameter sent to display or render will override those fetched from the instance or the class.
Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.
>>> class MyWidget(Widget):
... params = ["foo", "bar", "null"]
... foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.
Example:
>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'
Recursion can be prevented on children that not match filter.
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''