| Wolfram Humann 2005-05-20, 3:57 pm |
| Tk804.027
I have a problem using a Scale with a fractional -resolution (e.g. 0.1):
The -command callback sometimes (depending on reslution anc actual value
of the scale) gets called as soon as I enter the scale with the mouse or
move the mouse inside the scale. No button pressed -- just moving the mouse.
Scale.pm: <Motion> bound to Activate(). <Enter> bound to Enter() which
also calls Activate().
Scale/Activate.al: No callback called anymore, when I comment out
$w->configure(-state => 'active')
and
$w->configure(-state => 'normal')
Why do they execute the callback?
tkScale.c: ConfigureScale() calls TkScaleSetValue()
TkScaleSetValue() sets the INVOKE_COMMAND flag if the scale's value has
changed. This should not happen, when I just move the mouse. However,
TkScaleSetValue() does this to determine, if the value has changed:
} else if (scalePtr->value == value) {
Now, we all know it's a bad idea to compare "double" values for
equality. And indeed, printing scalePtr->value-value gives me lots of
xE-16 and xE-17. I changed the line above to
} else if (abs(scalePtr->value - value) <= 1E-12 * abs(value)) {
and all is well.
It might be even cleaner to include float.h and base the comparison on
some reasonable multiple of DBL_EPSILON.
|