[PyQt] properties and interfaces with dip 0.3

Lic. José M. Rodriguez Bacallao jmrbcu at gmail.com
Wed Jul 13 18:53:57 BST 2011


yes, I know I can't think in interfaces like base classes but, as I
read in documentation that attributes are automatically added to te
concrete implementation of the interface, well, look at this sample:

class ITest(Interface):

    id = Str()


@implements(ITest)
class Test(Model):

    @id.observer
    def on_change(self, change):
        print 'changing...'


if __name__ == '__main__':
    test = Test()
    test.id = 'xxx'
    print test.id

it give me this error:

Traceback (most recent call last):
  File "/home/jmrbcu/work/dev-projects/imagis/src/imagis/ui/widget.py",
line 49, in <module>
    class Test(Model):
  File "/home/jmrbcu/work/dev-projects/imagis/src/imagis/ui/widget.py",
line 51, in Test
    @id.observer
AttributeError: 'builtin_function_or_method' object has no attribute 'observer'

and if I change @id.observer to @ITest.id.observer ten the observer is
never called.

On Wed, Jul 13, 2011 at 1:35 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Wed, 13 Jul 2011 12:09:37 -0400, Lic. José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> hi folks, may be this is an fool question but, how to implement
>> properties with interface attributes, for example, this doesn't work:
>>
>> class SomeObject(object):
>>     def __init__(self, id):
>>         self.id = id
>>
>> class ISomething(Interface):
>>     id = Str()
>>
>> class Somthing(Interface):
>>
>>     _internal = Instance(SomeObject)
>>
>>     @ISomething.id.getter
>>     def id(self):
>>         return self._internal.id
>>
>>     @ISomething.id.setter
>>     def id(self, value):
>>         return self._internal.id = value
>>
>>     @_internal.default
>>     def _internal(self):
>>         return SomeObject(self.id)
>
> Whether the attributes of an interface have getters and setters is part of
> the detail of a particular implementation of that interface. It's not part
> of the specification of the interface.
>
> You seem to be thinking of an interface as a base class - it isn't.
>
> Phil
>



-- 
Lic. José M. Rodriguez Bacallao
Centro de Biofisica Medica
-----------------------------------------------------------------
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.

Recuerda: El arca de Noe fue construida por aficionados, el titanic
por profesionales
-----------------------------------------------------------------


More information about the PyQt mailing list