[wingide-users] Name completion on .NET and COM objects

Wingware Support support at wingware.com
Mon Oct 13 09:58:28 MDT 2008


Wikström Sven wrote:
> Thanks for the response.
> 
> I understand that it cannot work in the main editor window.
> But it does not work in the interactive shell nor the probe either, for me at least.
> 
> Behaviour in Wings interactive shell:
>>>>> import win32com.client
>>>>> excel = win32com.client.Dispatch("Excel.Application")
>>>>> excel.XXXXXX
> 
> Where "XXXXXX" is just a completion list of low-level COM stuff. I do not get name completion for the actual Excel COM object's attributes as with Pythonwin.
> 
> Do I need a special setup?
> 
> We would love to use Wing as it seems to be THE Python editor. We deal with COM and .NET quite a lot so this is the last question mark.

 From reading the win32com sources, it looks like the Dispatch class
does things entirely via a __call__ method, and that doesn't ever
add the methods/etc for the wrapped class to the wrapper, so even
at runtime in the Debug Probe or Python Shell it's not possible for
Wing to determine what the methods should be.

I'm fairly sure that PythonWin must contain some special code to
handle these.  I haven't found the code there yet but it may
just introspect the COM classes directly.  Wing isn't set up to
special case these.

One way to work around this would be to generate *.py skeletons for the
COM objects you're using, store them on disk and create a wrapper for
each creation that is something like this:

def CreateExcelApplication():
   retval = win32com.client.Dispatch("Excel.Application")
   import excel_application_skeleton
   isinstance(retval, excel_application_skeleton.ExcelApplication)
   return retval

Then at point of use do the following instead of calling Dispatch
directly:

excel = CreateExcelApplication()

You'll should get both the names in the wrapper and the skeleton
when you do 'excel.'

We're planning on trying to make this kind of thing possible in
the future w/o altering code, but for now the above is the way
to handle this case.

Please let me know if you run into any problems with it, or there's
something I need to clarify.

Thanks,

-- 

Stephan Deibel
Wingware | Python IDE
Advancing Software Development

www.wingware.com



More information about the wingide-users mailing list