pycom: how to expose Python 2.3 property instance as a VARIANT?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Eternal Squire

    pycom: how to expose Python 2.3 property instance as a VARIANT?

    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._publi c_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 ---
  • Lijun Qin

    #2
    Re: pycom: how to expose Python 2.3 property instance as a VARIANT?

    Make your class derived from object, such as
    class D(object):
    def __init__



    eternalsquire@c omcast.net (The Eternal Squire) wrote in message news:<904dab11. 0310111959.1b2f 7838@posting.go ogle.com>...[color=blue]
    > 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._publi c_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 ---[/color]

    Comment

    Working...