[PyQt] dip properties

José M. Rodriguez Bacallao jmrbcu at gmail.com
Tue Mar 13 14:37:33 GMT 2012


ohhh, I didn't know that I could be do it that way!!!, thanks very much!!!


2012/3/13 Phil Thompson <phil at riverbankcomputing.com>:
> On Tue, 13 Mar 2012 08:23:26 -0500, José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> yes, I know that, the problem is that I want to shorten the code. For
>> example, I want to do this:
>>
>> class Widget(QtGui.QWidget, Model):
>>     id = property(lambda self: self.objectName(), lambda self, v:
>> self.setObjectName(v))
>>
>> instead of this:
>>
>> class Widget(QtGui.QWidget, Model):
>>     id = Str()
>>
>>     @id.getter
>>     def id(self):
>>         return self.objectName()
>>
>>     @id.setter
>>     def id(self, value):
>>         self.setObjectName(value)
>
> So something like...
>
> class Widget(QtGui.QWidget, Model):
>    id = Str(getter=lambda self: self.objectName(), setter=lambda self, v:
> self.setObjectName(v))
>
> ???
>
> I think that would be trivial to add.
>
> Phil


More information about the PyQt mailing list