[wxPython] trying to simplify ActiveX wrapper program

Dear wxPyrts,

I've taken the IEActiveX wrapper demo program and am trying to simplify it to use a different ActiveX module, with minimal windows (I don't need a visible GUI for this). I understand that I need a wxFrame to contain the wxWindow object that is the ActiveX wrapper, but don't understand what I'm doing wrong below in the wxApp definition (the code as written crashes) - could someone please help and describe what needs to change for this to work? let me know if you want a version that uses the IEActiveX module so that you can run it to see what happens.

thanks,
Shi.

-=0=-

from wxPython.wx import *

if wxPlatform == '__WXMSW__':
     from wxPython.lib.activexwrapper import MakeActiveXClass
     import win32com.client.gencache

     try:
         mcmModule = win32com.client.gencache.EnsureModule("{941C4020-3357-11D5-94B2-006008904BC2}", 0, 1, 0) # {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}, 0, 1, 1 for IE
     except:
         raise ImportError("The ActiveX MCM control module does not appear to be installed.")

···

#----------------------------------------------------------------------

class TestPanel(wxWindow):
     def __init__(self, parent, log, frame=None):
         wxWindow.__init__(self, parent, -1)
         self.mcm = None
         self.log = log
         self.frame = frame
         if frame:
             self.titleBase = frame.GetTitle()

         # Make a new class that derives from the MCMActiveX class in the
         # COM module imported above. This class also derives from wxWindow and
         # implements the machinery needed to integrate the two worlds.
         theClass = MakeActiveXClass(mcmModule.MCMActiveX,
                                     eventObj = self)

         # Create an instance of that class
         self.mcm = theClass(self, -1)

  # specific call used to init the ActiveX module
         self.mcm.Initialize('.\\MoverCalibration.xml', 'ECRMIII')

         EVT_WINDOW_DESTROY(self, self.OnDestroy)

     def OnDestroy(self, evt):
         if self.mcm:
             self.mcm.Cleanup() # not sure if this is a generic function or needs to exist in the COM object
             self.mcm = None
             self.frame = None

     # The following event handlers are called by the web browser COM
     # control since we passed self to MakeActiveXClass. It will look
     # here for matching attributes and call them if they exist. See the
     # module generated by makepy for details of method names, etc.

     def OnLeftFootSwitchDownEvent(self):
         self.log.write('Left Footswitch Down\n')
         if self.frame:
             self.frame.SetStatusText(text)

     def OnLeftFootSwitchUpEvent(self):
         self.log.write('Left Footswitch Up\n')
         if self.frame:
             self.frame.SetStatusText(text)

     def OnRightFootSwitchDownEvent(self):
         self.log.write('Right Footswitch Down\n')
         if self.frame:
             self.frame.SetStatusText(text)

     def OnRightFootSwitchUpEvent(self):
         self.log.write('Right Footswitch Up\n')
         self.parent.Close()
         if self.frame:
             self.frame.SetStatusText(text)

#----------------------------------------------------------------------

if __name__ == '__main__':
     class TestApp(wxApp):
         def __init__(self):
             self.frame = wxFrame(None, -1, "ActiveX test -- MCM",
                              size=(640, 480), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

             self.tp = TestPanel(self.frame, sys.stdout, self.frame)

         def OnExit(self):
             print 'in OnExit\n'
             self.frame.Destroy()
             self.frame = None
             if self.tp.mcm:
                 self.tp.mcm.Cleanup()
                 self.tp.mcm = None

     app = TestApp()
     app.MainLoop()

Shi Sherebrin wrote:

Dear wxPyrts,

I've taken the IEActiveX wrapper demo program and am trying to simplify it to use a different ActiveX module, with minimal windows (I don't need a visible GUI for this). I understand that I need a wxFrame to contain the wxWindow object that is the ActiveX wrapper, but don't understand what I'm doing wrong below in the wxApp definition (the code as written crashes) - could someone please help and describe what needs to change for this to work? let me know if you want a version that uses the IEActiveX module so that you can run it to see what happens.

If you're not going to show the windows then you probably don't want to use the ActiveX wrapper. You probably just want to use the win32com modules to access the COM object directly.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!