how to use activex in wxpython with event support

wang xiaoyu wxyisok at hotmail.com
Fri Jan 2 07:15:47 CET 2004


Hello:
i want use activex in wxpython program,but when i use MakeActiveXClass
an exception occurs.

this is my source code dealing the DICOM ocx.I must note that in this
program "hwtxcontrol" is a ocx developed my me use vc6,this ocx works
fine in wxpython.

but you can see i only change this ocx with a new DICOM ocx and set up
eventClass,

but the exception occure:

File ".\site-packages\wxPython\lib\activexwrapper.py", line 105, in
axw__init__
  File "D:\Py22\lib\site-packages\win32com\gen_py\3A75EE8D-8E68-43FF-A90A-E4835B9A3DBDx0x1x0.py",
line 187, in __init__
    cookie=cp.Advise(win32com.server.util.wrap(self,
usePolicy=EventHandlerPolicy))
com_error: (-2147220990, 'CONNECT_E_CANNOTCONNECT', None, None)

the ocx and the source code (in delphi) you can down at:

http://www.psychology.nottingham.ac.uk/staff/cr1/dicomcom.html

from wxPython.wx import *
from wxPython.lib.rcsizer import RowColSizer
import pywin.mfc.activex
import activexwrapper,win32ui

if wxPlatform == '__WXMSW__':
    from wxPython.lib.activexwrapper import MakeActiveXClass    
    import win32com.client.gencache
    import win32com.client
    try:
        import hwtxcontrol
        hwtxocx=hwtxcontrol
        #import ezdicom
        #dicomocx=ezdicom
        #dicomocx=win32com.client.gencache.EnsureModule("{3A75EE8D-8E68-43FF-A90A-E4835B9A3DBD}",0,1,0)
        #dicomocx=win32com.client.Dispatch("ezDICOMax.ezDICOMX")
        dicomocx=win32com.client.gencache.EnsureModule('{3A75EE8D-8E68-43FF-A90A-E4835B9A3DBD}',
0, 1, 0)
    except:
        raise ImportError("IE4 or greater does not appear to be
installed.")

    class DicomControl(pywin.mfc.activex.Control, dicomocx.ezDICOMX):
        def __init__(self):
            pywin.mfc.activex.Control.__init__(self)
            dicomocx.ezDICOMX.__init__(self)
        def OnDCMmouseDown(self, X ,Y ,Button ,Shift):
                print "DICOM ocx Click!"

    class HwtxControl(pywin.mfc.activex.Control, hwtxocx.Hwtx):
        def __init__(self):
            pywin.mfc.activex.Control.__init__(self)
            hwtxocx.Hwtx.__init__(self)
        def OnClick(self):
            print "hwtx click!"
class TestPanel(wxWindow):
    def __init__(self, parent, log, frame=None):
        wxWindow.__init__(self, parent, -1,
                         
style=wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
        sizer = wxBoxSizer(wxVERTICAL)
        hwtxCtls=RowColSizer()
        theClass2 = MakeActiveXClass(dicomocx.ezDICOMX,eventClass=DicomControl)
        #theClass2 =
MakeActiveXClass(hwtxocx.Hwtx,eventClass=HwtxControl)
        self.ie4=theClass2(self,-1)
        self.ie4.SetSize(wxSize(300,300))
        #self.ie4.filename="e:\\d02.img"
        #self.ie4.palnumber=12
        #self.ie4.state=1
        hwtxCtls.Add(self.ie4, row=2, col=2)
        sizer.Add(hwtxCtls, 0, wxEXPAND)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        EVT_WINDOW_DESTROY(self, self.OnDestroy)
    def OnDestroy(self, evt):
        if self.ie4:
            self.ie4.Cleanup()
            self.ie4 = None

def runTest(frame, nb, log):
    if wxPlatform == '__WXMSW__':
        win = TestPanel(nb, log, frame)
        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 -- Internet
Explorer",
                             size=(640, 480),
                            
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
            self.CreateStatusBar()
            self.tp = TestPanel(self, sys.stdout, self)
            EVT_CLOSE(self, self.OnCloseWindow)

        def OnCloseWindow(self, evt):
            self.tp.Destroy()
            self.Destroy()

    app = wxPySimpleApp()
    frame = TestFrame()
    frame.Show(True)
    app.MainLoop()

i am a new python programer but i was really attracted by it elegant
code.i really want use wxpython as my framework,but if i cant use
activeX,i will have to change to vb:(

can you help me.Best regards.

sincerely 

wangxiaoyu



More information about the Python-list mailing list