For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > May 2005 > Patch idea for tkScale.c









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Patch idea for tkScale.c
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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com