I should have mentioned that I was using the Mac OS X port of clutter.
I just tested the sample using the GLX backend, and it works as
expected:

When using an idle function, or connect_after paint, the stage is
redrawn after the function terminates, no matter how long the function
takes to terminate.

gobject.idle_add(timeout_cb)
stage.connect_after('paint', timeout_cb)

(It doesn't redraw with gobject.timeout_add, but I guess that's
correct behaviour because timeout_add has a higher priority.)

I guess this is a bug in the Mac OS X port then, so I will probably open a bug.

Are there any comments on this?

Thomas


On Thu, Dec 25, 2008 at 1:53 PM, Thomas Steinacher <[email protected]> wrote:
> Hello,
>
> I have a certain device which sends messages via UDP. These messages
> have effect on the stage rendering, which means I need to get them
> periodically. The question is, what's the best way to do this? The
> callback should be triggered between every redraw, i.e. there should
> be no two stage redraws without the callback being called between the
> redraws. Also, if the callback triggers a redraw, it shouldn't be
> called again until the redraw happened. If the callback doesn't
> trigger a redraw, it should be called again "very soon" (= n times per
> second) to check for messages again.
>
> Currently I am using gobject.timeout_add. This usually works okay, but
> it has side effects which I don't want. Consider the code below. The
> texture's position is never updated on my machine. If I uncomment
> "time.sleep", everything is fine. I considered using gobject.idle_add
> as well (uncommented below). This also doesn't give me the desired
> effect: The texture is not drawn at all. Another thing I tried is to
> connect after the stage is painted (also uncommented below). This
> doesn't work either. The stage is painted a few times and the callback
> is never called again.
>
> I am now thinking about not using clutter_main, but a custom loop
> which calls my callback after every gobject.MainContext.iteration().
> But before I take it that far, I'd like to hear your opinions.
>
> Thanks,
>
> Thomas
>
>
>
> import clutter
> import gobject
> import time
>
> # Assume 20 frames per second.
>
> def timeout_cb(stage=None):
>    global texture
>
>    # Here I would actually check the messages.
>    # To illustrate the problem, let's just move the actor by one pixel.
>
>    x, y = texture.get_positionu()
>    print 'updating', x
>    x += 1
>    texture.set_positionu(x, y)
>
>    # Sometimes this function can be slow. In that case redraws are blocked.
>    time.sleep(0.05)
>
>    return True
>
> stage = clutter.Stage()
> stage.set_size(640, 480)
> stage.connect('key-press-event', clutter.main_quit)
>
> texture = clutter.Texture()
> texture.set_from_file("mypic.png")
> stage.add(texture)
>
> # Set up a callback which updates the stage periodically.
> gobject.timeout_add(50., timeout_cb)
> # gobject.idle_add(timeout_cb)
> # stage.connect_after('paint', timeout_cb)
>
> stage.show_all()
> clutter.main()
>
-- 
To unsubscribe send a mail to [email protected]

Reply via email to