Phil Thompson schrieb:
On Wednesday 18 February 2004 19:04, Eron Lloyd wrote:
  
Would there be any benefit in doing this? From the way I understand it, all
Qt objects already expose their get/set methods, while any objects you
create through subclassing can simply use Python's native properties
support. For the most part, properties have their biggest value in use with
Designer.

Eron
    

I agree, it just duplicates existing functionality at the cost of code bloat.

  
Not only code bloat, also a performance penalty.

Look at the following test class and the two methods to get and set an attribute:

--------------------------------------------------
class PropertyTest(object):
    def getValue(self):
        return self._value
    def setValue(self, value):
        self._value = value
    value = property(getValue, setValue, None)
--------------------------------------------------
x = PropertyTest()
for i in xrange(100000):
    x.setValue("TEST")
    a = x.getValue()
    x.setValue(a.swapcase())
--------------------------------------------------
x = PropertyTest()
for i in xrange(100000):
    x.value = "TEST"
    a = x.value
    x.value = a.swapcase()
--------------------------------------------------

On my Linux box with Python-2.3.3, the second method has only ~75% of the performance of the first method.

Nevertheless it makes sense to implement QMetaObject and QMetaProperty, just in case someone plans to build a kind of dialog editor with PyQt (in the future, we want to give our customers the facility to create or modify dialogs or dialog components inside the application).

Ulli

Reply via email to