On Oct 1, 2004, at 12:39 PM, Daniele Varrazzo wrote:
> Dear Quixote people,
>
> i prefer form2 over form under many aspects, but because the widgets
> graphical look is "hardcoded" into the Widget base class, it's
> (almost) impossible to change it by subclassing: you should subclass
> all the derived widgets.
>
> In my application forms i desired three columns: the labels, the
> widgets, the hints and errors. I couldn't overload Widget.render()
> because it's inherited by all the widgets. I solved my
It isn't really so hard to change the Widget render.
def foo(widget):
return widget.render_content()
Widget.render = foo
If you are using composite widgets, you will need to
overwrite their render methods as well, but I suspect
that you are not using them.
Also, changing css can produce a surprising range
of different layouts with the default render.
>
> A solution to keep the widgets rendering code apart from the form code
> would be to move all Widget.render* methods (except render_content)
> into a WidgetRenderer class and compose each form instance with a
> WidgetRenderer instance. Anyway i don't think it would be much useful:
> the widgets rendering is tightly coupled to the form rendering (a
>
needs s...) thus each time Form is subclassed (to
> alter its graphical look) also WidgetRenderer probably needs to be,
> and you would also need stuff like
> class Form:
> widget_renderer_class = WidgetRenderer
> def __init__(self, ...):
> self.widget_renderer = self.widget_renderer_class()
Composite widgets are like forms, in that you may really want
specialized layouts for them. This specialization for each
type of Composite widget must be described somewhere. The
form2 pattern is to put the specialized code on the widget itself.
Since this is python though, nothing is really hardcoded.
|