Table Of Contents

Using ToscaWidgets in TurboGears 1.0

ToscaWidgets are officialy supported starting with TurboGears 1.1 and are the default widgets package starting with TurboGers 2.0. If you want to start using ToscaWidgets now with TurboGears 1.0, you can do so by using Genshi as your template engine.



First install/update ToscaWidgets:

easy_install -U toscawidgets
easy_install -U tw.forms
easy_install -U tw.dynforms
etc. as needed

Make sure ToscaWidgets is turned ON by adding/changing this line in the dev.cfg/prod.cfg or app.cfg:

toscawidgets.on = True


Make sure you have the latest version of Genshi:

easy_install -U genshi

If you wish, set Genshi as the default view by adding/changing this line in the dev.cfg/prod.cfg or app.cfg:

tg.defaultview = 'genshi'

alternatively, you can specify Genshi one at a time, such as:


Creating Widgets

Be sure to:

import tw, tw.forms, tw.dynforms (etc.)

Instantiate a widget container such as:

class MyFields(tw.api.WidgetsList):
   mytestinput = tw.forms.TextField('myid', label_text='Test Input Field')

tosca_form = tw.forms.TableForm(

and then pass the widgetform via the controller as a dict [1]:

def toscademo(self):
    return dict(form=tosca_form)

Your widgets can then be rendered through your template (toscatest.html in this case) by adding:


although, unlike TG Widgets, Tosca can render with simply:

[1]In contrast, TurboGears 2.0 uses Pylons and prefers passing widgets to the template via the template context, not by passing them in the dictionary returned by the controller. So don’t be misled by this when trying to use TurboGears 2.0 docs to understand ToscaWidgets for TurboGears 1.0.