pycom: how to expose Python 2.3 property instance as a VARIANT?
Lijun Qin
qinlj at solidshare.com
Wed Oct 15 04:56:01 EDT 2003
Make your class derived from object, such as
class D(object):
def __init__
eternalsquire at comcast.net (The Eternal Squire) wrote in message news:<904dab11.0310111959.1b2f7838 at posting.google.com>...
> Hi everyone,
>
> I am wanting to write a Python COM server with a data member created
> by using the new Python 2.3
> property() built-in function. When I attempt to access the member
> through a client, I get
> the ComError message saying that I cannot convert type property into a
> VARIANT, so it looks
> like the default exposure mechanism in pythoncom.dll is not working
> properly.
>
> Do you have any suggestions as to how I can wrap the property
> properly? I'd much rather not create a
> nonstandard pythoncom.dll to do the conversion unless I absolutely
> must.
>
> Thanks:
>
> The Eternal Squire
>
> (see below an example sketch of what I intend. I'm well aware that I
> need the CLSID, PROGID, and other attributes in my example, let's
> assume I did that and that I also know how to register a COM server).
>
> ---- cut here ---
>
> class Friend:
> 'an object that modifies or uses the object which owns it'
> def __init__ (self, top):
> self.top = top
>
> class SmartValue (Friend):
> 'an example of a managed attribute of a COM interface'
> KEY = 'x'
>
> def __init__ (self, top):
> Friend.__init__ (self, top):
> self.storage = 0
> setattr (self.top, KEY, property (self.get, self.set))
> self.top._public_attrs_ += [ self.KEY ]
>
> def get (self):
> return self.storage
>
> def set (self, value):
> self.storage = value
>
>
> class COMInterface:
> ' an example COM interface template'
>
> ELEMENTS = [ ]
>
> def __init__ (self):
> [ e (self) for e in self.ELEMENTS ]
>
>
> class MyInterface (COMInterface):
> ' an example specific COM interface'
>
> ELEMENTS = [ SmartValue ]
>
> if __name__ == '__main__':
> 'code to register MyInterface would follow here'
>
> --- cut here ---
More information about the Python-list
mailing list