Displaying wxPython objects from another application's embedded interpreter

Hmmm, clumsy subject line but here's my situation:

A commercial application that we use (Abaqus/CAE, fwiw) has an embedded
Python interpreter. It allows access to the interpreter through a
plugin architecture.

We have developed several applications/classes/widgets in wxPython.
We'd like to call some of these classes from CAE and return data. The
workflow would be to call the class (displaying a wxFrame for example),
have the user interact with the class, and then have the class return
some data to the calling function.

If I do this by just importing the class and trying to display the
frame, the interpreter throws an exception "wx._core.PyNoAppError: The
wx.App object must be created first!".

OK, fair enough. I'm a little leery about creating an instance of
wx.App when it's not the main thread, but I gave it a go. This worked
much better, the frame popped up and I was able to interact with it.
However, when I closed the frame, control didn't return to the embedded
interpreter.

Now I haven't put a lot of time into troubleshooting this, but when I
run the class from the command line, it behaves: pops up the frame,
interaction happens, and on closing the frame it exits nicely back to
the command line.

So my question is, am I taking the right tack here? Should I be
instancing a new wx.App every time I want to display a dialog and then
make sure it cleans up nicely when it closes? Or is there some other
approach I can take here? I looked at Robin's PIA book, and I've looked
through some of the stuff in the documents & demos, but nothing quite
matches what I think I'm looking for.

Anyone have some insight?

Thanks,
Anthony.

···

--
Anthony Floyd, PhD
Convergent Manufacturing Technologies Inc.
6190 Agronomy Rd, Suite 403
Vancouver BC V6T 1Z3
CANADA

Email: Anthony.Floyd@convergent.ca | Tel: 604-822-9682
WWW: http://www.convergent.ca | Fax: 604-822-9659

CMT is hiring: See http://www.convergent.ca for details

Anthony M. Floyd wrote:

Hmmm, clumsy subject line but here's my situation:

A commercial application that we use (Abaqus/CAE, fwiw) has an embedded
Python interpreter. It allows access to the interpreter through a
plugin architecture.

We have developed several applications/classes/widgets in wxPython.
We'd like to call some of these classes from CAE and return data. The
workflow would be to call the class (displaying a wxFrame for example),
have the user interact with the class, and then have the class return
some data to the calling function.

If I do this by just importing the class and trying to display the
frame, the interpreter throws an exception "wx._core.PyNoAppError: The
wx.App object must be created first!".

OK, fair enough. I'm a little leery about creating an instance of
wx.App when it's not the main thread, but I gave it a go.

Whichever thread makes the wx.App is the main thread as far as wx is concerned.

This worked
much better, the frame popped up and I was able to interact with it.
However, when I closed the frame, control didn't return to the embedded
interpreter.

Did you call the app's MainLoop method or were you just letting the events be dispatched from Abaqus's event loop? If the wx MainLoop doesn't run then the frame won't get cleaned up after it closes.

Now I haven't put a lot of time into troubleshooting this, but when I
run the class from the command line, it behaves: pops up the frame,
interaction happens, and on closing the frame it exits nicely back to
the command line.

So my question is, am I taking the right tack here? Should I be
instancing a new wx.App every time I want to display a dialog and then
make sure it cleans up nicely when it closes? Or is there some other
approach I can take here? I looked at Robin's PIA book, and I've looked
through some of the stuff in the documents & demos, but nothing quite
matches what I think I'm looking for.

Anyone have some insight?

While it's theoretically possible to create and destroy apps along the way, it usually ends up being lots better if you can limit it to just one app in the process. But without knowing more about the environment the host app provides and how it sets up the Python interpreter. There are a few other things that can go wrong if there are conflicts there.

···

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