Tk Source Code

View Ticket
Login
Ticket UUID: 81c3ef93148d17ff280d9a0b4c4edfce453b972
Title: Tk Scale `from` attribute not rounded
Type: Bug Version: 8.6.10
Submitter: E-Paine Created on: 2020-08-03 14:10:20
Subsystem: (unused) Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-08-17 21:20:47
Resolution: Invalid Closed By: fvogel
    Closed on: 2020-08-17 21:20:47
Description:
Commit 591f68cb38 changed the behaviour of the ConfigureScale method so
​that the `from` and `to` arguments were rounded relative to the `from`
​value (the behaviour of `tickinterval` remained unchanged). This change
​means that lines 623 & 624 (of that blob) are equivalent to not rounding
​the new value at all. Is it intentional for the `from` value to no
​longer be rounded based on the `resolution`? For reference, this came to
​my attention due to a failure in the Python tkinter tests
​[https://bugs.python.org/issue41306].
User Comments: fvogel added on 2020-08-17 21:20:47: (text/x-fossil-wiki)
[d4bc0b58] removes the no-op (rounding of the fromValue to the resolution).

This is now merged into core-8-6-branch and trunk.

Thanks!

fvogel added on 2020-08-17 11:30:26: (text/x-fossil-wiki)
The default value for -resolution is 1 (i.e. the value displayed on the scale is integral). This is [https://www.tcl.tk/man/tcl8.6/TkCmd/scale.htm#M12|documented]. If in addition to your script you give -resolution 0.1 you will get what you expect.

Moreover, to see the ticks you need to specify -tickinterval to be something else than 0 (the default), say 0.5.

E-Paine added on 2020-08-17 09:35:54:
Thank you @fvogel for your comment (looking through those issues helped
​me understand why the patch was required). Another reason I posted this
​as a bug is the inconsistency when the `from` value has a higher
​precision than the resolution. Running the below script prints "14.9"
​but the scale shows its initial value to be 15 and cannot be set any
​lower (apologies if I am missing something but this seems like a
​confusing inconsistency).

pack [scale .s -orient horizontal]
.s configure -length 400 -bd 0 -from 14.9
puts [.s cget -from]

Granted, this is possibly not related to this issue as it can also be
​shown to happen when the scale is first created (see below script) but I
​cannot understand why the difference in behaviour between your and my examples.

pack [scale .s -orient horizontal -from 14.9 -to 16.9]
puts [.s cget -from]

fvogel added on 2020-08-16 14:17:25: (text/x-fossil-wiki)
That change was made to address [3003895fff] and [1899040fff]: "TkRoundToResolution doesn't account for -from".

When partially reverting as follows, so that -from gets rounded to the resolution again:
<verbatim>
-	scalePtr->fromValue = TkRoundValueToResolution(scalePtr,
+	scalePtr->fromValue = TkRoundIntervalToResolution(scalePtr,
 		scalePtr->fromValue);
</verbatim>
then the following example creates a scale that does not honor the given bounds (the obtained lower bound is 2 instead of 1, and the upper bound is 10 instead of 9):
<verbatim>
package require Tk
pack [scale .s -orient horizontal]
.s configure -length 400 -bd 0 -from 1 -to 9 -resolution 2 -tickinterval 1
</verbatim>

So basically yes, I would say this change is intentional but I'm open to analyze a better fix if someone is able to exhibit one.

Nevertheless, it's true the code could be simplified since [https://core.tcl-lang.org/tk/artifact/087d4422f5522b6e?ln=666,667|this line] actually does nothing.

chrstphrchvz added on 2020-08-03 15:04:48: (text/x-fossil-wiki)
Note for Fossil users: [https://github.com/tcltk/tk/commit/591f68cb38|git mirror commit 591f68cb38] corresponds to check-in [d7ca808d26]