Help with c++ embedding

Hello,

I’m using boost python to run python embedded in a C++ application on windows. I would like to be able to have the scripts that run in this embedded environment be able to display matplotlib plots. I have searched in vain for information on the nuances of running matplotlib pylab plots in an embedded c++ environment and am hoping someone can help me out.

My C++ application has an event handler to run a python script when the user so chooses. From this main message thread I execute a script file (using boost::python::exec_file() ) and if that script does a pylab plot of data the first time through everything works fine. An example script would be something like:

fig = pylab.figure()
pylab.imshow( myImage )
pylab.show()

I am able to interact with the plot window just fine and close it from the upper right window controls. However, if I run the same script again from my app the figure window comes up with my data but the window is now dead. I am unable to interact or even close the figure window. When I try to move the window my app crashes.

I want the plotting to behave synchronously so that control is not returned to my app until the plot is dismissed. However, after the first show it seems that interactivity is automatically enabled for matplotlib. I’ve tried explicitly turning interactivity off in the script ( pylab.ioff() ) but show seems to automatically turn it back on.

I’m just not sure of all I need to do to get this working so that I can bring up the plot over and over. BTW I’ve configured my matplotlib with a wxAgg backend. Can anyone help me out here or point me to information on embedding matplotlib in c++? Thanks in advance….

J.D.

Hello,

I'm using boost python to run python embedded in a C++ application on
windows. I would like to be able to have the scripts that run in this
embedded environment be able to display matplotlib plots. I have searched
in vain for information on the nuances of running matplotlib pylab plots in
an embedded c++ environment and am hoping someone can help me out.

Alexander Schmolck reported similar problems trying to call pylab from
an embedded app. My response to him at the time was:

  > Eeeeew, that looks really dangerous. For starters, I would never try
  > to do this using pylab, but rather follow the lead of
  > examples/embedding_in_qt.py. Then you won't be competing for the
  > mainloop....

I CCd him on this email. Perhaps he has made some progress since his
original attempts and can advise...

JDH

···

On Nov 27, 2007 12:10 PM, J.D. Herron <jotadehace@...287...> wrote:

My C++ application has an event handler to run a python script when the user
so chooses. From this main message thread I execute a script file (using
boost::python::exec_file() ) and if that script does a pylab plot of data
the first time through everything works fine. An example script would be
something like:

fig = pylab.figure()
pylab.imshow( myImage )
pylab.show()

I am able to interact with the plot window just fine and close it from the
upper right window controls. However, if I run the same script again from
my app the figure window comes up with my data but the window is now dead.
I am unable to interact or even close the figure window. When I try to move
the window my app crashes.

I want the plotting to behave synchronously so that control is not returned
to my app until the plot is dismissed. However, after the first show it
seems that interactivity is automatically enabled for matplotlib. I've
tried explicitly turning interactivity off in the script ( pylab.ioff() )
but show seems to automatically turn it back on.

I'm just not sure of all I need to do to get this working so that I can
bring up the plot over and over. BTW I've configured my matplotlib with a
wxAgg backend. Can anyone help me out here or point me to information on
embedding matplotlib in c++? Thanks in advance….

J.D.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

John Hunter wrote:

  > Eeeeew, that looks really dangerous. For starters, I would never try
  > to do this using pylab,

exactly. the question is -- what GUItoolkit are you using with C++? hopefully it is wx or qt (you'd be using C with GTK, right?).

If so, then use the appropriate back-end, use it like the embedding_in examples, and then it's like using GUI toolkit calls with a mixed C++/Python app without MPL -- use the appropriate GUI mailing list for questions about that.

If you're not using a GUI toolkit at all with C++, I'd be inclined to reverse your approach, and use Python+wx (opr QT, or GTK) to host your app, and extend with the C++.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...