Hi guys.

TL;DR: is there a way to suppress the value-changed signal from being
emitted when I call SpinButton.set_value()?

My application needs to be able to let the user specify a length of
time, which I've chosen the SpinButton to represent (I like that it
accepts mouse wheel as input as well as typing and up/down buttons).

The way I'm doing this currently is with three separate SpinButtons,
one for hours, one for minutes, and one for seconds. When I need the
total time duration, I call get_value() on each of them, multiplying
hours by 3600 and minutes by 60, and summing the results, giving me a
total number of seconds representing a time duration. This works out
really well for me because my app uses epoch seconds for all internal
date logic.

The problem that I'm running into, however, is that I want the
SpinButtons to be able to overflow smoothly (eg, if hours says 0 and
minutes says 59 and seconds says 59 and the user clicks on the up
arrow of the seconds SpinButton, I want the spinbuttons to then read
as 1 hour, 0 minutes, 0 seconds.

I wrote some rudimentary code in my value-changed signal handler to
change these values, but I'm running into issues where calling
set_value() on a SpinButton causes it to re-emit the value-changed
signal, which in turn re-invokes my value-changed signal handler. In
the worst case, my signal handler is called 5 times for a single user
event (once for the user event, once to set the seconds spinbutton to
0, once again to change the minutes spinbutton from 59 to 60, once
again to set it from 60 to 0, and once again to set the hours from 0
to 1).

This turns into a pretty big disaster of race conditions and painful
logic where five instances of the method are running simultaneously.
Somehow, by some fluke of luck, the code I've written seems to work,
but I have no idea how or why. You can see it here:

https://github.com/robru/GottenGeography/blob/master/gottengeography.py#L673

I'm terrified that this delicate balance of race conditions is going
to blow up on some other computer that's perhaps not as fast as my
development machine.

Is there any way at all that I can suppress the value-changed signal
from being emitted while I'm setting the value of a SpinButton, that
would be a HUGE help to me. Failing that, however, is there some way
that I can program a single SpinButton to represent time in the form
of "HH:MM:SS"? (as opposed to three separate SpinButtons each
displaying an int). Ideally the SpinButton would handle the overflow
of seconds and minutes by itself, and get_value() would just give me
the total time in seconds.

Thanks!

-- 
http://exolucere.ca
_______________________________________________
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