Using wxPython in COM server

Robin Dunn robin at alldunn.com
Thu Dec 2 19:18:55 EST 1999


Mark Hammond <mhammond at skippinet.com.au> wrote in message
news:zW914.12685$VA6.61396 at news-server.bigpond.net.au...
> Nikolai Kirsebom wrote in message <3844dc35.143149908 at news.mch.sni.de>...
> >
> >I manage to get the dialog presented, but at the same time I get an
> >application error in winword.exe (The instruction at "0x...."
> >referenced memory at "0x0000000".  The memory could not be "read".)
> >
> >When I select OK in the application error message box, my dialog is
> >completely painted (static text and buttons), and I get e new message
> >box from the runtime library of Microsoft Visual C++ (Runtime error!
> >Program: C:\Program.....\Winword.exe abnormal program termination).
>
> Almost certainly a thread-state issue.  wxPython probably doesnt release
and
> acquire the Python thread-lock as it crosses the boundary from Python to C
> and back.  This is almost always the end result of that support missing.
Im
> afraid I can personally offer no additional advice - you need to speak to
> the wxPython guys and get thread support :-)
>

wxPython does handle the thread state properly (one final bug in that area
was squashed in the last release,) but the problem in this case is that there
is no wxApp object created.  It is during the initialization of the wxApp
object that wxPython initializes itself for proper thread state handling,
among other things.

At a minimum, you might try something like this:

   def RequestYesNo(self):
      from wxPython.wx import *
      class MyApp(wxApp):
          def OnInit(self):
              return true
      app = MyApp(0)

      win = wxDialog(NULL, -1, "HELLO", wxDefaultPosition, wxSize(350,200))
      wxStaticText(win, -1, "This is a wxDialog", wxPoint(20, 20))
      wxButton(win, wxID_OK,     " OK ", wxPoint(75,
120),wxDefaultSize).SetDefault()
      wxButton(win, wxID_CANCEL, " Cancel ", wxPoint(200, 120),wxDefaultSize)
      val = win.ShowModal()
      win.Destroy()
      return val


Although I am not sure what you might lose by not getting into the
app.MainLoop...


--
Robin Dunn
Software Craftsman
robin at AllDunn.com
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!









More information about the Python-list mailing list