[wxPython] Active X and Excel

When I tried to take one of the Active X demos and used Excel I get
the following error message:

Traceback (innermost last):
� File "ActiveXWrapper_Excel.py", line 88, in ?
��� frame = TestFrame()
� File "ActiveXWrapper_Excel.py", line 80, in __init__
��� self.tp = TestPanel(self, sys.stdout)
� File "ActiveXWrapper_Excel.py", line 43, in __init__
��� self.excel = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)
� File "C:\Program Files\Python\wxPython\lib\activexwrapper.py", line 102, in axw__init__(0, 0, sz.width, sz.height), self._wnd, ID)

� File "C:\Program Files\Python\Pythonwin\pywin\mfc\activex.py", line 23, in CreateControl self.__dict__["_obj_"] = win32ui.CreateControl(clsid, windowTitle, style, rect, parent, id)
win32ui: CreateControl failed
Exception exceptions.AttributeError: "'None' object has no attribute 'Cleanup'"
in <method TestPanel.__del__ of TestPanel instance at a94cb0> ignored

Of course the Active X demos that are supplied with wxPython and the
current Pywin work.

Here's the code that is failing:

"""
<html><body>
This demo shows how to embed an ActiveX control in a wxPython application, (Win32 only.)
<p>
The MakeActiveXClass function dynamically builds a new Class on the fly, that has the
same signature and semantics as wxWindow.� This means that when you call the function
you get back a new class that you can use just like wxWindow, (set the size and position,
use in a sizer, etc.) except its contents will be the COM control.
</body></html>
"""

from wxPython.wx import *

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

��� try:
������� excelModule = win32com.client.gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2)
��� except:
������� excelModule = None
������� raise ImportError("Excel does not appear to be installed.")

···

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

class TestPanel(wxPanel):
��� def __init__(self, parent, log):
������� wxPanel.__init__(self, parent, -1)
������� self.log = log

������� sizer = wxBoxSizer(wxVERTICAL)
������� btnSizer = wxBoxSizer(wxHORIZONTAL)

������� self.excel = None
�������
������� # this function creates a new class that can be used as a
������� # wxWindow, but contains the given ActiveX control.
������� ActiveXWrapper = MakeActiveXClass(excelModule.Application)

������� # create an instance of the new class
������� self.excel = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)

������� sizer.Add(self.pdf, 1, wxEXPAND)

������� btnSizer.Add(50, -1, 2, wxEXPAND)
������� sizer.Add(btnSizer, 0, wxEXPAND)

������� self.SetSizer(sizer)
������� self.SetAutoLayout(true)

��� def __del__(self):
������� self.excel.Cleanup()
������� self.excel = None

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

def runTest(frame, nb, log):
��� if wxPlatform == '__WXMSW__':
������� win = TestPanel(nb, log)
������� return win
��� else:
������� dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
������������������������� 'Sorry', wxOK | wxICON_INFORMATION)
������� dlg.ShowModal()
������� dlg.Destroy()

overview = __doc__

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

if __name__ == '__main__':
��� class TestFrame(wxFrame):
������� def __init__(self):
����������� wxFrame.__init__(self, None, -1, "ActiveX test -- Excel", size=(640, 480),
���������������������������� style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
����������� self.tp = TestPanel(self, sys.stdout)

������� def OnCloseWindow(self, event):
����������� self.tp.excel.Cleanup()
����������� self.Destroy()

��� app = wxPySimpleApp()
��� frame = TestFrame()
��� frame.Show(true)
��� app.MainLoop()

# create an instance of the new class
self.excel = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)

sizer.Add(self.pdf, 1, wxEXPAND)

            ^^^^^^^^^

self.excel?

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!