[wxPython] FW: Accessing Python stuff thru OLE...

Robin Dunn robin at alldunn.com
Fri Mar 23 16:58:02 EST 2001


>
> I used the example code at the end of this post.  I took the MyAboutBox
from
> the wxPython demo and tried opening it thru my OLE object.  Works great
the
> first time, but I get the only 1 instance of wxApp allowed per thread
> exception afterwords.  Anyway to fix this?

What version of wxPython do you have?  I went to remove this problem a
couple days ago and found that I had already ifdef'd it out of the code.  I
had forgotten that I was already experimenting with it.  Anyway, that change
was in version 2.2.5 so it should not have the restriction.  I've pasted in
a session from PythonWin below that shows this in action.

The main thing to watch out for now is that all wxPython stuff needs to
happen in the same thread as wxWindows keeps track of what it thinks is the
"main thread" and tries to ensure that everything to do with the GUI happens
there.

One little potential problem in your sample code is that you create a Dialog
but then treat it like a frame.  One of the differences between them is that
the dialog does not automatically delete itself when it is closed, so you
will have to call dialog.Destroy when you are done with it.



PythonWin 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2000 Mark Hammond (MarkH at ActiveState.com) - see
'Help/About PythonWin' for further copyright information.
>>> from wxPython.wx import *
>>> app = wxPySimpleApp()
>>> f = wxFrame(None, -1, "Hello", size=(150,75))
>>> b = wxButton(f, -1, "Click Me")
>>> f.Show(true)
1
>>> def hello(evt):
...  print "HELLO:", evt
...
>>> EVT_BUTTON(f, b.GetId(), hello)
>>> app.MainLoop()
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
>>>
>>> app2 = wxPySimpleApp()
>>> f = wxFrame(None, -1, "Hello", size=(150,75))
>>> b = wxButton(f, -1, "Click Me")
>>> EVT_BUTTON(f, b.GetId(), hello)
>>> f.Show(true)
1
>>> app2.MainLoop()
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
HELLO: <C wxCommandEvent instance at _12f244_wxCommandEvent_p>
>>>

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








More information about the Python-list mailing list