Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 1 (modified by michele, 14 years ago) (diff)



This page aims to collect opinions regarding TurboGears Widgets.

If you don't know TG widgets take a look at  this message from Kevin.

Feel free to add your own opinions and comments to this page.

Using Widgets

Actually to use a widget you need to do something like this:

  1. Create an instance of the widget from your controller
    age_field = widgets.TextField("age", default=0, validator=validators.Int())
  2. Insert your widget instance inside your template
    <div py:replace="age_field.insert(age)"/> 

IMHO for the second point we can use Kid py:match attribute to do something like this:

<widget name="age_field" value="age" />

it shouldn't be to hard if we add to the sitetemplate a definition like this (I have not tested it):

<span py:match="item.tag == 'widget'"
  py:replace="getattribute(self, item.get('name'), None).insert(item.get('value'))">

Customizing Widgets Look&Feel

Look&Feel customization is a quite important aspect for widgets. Actually you have two options:

  1. Providing a custom CSS stylesheet
  2. Providing a custom Kid template

Customization should be an easy task and should happen inside our templates. Widgets should use CSS class and selector to make it straigthforward.

Default attributes

During the 0.9 IRC Chat all have agreed that widgets should use namespaced class names.

For example:

<div class="tg_text_field">...</div>

Ability to set common attributes used for widgets

There is a ticket (#106) regarding this. This is an import requirement that will make customization even more easy. Using the syntax I proposed above customization shouldn't be that hard and inside your template you should be able to do the following:

<widget name="age_field" value="age" size="30" id="id_age_field"/>

But, how can we make customization as easy also for complex widgets that embeds others widgets? For example the Form widget? Any opinion?

See also