Note that there are some explanatory texts on larger screens.

plurals
  1. POCommunication between windows with python matplotlib using gtk.WindowGroup
    primarykey
    data
    text
    <p>I am developing an application in python which plots information using <strong>matplotlib</strong>, <strong>numpy</strong> and <strong>gtk</strong>. I am plotting numpy data using matplotlib, the user can change some parameters in widget to modify the plot </p> <p>For design reasons I want to separate the plot (and data) from the control GUI, then I am plotting the data in one window and I have the controls in a separated window. In <strong>gtk</strong> I found the <em>WindowGroup</em> widget that looks can send data over multiple windows, however I cannot find the how!</p> <p>The following code shows a simplification of the problem: I plot a sine in a window, the user can modify the variable <em>fm</em> in the window with the vertical adjustment bar (event). When I run the script I can see that the event (move the vertical adjustment bar) triggers the function but does't actualize the plot. </p> <p>How can change the plot? or send messages between two windows using the <em>WindowGroup</em> widget?</p> <pre><code>#!/usr/bin/python import gtk import numpy import matplotlib.pyplot as plt from matplotlib.backends.backend_gtkagg \ import FigureCanvasGTKAgg as FigureCanvas def update_hscale(event): global t fm = hscale.get_value() y_new = numpy.sin(2*fm*t) l.set_ydata(y_new) plt.draw() print "doing fm=", fm # define the window group window_group=gtk.WindowGroup() # matplotlib plot in window 1 fm = 5.0 t = numpy.arange(200) y = numpy.sin(2*fm*t) fig = plt.figure(1) ax = fig.add_subplot(111) l, = ax.plot(t, y) win1 = gtk.Window() win1.connect("destroy", gtk.main_quit) win1.set_default_size(800,300) vbox1 = gtk.VBox() canvas = FigureCanvas(fig) vbox1.pack_start(canvas, fill=True) win1.add(vbox1) # controls in window 2 win2 = gtk.Window() vbox2 = gtk.VBox() adj = gtk.Adjustment(0.0, -5, 5, 1.0, 1.0, 1.0) hscale = gtk.HScale(adj) hscale.set_size_request(200, 30) vbox2.pack_start(hscale) hscale.connect("value-changed", update_hscale) win2.add(vbox2) # adding windows to window_group window_group.add_window(win1) window_group.add_window(win2) win1.set_default_size(400,300) win1.show_all() win2.show_all() gtk.main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload