Jotsite Water Cooler Area




Post a New Topic

Show Recent Topics 

Instantiating an ActiveX component with wxPython


I have been discussing this issue with Shi Sherebrin who have been able to make it work in his code. The original article where Shi posted the code is here: http://aspn.activestate.com/ASPN/Mail/Message/1392458
For my attempts, I have been stumped at the following smallest snippet of code that I have mustered up:
______________________________________
from wxPython.wx import *
from wxPython.lib.activexwrapper import MakeActiveXClass
import win32com.client.gencache

calendar = win32com.client.gencache.EnsureModule('{8E27C92E-1264-101C-8A2F-040224009C02}', 0, 7, 0)

ActiveXWrapper = MakeActiveXClass(calendar)
_________________________Error____________
...\site-packages\wxPython\lib\activexwrapper.py", line 60, in MakeActiveXClass
AttributeError: 'module' object has no attribute 'default_source' in activexwrapper.py
______________________________________

In this simplest of example, I am only trying to instantiate the built-in calendar activeX component. ActivexWrapper.py was last changed in July 2002, so it should have worked. The tool versions that I am using are:
ActivePython 2.2.2 build 224
wxPython 2.4.0.2, non-unicode

Shi, I am surprised your code works because plugging the changes you sent me in email, the above error still occurs. Additionally, it occurs with many other ActiveX components that I have tried it with.

Hoang Do
March 11, 2003 (13:55)


Hoang,

I'm using older versions (Python 2.1 and wxPy 2.3.3.1) - I wouldn't think that a newer version should break this, but I suppose it's possible.. I suggest the first thing to try is the demo code, to make sure THAT works, and go from there.

Also, you might want to read up on PythonCOM, one link I found is http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Shi Sherebrin
March 11, 2003 (14:30)


Another thing - it's been a while since I looked at this stuff so I may not be remembering properly, but perhaps you need to run makepy on the COM object you want to use first?

Shi Sherebrin
March 11, 2003 (14:32)


Never say Never... Shi. I just had an instance of newer libraries breaking old code: http://jotsite.com/Watercooler/archives/000177.html

I have been searching for ways to do ActiveX for a while because 3 years ago I did some MFC work for Interval Research with a prototype product similar to TiVo. My attempt in doing Python and ActiveX didn't pan out six months ago so I dropped it. Now that I'm poking at wxPython and the two examples work beautifully, I am more hopeful.

Do you know whether your code still runs Shi? An answer either way would help before I attempt to contact Robin Dunn. So far, the tricky part seems to be trying to invoke an activeX component that do not yet have a container. Mark Hammond pointed it out here:
http://groups.google.com/groups?q=python+activex+container&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3AB5C09D.8040402%40ActiveState.com&rnum=2
I wonder if this has changed with wxPython's new releases.

Hoang Do
March 11, 2003 (16:01)


I didn't say never; in fact, I acknowledged the possibility that a newer version wouldn't work - but you seem to have mentioned that the latest demos do work. I'm afraid I won't be able to upgrade and test my existing code at this time. It really is just a stripped-down and slightly modified version of the existing WxPy demo, so I suspect you have other issues to deal with, possibly related to what you mentioned about COM containers, of which I know nothing. When I do have the opportunity to test my code with the latest WxPy version, I'll let you know.

Shi.

Shi
March 11, 2003 (17:23)


Hi, I think this might have a better result if you try this:

you have two lines that say this:
================================================

calendar = win32com.client.gencache.EnsureModule('{8E27C92E-1264-101C-8A2F-040224009C02}', 0, 7, 0)

ActiveXWrapper = MakeActiveXClass(calendar)
================================================
change them to this:

calendarModule = win32com.client.gencache.EnsureModule('{8E27C92E-1264-101C-8A2F-040224009C02}', 0, 7, 0)

ActiveXWrapper = MakeActiveXClass(calendarModule.Calendar)
=================================================

Keep in mind that a com module generated by makepy.py is going to have one or more classes in it derived from CoClassBaseClass (they will be all the classes listed after CoClassBaseClass is defined for your makepy generated module). These are going to be classes to derive from with MakeActiveXClass() function. There is only one CoClass in your ms calender module, it is called 'Calender' (capitalization matters). The default class error you are getting means you told MakeActiveXClass() which module to look in for the coclass but not which coclass in that module, and the fact that this module only has one coclass didn't help it decide.

THey are called coclasses btw, I think because they are meant to be one half of a multiple inheritance. I sent you a boilerplate module for this calender object, it shows how MakeActiveXClass() can spit out a class that multiply inherits from the coclass and an event handler class defined by you prior to calling MakeActiveXClass(). This is how you will want to catch COM events and handle them in python.

Remember also that MakeActiveXClass() returns a class, in this case we are calling it ActiveXWrapper (I would have preferred ActiveXWrapperClass). To use this generated class you will have to instantiate it, e.g.:

calObj = ActiveXWrapper(parent, id = -1)

the arguments are because the CoClass is derived way back there from wxWindow, and thus you need to provide the default wxWindow parameters.

The end result is that ActiveXWrapper is multiply derived from the COM CoClass and an event class, and the COM CoClass is derived from wxWindow with COM wrappings thrown in, so you need to treat your calObj like a wxWindow, and give it a parent, an ID, a size and pos if you wish, etc.

Thomas Ellis
March 20, 2003 (13:10)


Thanks Thomas.... after struggling a bit, I have been able to make it work. I hope you will submit the recipe to the Python Cookbook as you have mentioned.

Unfortunately the ActiveX doesn't cooperate with BOA because BOA doesn't support sizers.

Hoang
March 23, 2003 (20:07)




Write a Reply