From: Marco B. <mar...@ve...> - 2002-08-03 10:51:58
|
On Fri, 2 Aug 2002 16:43:05 +0200, Alberto Griggio <al...@ti...> wrote: >> I saw that now a lot of widgets have the same properties so we have >> the same code in a lot of file, how could we avoid this? My only idea >> is to modify classes derived from Property to handle access functions >> directly. > >This is the price to pay for widget independence, i.e. to keep each >widget as much isolated as possible from the others, so that it can be >added/removed without pain. >Anyway, we could use an approach similar to the one or CheckBox, >RadioBox, RadioButton, which all share the same ChoicesProperty, but I >think this is not possible for all cases (i.e. there are properties >which are quite similar but not identical) Why not something like this? class MyWidget(ManagedBase): def __init__(self, ...): ManagedBase.__init__(...) TextProperty(self, 'text') ... ... Where TextProperty is: class TextProperty(Property): def __init__(self, widget, name, initial=''): widget.access_functions[name] = self.get, self.set widget.properties[name] = self self.widget = widget self.value = initial def set(self, value): value = str(value) if value != self.value: # [...] undo code self.value = value if self.widget.widget: self.set_widget_value() def set_widget_value(self): self.widget.widget.SetText(self.value) This is completely compatible with the old code. I modified EditButton and wxGLade works perfectly, you can find this version at http://spazioweb.inwind.it/marcobari/tmp/button.py. -- Marco Barisione (ICQ 84277092) |