pylab and gtk : the main windows close !

I have a problem : I wrote a little GUI with glade, python

    > and pygtk. This GUI produce one or many figures to plot
    > results, depend on what the user click. To plot a new
    > figure, I use from pylab import * an figure(). My GUI is
    > a one windows GUI.

    > The problem is : when 1 figure + the main window is open
    > and I close this figure, the main window also close !

You should not mix pylab with GUI programming. You must use OO
matplotlib instead http://matplotlib.sf.net/faq.html#OO. pylab will
try and manage the figure windows for you, which is causing your
problem.

See examples/embedding_in_gtk*.py and examples/mpl_with_glade.py

    > When my main scipt is run with the ipython console with
    > 'run my_gui.py' , it works. But with 'python my_gui.py',
    > it doesn't work.

This is a quirk resulting from the fact that in "interactive" mode,
which ipython sets, destroying the last window managed by pylab
doesn't result in a main quit

    > What is trick ?

See above :slight_smile:

JDH

matplotlib seems to be more heavy to use.

I don’t want figure embeded my gtk main window.

I just a gtk main windows with 3 buttons: plot_this, plot_that,
plot_all.

And new figure appairs when I click on it.

It is for users that absolutly does’nt want to deal with script.

I spend my time plotting figure and pylab seems to be easy, quick and
elegant.

If I can plot a result in 1 line, I prefer.

So in this context, is pylab a bad choise ?

John Hunter a écrit :

···

<sgarcia@…839…>http://matplotlib.sf.net/faq.html#OOhttp://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=clickMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Samuel GARCIA
CNRS - UMR5020
Universite Claude Bernard LYON 1
Laboratoire des Neurosciences et Systemes Sensoriels
50, avenue Tony Garnier
69366 LYON Cedex 07
04 37 28 74 64

I read the doc of pythonic_matplotlib.py and I think I am the case
where I should use ‘from pylab import *’

no ?

I don’t want to manage each win, each toolbar and each canvas.

I want a gtk interface with no canvas and many independents figures
started by the main window

sam

John Hunter a écrit :

···

<sgarcia@…839…>http://matplotlib.sf.net/faq.html#OOhttp://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=clickMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Samuel GARCIA
CNRS - UMR5020
Universite Claude Bernard LYON 1
Laboratoire des Neurosciences et Systemes Sensoriels
50, avenue Tony Garnier
69366 LYON Cedex 07
04 37 28 74 64

matplotlib seems to be more heavy to use.

I think you mean "harder".

I don't want figure embeded my gtk main window.
I just a gtk main windows with 3 buttons: plot_this, plot_that, plot_all.
And new figure appairs when I click on it.
It is for users that absolutly does'nt want to deal with script.
I spend my time plotting figure and pylab seems to be easy, quick and elegant.
If I can plot a result in 1 line, I prefer.
So in this context, is pylab a bad choise ?

Pylab is for interactive use. See
http://matplotlib.sourceforge.net/interactive.html
for a discussion of the issues.

So if you can create your figures ahead of time and just
load them, that's fine. But if you want to create them
on the fly, you should use Matplotlib's OO functionality.
Maybe the function below will be a bit helpful for
getting started. (Caution: it's a novices effort.)

Alan Isaac

def show_tkagg(figure,title=''):
  """Create a new matplotlib figure manager instance.
  """
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  #_focus = windowing.FocusManager()
  window = Tk.Tk()
  window.wm_title(title)
  canvas = FigureCanvasTkAgg(figure, master=window)
  canvas.draw()
  canvas.get_tk_widget().pack()
  Tk.mainloop()

···

On Tue, 15 Nov 2005, Samuel CIA apparently wrote:

Yes I understand the solution I try it, it work but the problem comes
with when I try text() function of pylab that does’nt exist in
matplotlib.

I think it’s to much work for me to rewrite functions that are in pylab
and not in matplotlib.

I am a newbie and I don’t care to not write programs in pure pytonic
style.

from pylab import * is good for me.

I solve my first problem by changing in matplotlibrc :

backends : GTKAgg

the mix of TKAgg and GTK (my main windows) did not worked in fact.

But I don’t want to change the matplotlibrc for each user so I want to
do this in the code.

Also in ipython in GTKAgg doesn’t work for me.

I tryed in my code :

from pylab import *

rcParams[‘backends’]= ‘GTKAgg’

but it failed

thanks

sam

Alan G Isaac a écrit :

···

http://matplotlib.sourceforge.net/interactive.htmlhttp://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=clickMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Samuel GARCIA
CNRS - UMR5020
Universite Claude Bernard LYON 1
Laboratoire des Neurosciences et Systemes Sensoriels
50, avenue Tony Garnier
69366 LYON Cedex 07
04 37 28 74 64

Samuel GARCIA wrote:

I try text() function of pylab that does'nt exist in matplotlib.
I think it's to much work for me to rewrite functions that are in pylab and not in matplotlib.

It may well be too much work for you, but I hope, as a group, we will some day, get ALL of the pylab functionality into a nice OO interface in matplotlib. But I'm not one to talk, I haven't contributed anything yet.

I am a newbie and I don't care to not write programs in pure pytonic style.
from pylab import * is good for me.

It is a bad habit to get into however. I beleive that strongly. That being said, pylab was written with this in mind, so go for it.

I tryed in my code :
from pylab import *
rcParams['backends']= 'GTKAgg'

do this instead:

import matplotlib
matplolib.use('GTKAgg')
from pylab import *
# or better: import pylab

The reason is that when pylab has been imported, it is too late to change back ends

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...