[python-win32] any hope for a wxWindows COM server?

Dave Primmer primmer@hotmail.com
Tue, 30 Apr 2002 02:07:58 -0700


Has anybody got sample code of a working wxWindows COM server? I'm actually 
using PythonCard but if I could see how it was done in wxWindows that might 
help. I also have some basic questions about how to connect with a client. 
The client would want to attach to a running copy of the COM server the same 
way you can use the copy of Word that's running if it's already started.

I've got the COM server and client samples from win32all working so I know 
how to do the Non-GUI stuff.

Here's an attempt to wxPython a simple example. This is the text sample from 
the wxWiki tutorial with added basic COM server stuff:

#########################################
#comserver.py

from wxPython.wx import *

class MainWindow(wxFrame):
    _reg_clsid_ = "{0D583BF3-1106-4CEF-A540-7D3D9AC336A8}"
    _reg_desc_ = "Python Test COM Server"
    _reg_progid_ = "wxPython.COMserver"
    _public_methods_ = ['Hello']

    def __init__(self,parent,id,title):
        wxFrame.__init__(self,parent,-4, title, size = ( 200,100),
             style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
        self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE)
        self.control.WriteText("hello ")
        self.Show(true)

    def Hello(self, who):
        self.control.WriteText("Hello " + who)

if __name__=='__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(MainWindow)

    app = wxPySimpleApp()
    frame = MainWindow(None, -1, "Small editor")
    frame.Show(1)
    app.MainLoop()

###################################
#and comclient.py

import win32com.client
w = win32com.client.Dispatch('wxPython.COMserver')
w.Hello('bob')


############################
here's the error I get when I try to run the com client

  File "C:\web\scripts\python\comclient.py", line 2, in ?
    w = win32com.client.Dispatch('wxPython.COMserver')
  File "C:\Python22\lib\site-packages\win32com\client\__init__.py", line 92, 
in Dispatch
    dispatch, userName = 
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line 81, 
in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line 72, 
in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, 
pythoncom.IID_IDispatch)
com_error: (-2147467259, 'Unspecified error', None, None)



_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx