Hi,
Probably the best (and easiest thing to do) is this:
Add a property to your model class that returns exactly what you want
the label to show.
In your case:
class Person(object):
# snipped your existing class
def get_gender_string(self):
if self.gender == -1:
return 'Not specified'
elif self.gender == 0:
return 'Male'
# etc
# now declare it as a property
gender_string = property(get_gender_string)
Now any instance of Person will have the gender_string property which
you can read as any other attribute: myperson.gender_string. Then
setting the label's model attribute to 'gender_string' instead of
'gender' will display what you want.
Ali
On 29/10/2007, Lucas Di Pentima <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm using kiwi's Label class to show read-only attribute values for
> some model instances, and I need to show different strings depending
> on the attribute's value, for example: if 'gender' attribute's value
> for the Person class is -1, then the Label widget should show 'not
> specified' in the UI.
>
> I tried the "replace()" method, but that method setup up value mapping
> for the entire Label class, I need to be instance-based, how can I do
> this? Should I make my own Label's subclass and implement it or
> there's any way to do that in kiwi?
>
> Best regards,
> --
> Lucas Di Pentima - http://lucas.di-pentima.com.ar
> GnuPG Public Key:
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x6AA54FC9
> Key fingerprint = BD3B 08C4 661A 8C3B 1855 740C 8F98 3FCF 6AA5 4FC9
> _______________________________________________
> Kiwi mailing list
> [email protected]
> http://www.async.com.br/mailman/listinfo/kiwi
>
_______________________________________________
Kiwi mailing list
[email protected]
http://www.async.com.br/mailman/listinfo/kiwi