[twill] Problem with single checkbox

Christoph Zwerschke cito at online.de
Sat May 9 08:48:03 PDT 2009


I'm using twill for a couple of projects now and find it really useful.

Three suggestions:

1) It would be nice if the <formnum> parameter to "formvalue" could be 
left out and then defaults to 1.

2) Twill checks the selected state of checkboxes like this:

     if isinstance(control, ClientForm.CheckboxControl):
         try:
             checkbox = control.get()
             checkbox.selected = make_boolean(val)
             return
         except ClientForm.AmbiguityError:
             # if there's more than one checkbox, use the behaviour for
             # ClientForm.ListControl, below.
             pass

I.e. if there is only one checkbox, it tries to interpret the value as a 
boolean and set the selected state accordingly. This is different from 
the usual behavior of list boxes or multiple check boxes and thus can be 
confusing if you're not aware of this feature (and I think it's not even 
documented). So I suggest to interpret the value in the usual way first 
and only if that does not apply, interpret it as a boolean:

     if isinstance(control, ClientForm.CheckboxControl):
          try:
             checkbox = control.get()
         except ClientForm.AmbiguityError:
             # if there's more than one checkbox, use the behaviour for
             # ClientForm.ListControl, below.
             pass
         else:
             if checkbox.name in (val, '+' + val):
                  checkbox.selected = True
             elif checkbox.name == '-' + val:
                  checkbox.selected == False
             else:
                  checkbox.selected = make_boolean(val)
             return

3) Can we have a new version? I stumbled over another bug that I noticed 
was already fixed in the trunk.

-- Christoph



More information about the twill mailing list