[Matplotlib-users] matplotlib in GTK3 - interactive window while not calling Gtk.main()

Thomas Caswell tcaswell at gmail.com
Fri Apr 27 20:45:53 EDT 2018


Michael,

If you are doing custom embedding I suggest staying away from `pyplot`
altogether, it maintains global state you may not want, see for example
https://matplotlib.org/gallery/user_interfaces/embedding_in_gtk3_sgskip.html#sphx-glr-gallery-user-interfaces-embedding-in-gtk3-sgskip-py
 .

For the long answer to your question, see
https://github.com/matplotlib/matplotlib/pull/4779 (which I really need to
finish and get merged).  In short, to have both an interactive prompt and a
window you need to have an 'input hook' installed to time-share between the
GUI event loop an the prompt event loop.  It sounds like you change a bunch
of things at once (gtk2 -> gtk3 + matplotlib version bumps),  did you also
change IPython versions?  If so, you will need to use their input hook
mechanism explicitly (`%matplotlib gtk3` should do the trick) as they moved
from readline -> ptprompt so the input hooks the GUI libraries ship no
longer work.

It may also be worth checking the value of `mpl.get_backend()` to make sure
pyplot as not defaulted to another GUI framework (ex Qt5) and you have 2
GUI frameworks in the same process conflicting with each other!

Hope that helps!

Tom

On Sun, Apr 22, 2018 at 4:50 PM michalwd1979 <michalwd1979 at o2.pl> wrote:

> Dear Members,
> Recently I upgraded to from matplotlib 1.4.3 + gtk2 to matplotlib 2.2.2 +
> gtk3 and I have a problems with porting my old code.
> I'm using matplotlib in Gtk window with typical:
> win = Gtk.window()
> vbox = Gtk.Box(...)
> win.add(vbox)
> fig = pylab.figure()
> canvas = FigureCanvas(fig)
> toolbar = NavigationToolbar(canvas, fig)
> axis = fig.add_axes(...)
> vbox.pack_start(canvas,...)
> vbox.pack_start(toolbar,....)
> win.show_all()
> while(Gtk.events_pending()): Gtk.main_iteration()
>
> After this code I have a valid window on screen however it does not reacts
> on mouse clicks (zooming etc.) until calling Gtk.main_iteration() in loop
> or Gtk.main(). I can understand why, however it was working differently
> with old matplotlib and gtk2 (window was responsive all time).
> The rest of my code is a python "Text User Interface" application
> (controlled by commands typed to terminal), the window is only for showing
> the results (animated waveform). Now I would like to keep the application
> as it is, but also to have responsive matplotlib window, without calling
> Gtk.main(). Is it possible? If yes, then how to do this?
>
> Sorry for the long mail - I have no idea how to describe the problem
> shortly and all examples I found always have Gtk.main() called so they are
> in fact full GTK programs. I want a simple text program with matplotlib
> window as a "result showing" addition only.
> Best Regards,
> Michael Widlok
>
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180428/052e80cd/attachment.html>


More information about the Matplotlib-users mailing list