No doubt it's bad idea, but time.sleep(1) was the simplest dirty hack to rule out any timing issues I could think of. :) I think I'll just invoke gnuplot on any replot request and update the image when process exists, as this program has no performance requirements and process spawning overhead isn't so much of a problem. If it causes any problems or I get an unused evening, will play with gtk.gdk.Pixbuf.

On 01/29/2013 04:06 AM, Niklas Koep wrote:
Glad to hear it, although I must say manually adding a delay sounds like an unreliable workaround. Putting a file monitor in place might look like an overkill solution, but it should work more reliably. Take a look at gio.FileMonitor. If you add a montior for a directory (or a specific file) and listen for events indicating metadata changes you should be able to determine when it's safe to read the image. Just a suggestion. Another solution I could think of would be to call gnuplot manually, setting its output to stdout and connecting to the process via pipe. That way you could get the raw image data and then manually construct a gtk.gdk.Pixbuf from that which you can in turn feed to a gtk.Image. Again, that's all just speculation though as I've never tried any of this myself. Best of luck.

Cheers.


2013/1/28 Daniil Baturin <[email protected] <mailto:[email protected]>>

    Niklas, you were right. Thanks a lot!
    I was using a gnuplot module and a quick look at it gave me
    impression it did take care of time issues and its method don't
    return until gnuplot task if finished. In fact it didn't, but
    sleep() inserted before set_from_file() fixed the issue.

    That module is not so perfect in other aspects too, so I guess I
    should either improve it and send patches back to the author or
    make a less general purpose synchronous interface myself. :)


    On 01/29/2013 03:28 AM, Niklas Koep wrote:
    I've tested the what I described earlier today and it works. If
    there are two distinct images on disk, then calling
    gtk.Image.set_from_file() will automatically update the image gtk
    displays. This leads me to believe that it's a timing issue
    you're facing. The plotter.plot() method wouldn't happen to be
    asynchronous, would it? Because if it is it might just be the
    case that you update the gtk.Image before the entire image
    generated by gnuplot has been written to disk. Obviously, that's
    just a guess since I don't know how your plot() method works
    internally. But it would explain why the first update of your
    image (sometimes) doesn't take and the image on disk actually
    appears correct if you look at it after a certain time.


    2013/1/28 Daniil Baturin <[email protected]
    <mailto:[email protected]>>

        I'm using set_from_file(), and it kind of works. The problem
        is that the image is updated only second time event handler
        that replots and invokes set_from_file() is triggered. I
        double checked replot occurs every time event is caught, when
        I open the image file manually it contains the updated plot.

        I added queue_redraw() after set_from_file(), but it didn't help.

        This is what I have there now:
          def apply_equations(self, widget, data):
                x_equation = data[0].get_text()
                y_equation = data[1].get_text()
                image = data[2]
                print "Equations: x=%s, y=%s" % (x_equation, y_equation)
                expression = x_equation + "," + y_equation
                plotter.set_expression(expression)
                plotter.plot()
                image.set_from_file("test.png")
                image.queue_draw()

        self.equations_apply.connect("clicked", self.apply_equations,
        (self.x_expression, self.y_expression, self.image) )




        On 01/28/2013 10:02 PM, Niklas Koep wrote:
        If you're updating your gtk.Image contents via its
        set_from_file() method you don't need to request an update
        at all -- it happens automatically. Generally speaking,
        however, gtk.Widget implements a queue_draw() method which
        can be used to invalidate the entire visible area of a
        widget which in turn causes it to be redrawn. For your use
        this doesn't seem to be required though. Hope this helps.



        2013/1/27 Daniil Baturin <[email protected]
        <mailto:[email protected]>>

            Hi,
            What is the proper way to reload gtk.Image contents?

            I want to make a simple educational gnuplot frontend
            that would allow playing with parametric curve
            coefficients by using spin buttons, expressions with
            substituted constants will be passed to gnuplot and
            generated png displayed in a gtk.Image. But I'm not sure
            how to request update of displayed image if the image
            has changed.


-- #!/usr/bin/env perl
            @a=split(//, "daniil @ baturin  .  org" );# Daniil Baturin
            @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i<24){$_.=
            chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print"$_\n"#

            _______________________________________________
            pygtk mailing list [email protected]
            <mailto:[email protected]>
            http://www.daa.com.au/mailman/listinfo/pygtk
            Read the PyGTK FAQ: http://faq.pygtk.org/




-- #!/usr/bin/env perl
        @a=split(//, "daniil @ baturin  .  org" );# Daniil Baturin
        @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i<24){$_.=
        chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print"$_\n"#


        _______________________________________________
        pygtk mailing list [email protected] <mailto:[email protected]>
        http://www.daa.com.au/mailman/listinfo/pygtk
        Read the PyGTK FAQ: http://faq.pygtk.org/




-- #!/usr/bin/env perl
    @a=split(//, "daniil @ baturin  .  org" );# Daniil Baturin
    @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i<24){$_.=
    chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print"$_\n"#


    _______________________________________________
    pygtk mailing list [email protected] <mailto:[email protected]>
    http://www.daa.com.au/mailman/listinfo/pygtk
    Read the PyGTK FAQ: http://faq.pygtk.org/




--
#!/usr/bin/env perl
@a=split(//, "daniil @ baturin  .  org" );# Daniil Baturin
@b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i<24){$_.=
chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print"$_\n"#

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to