RE: Python Com and Overloaded methods problem

Date : Wed, 17 Jan 2007 10:21:21 -0000
To : <XSI(at)Softimage.COM>
From : "Daniele N" <daniele(at)passion-pictures.com>
Subject : RE: Python Com and Overloaded methods problem
Sorry no good news here... Just stay away from COM unless you really
need it, or your company is bought by Microsoft:-)

 

Hahaha, no, not yet  ;)

Thank you again Aloys, this is all I needed to know. That's a shame
anyway, I liked the idea of use other supported languages for manipulate
objects created in python or vice versa... Maybe with .NET?

 

Cheers,

Daniele ( Dan-ee-yel-eh )

________________________________

From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf
Of Aloys Baillet
Sent: 16 January 2007 22:30
To: XSI(at)Softimage.COM
Subject: Re: Python Com and Overloaded methods problem

 

Hi Daniele,

A lot of limitations in here... the bigger one is JScript itself. I
don't think you can use operator overloading in JScript anyway, so the
__add__ method will not be understood by JScript anyway. I'm not even
sure you can do that in a standard COM object... 
Regarding the tuple vs list problem, the SafeArray COM object is the
same as a tuple: it's not modifiable. That's why pythoncom converts any
list to a tuple, it's a COM limitation again, not a pythoncom one. 
The bad thing here is that COM and JScript are not even close friends...
the fact that you have to use the VBArray.toArray method to use standard
JScript arrays from COM returned VBArray (aka SafeArray) is already a
source of headache... 

Sorry no good news here... Just stay away from COM unless you really
need it, or your company is bought by Microsoft:-)


Cheers,

Aloys

On 1/15/07, Daniele N <daniele(at)passion-pictures.com> wrote:

Hi Aloys,

I see... Unfortunately it seems impossible call overloaded special
methods like __add__ or __iter__, once the class is wrapped, doesn't
matter if it is called by a Jscript, VBScript or Python code.

 

For example exposing that class in a command:

 

from win32com.server.util import wrap

from win32com.server.util import unwrap

from win32com.client.dynamic import Dispatch 

import win32com.client

from win32com.client import constants

 

null = None

false = 0

true = 1

 

class MyClass:

    _public_methods_ = ['__add__', 'Method']

    _public_attrs_ = ['ClassArray']

    

    ClassArray = []

    

    def __add__(self, other):

        Application.LogMessage('porca miseria')

        ReturnClass = MyClass()

 

        for element in self.ClassArray:

            ReturnClass.ClassArray.append(element)

        for element in other.ClassArray:

            ReturnClass.ClassArray.append(element)

        

        return wrap(ReturnClass)

    

    def __init__(self):

        pass

        

    def Method(self):

        pass

 

def XSILoadPlugin( in_reg ):

    in_reg.Author = "daniele"

    in_reg.Name = "DispatchTestPlugin"

    in_reg.Email = ""

    in_reg.URL = ""

    in_reg.Major = 1

    in_reg.Minor = 0

 

    in_reg.RegisterCommand("DispatchTest","DispatchTest")

    #RegistrationInsertionPoint - do not remove this line

 

    return true

 

def XSIUnloadPlugin( in_reg ):

    strPluginName = in_reg.Name

    Application.LogMessage(str(strPluginName) + str(" has been
unloaded."))

    return true

 

def DispatchTest_Init( ctxt ):

    oCmd = ctxt.Source

    oCmd.Description = ""

    oCmd.ReturnValue = true

 

    return true

 

def DispatchTest_Execute():

    oClass = MyClass()

    return wrap(oClass)

 

 

And now launching this simple Jscript code:

 

Test1 = DispatchTest()

Test2 = DispatchTest()

 

Test1.ClassArray = new Array(0, 1, 2, 3)

Test2.ClassArray = new Array("Hello", "World")

 

Test3 = Test1+Test2

LogMessage(Test3.ClassArray)

 

I still not able to get correct this line Test3 = Test1+Test2. Test3 is
simply "null" making the line after fail: 

//ERROR : 'Test3.ClassArray' is null or not an object.

 

And by the way, if the class is wrapped and I'm used it from Python
code, if I pass a list it will be converted in a tuple... this is very
unwanted, don't you think?

 

Everything works fine with unwrap, but probably is a better idea don't
expose python classes to the com if it isn't really really necessary.

I'm developing a quite articulated framework for create rigs in python
an I thought to expose everything to the com for make it usable from
Jscript, but I have big problem now because of this idea.

 

Thank you for the answer anyway,

Daniele ( Dan-ee-yel-eh )

________________________________

From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf
Of Aloys Baillet
Sent: 14 January 2007 21:28
To: XSI(at)Softimage.COM
Subject: Re: Python Com and Overloaded methods problem

 

Hi Daniele,

Once your class instance is COM-wrapped, it's not available for regular
Python use: the wrap is COM-ready and you can return this object from a
python custom command and use it from JScript for example, but if you
want to access the original python object, you need to call the
pythoncom.UnwrapObject if I remember correctly.

Regarding the SWIG thing, we just need someone really courageous to
start this big big task... 

Cheers,

Aloys

On 1/13/07, Daniele N <daniele(at)passion-pictures.com> wrote:

One more thing.


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.