[pygtk] strange spinbutton behavior
Tim Evans
t.evans at aranz.com
Thu Jun 28 08:46:51 WST 2007
James Dietrich wrote:
[snip]
> Hi,
>
> Thanks for the suggestions, but it's not what I need.
> Perhaps I didn't explain myself well enough.
>
> In the original example, I want and expect that the spinbutton
> should advance one digit at a time by clicking on the tiny
> arrows.
>
> It does work as expected if the adj_callback executes quickly,
> like if I uncomment the return statement in there.
>
> However, if that long loop executes in the callback (it takes
> several seconds at least), then the spinbutton advances by
> two digits for every one click.
>
> Any more ideas on how to make the spinbutton only advance
> one digit at a time even if the callback takes several seconds?
>
> Thanks for your help,
> James Dietrich
I think what might be happening is that the spinbutton arrow is thought
of as pressed until your callback finishes and GTK can go back to
handling events. Now, if spinbutton arrows are held down, they have a
repeat like the normal keyboard repeat. GTK registers the button as
being held down for a while and a repeat sneaks in there.
If this is the cause then you can fix it by moving the main work of your
handler to an idle callback, something like this:
def adj_callback(adj):
gobject.idle_add(_real_adj_callback)
def _real_adj_callback():
gtk.gdk.threads_enter()
try:
for x in range(10000000):
y = x * x
return False
finally:
gtk.gdk.threads_leave()
The threads enter/leave calls aren't needed if you're not using
threading, but for an action that can take several seconds you should
probably look at using them.
--
Tim Evans
Applied Research Associates NZ
http://www.aranz.co.nz/
More information about the pygtk
mailing list