Using wxPython in COM server

Robin Dunn robin at alldunn.com
Fri Dec 3 15:35:07 EST 1999


Robin Becker <robin at jessikat.demon.co.uk> wrote in message
news:CLP9PCAkD+R4EwQr at jessikat.demon.co.uk...
> In article <d0E14.1$002.65844 at news.randori.com>, Robin Dunn
> <robin at alldunn.com> writes
> ...
> >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...
> >
> ...
>
> I tried this snippet and it works the first time, but complains about
> only being allowed one app per process. How do I shut down wxPython
> cleanly and later restart it?

Did you do the win.Destroy()?  That message is generated if there are any
exiting top level windows when you try to create a new app object.

Actually, now that I think about it for a minute, this is the problem of not
getting into the MainLoop.  Top level windows don't delete themselves when
Destroy is called because there may still be pending events.  So instead they
are deleted in idle time which is processed as part of the main loop.

Try this:  Add a call to app.MainLoop() just before the last line.  This
should return almost immediately because once it deletes the wxDialog there
will be no top level windows left and that is the signal for the mainloop to
terminate.


--
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