If you are embedding matplotlib, do not import `pyplot`.  `pyplot` sets up
a bunch of gui-magic (tm) in the background (as you found in
`figure_manager`).

Tom


On Fri, Oct 11, 2013 at 11:57 AM, Federico Ariza
<ariza.feder...@gmail.com>wrote:

> Hello everybody
>
> Working on one GTK3 app, that calls matplotlib to plot some figures, I
> found that closing all the figures from matplotlib kills my app also.
> The problem....
>
> Gtk.main() is called only if there is no previous invocation, in my
> case, my Gtk3 app invokes main, so the mainloop won't call it again.
>
> #in backend_gtk3.py
> #
> class Show(ShowBase):
>     def mainloop(self):
>         if Gtk.main_level() == 0:
>             Gtk.main()
>
> But in the "destroy" method of the figure manager calls Gtk.main_quit
> everytime that there are no more figures
>
> #in backend_gtk3.py inside destroy method of FigureManagerGTK3
> #
> if Gcf.get_num_fig_managers()==0 and \
>                not matplotlib.is_interactive() and \
>                Gtk.main_level() >= 1:
>             Gtk.main_quit()
>
>
> So basically we are not calling Gtk.main but we are Gtk.calling main_quit.
> Isn't it more natural to call Gtk.main the same amount of times that
> we are going to call Gtk.main_quit?
>
> Adding matplotlib.rcParams['interactive'] = True doesn't help
>
> Here is my little testing code
>
> ##############################
> #file myapp.py
>
> import matplotlib
> matplotlib.rcParams['interactive'] = True
> matplotlib.use('GTK3AGG')
> import matplotlib.pyplot as plt
>
> from gi.repository import Gtk
>
> class MyWindow(Gtk.Window):
>
>     def __init__(self):
>         Gtk.Window.__init__(self, title="Hello World")
>
>         self.button = Gtk.Button(label="Click Here")
>         self.button.connect("clicked", self.on_button_clicked)
>         self.add(self.button)
>
>     def on_button_clicked(self, widget):
>         fig = plt.figure()
>         ax = fig.add_subplot(111)
>         ax.plot([1,2,3])
>         plt.show()
>
> win = MyWindow()
> win.connect("delete-event", Gtk.main_quit)
> win.show_all()
> Gtk.main()
> #########################
>
> I know this is related to interactive mode, but running from console
> >>> python myapp.py
> reproduces the problem
>
> Why hasattr(sys, 'ps1') is False? if I am running it from console? how
> do I change this?
>
>
> Thanks
> Federico
>
> P.S. Does anybody had the time to check my PR for multi-figure-manager?
> https://github.com/matplotlib/matplotlib/pull/2465
>
> --
> Y yo que culpa tengo de que ellas se crean todo lo que yo les digo?
>
> -- Antonio Alducin --
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>



-- 
Thomas A Caswell
PhD Candidate University of Chicago
Nagel and Gardel labs
tcasw...@uchicago.edu
jfi.uchicago.edu/~tcaswell
o: 773.702.7204
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to