Re: CompositeWidget question

David Binger <[email protected]>
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
On Jul 14, 2005, at 9:04 PM, [email protected] wrote:

>
> Is this the right way to do it?  Should my ._parse method set the  
> value to
> a tuple of subvalues, and .set_value propagate the values to the
> subwidgets?  Or should I ignore the widget value and have caller  
> look at
> the subwidget values directly?  "form.get_widget('quantity')['low']"?
> I suppose I can't do "form['quantity']['low']" ?

I think that the first option you suggest, setting the value to a tuple,
or to an instance of a class you write for this particular purpose,  
is a good
way to do it.  The user of the widget should not need be aware of the
particulars of the subwidgets.

>
> What if I need several range controls on the same form?  All the
> subwidgets will be in a flat namespace in the HTML.  I'm getting  
> subwidget
> names like 'release$low', so I guess that's being taken care of
> automatically somehow.

Right, you would just get the _parsed value from your composite  
widget as
if it were a non-composite widget.

>     def _parse(self):
>         is_low = self['low'] is not None
>         is_high = self['high'] is not None
>         is_unit = self['unit'] is not None
>         if is_high and not is_low:
>             self.error = "Must provide low number."
>         if (is_low or is_high) and not is_unit:
>             self.error = "Must provide unit."

The _parse needs to set the value to something.

>
> I made a date widget earlier but that was pretty straightforward,  
> since
> the value is a datetime object, and I put the subwidgets  
> in .year, .month,
> and .day attributes.  (Perhaps I should have used .add()  
> and .widgets, but
> I bypassed them.)  But a range object doesn't have an obvious  
> single value
> unless I arbitrarily say  ".value = (low, high, unit)".  Is that  
> how to do
> it with composite widgets?

Yes.  Or, you could make a RangeWithUnit class for this purpose.
You might be interested in the classes for this that are in dulcinea.
They serve a similar purpose, but the widgets don't work the same
way as the ones you want.

>
> After that I need to make a latitude/longitude widget that accepts:
>     123.45               West    (degrees)
>     123     45.67        West    (degrees, minutes)
>     123     45    45.67  West    (degrees, minutes, seconds)
> But first I have to get the simpler widget down.

That will be easier after you get the pattern worked out.

>
> What is the purpose of WidgetList and WidgetDict?  At first I  
> thought they
> were for making arbitrary composite widgets, but that raises the  
> question
> of when to use them and when to use CompositeWidget directly, and what
> that funny 'add_element' widget is for.  Then I thought, "No, they are
> specialized widgets, for growable lists/dicts."  Are they for when you

That thought was correct.

> have multiple values and want to let the user as many additional  
> values as
> they want?  But there's nothing to delete an element if they want  
> to go
> the other way.  Or are these widgets for something else?

Dulcinea has a DeletableWidget that is designed to allow delete buttons
in a WidgetList.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.