Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ttk::spinbox is there a way to do an invoke method?

227 views
Skip to first unread message

tedbr...@gmail.com

unread,
May 26, 2020, 10:39:35 AM5/26/20
to
With the regular TK spinbox, there's an invoke
method, but not in ttk::spinbox, that I can tell.

Is there some other way to do that?

Note that ttk::button has the invoke method. So this
would seem to be a natural for ttk::spinbox as well.

Where this really shines is in the simple code that
can be used to bind <MouseWheel> events to a spinbox.

See the example at the bottom of

https://wiki.tcl-lang.org/page/spinbox

One simple proc can handle all the spinboxes
that are given a <MouseWheel> binding. And the binding
is even identical for all of them.

It's even better now that focus isn't required
to receive <MouseWheel> events. IMO much easier than
clicking those (often) tiny arrows.

Harald Oehlmann

unread,
May 26, 2020, 11:19:18 AM5/26/20
to
Thank you. Do you use Tk8.6.10 or newer ?
MouseWheel is constantly improving.

You may look to the history on:

https://wiki.tcl-lang.org/page/mousewheel

Are you aware of the scrollutil package ?

If the spinbox in 8.6.10 has no scrollwheel bindings, I would consider
this as a bug and you may issue a ticket.

Thank you,
Harald

tedbr...@gmail.com

unread,
May 26, 2020, 2:13:24 PM5/26/20
to
On Tuesday, May 26, 2020 at 8:19:18 AM UTC-7, Harald Oehlmann wrote:


>Do you use Tk8.6.10 or newer ?

Yes, I use Ashok's latest tclkit/gui with twapi
on windows.

>Are you aware of the scrollutil package ?

I've seen it but my programs are pretty simple. My
latest program is a Tivo remote controller via a mouse.
It has 6 spinboxes to set various skipping parameters.
They're now all wheel enabled.

It's kinda cool to skip around a tv show using the
mouse wheel. I also built a vlc video player remote
that uses the mouse wheel.

>If the spinbox in 8.6.10 has no scrollwheel bindings, I would consider
this as a bug and you may issue a ticket.

I didn't see it there, but if added, perhaps as a configure
option with default off, to avoid any surprises.


I am considering a TIP for the invoke on ttk::spinbox if
nobody knows another way to do that. I have written code
to do a numerical only version to use the wheel, but I
think invoke should be there in ttk::spinbox anyway.


Here's what I came up with. The int conversions are probably
overkill.

###############

proc adjust_ttk {spinner value} { ;# for pos ints and a variable
foreach attribute {from to increment textvariable} {
set v [$spinner cget "-$attribute"]
set $attribute $v
}
set oldval [set $textvariable]
if { $value > 0 } {
set newval [expr {( int($oldval+.5) + int($increment+.5) )}]
if { $newval > $to } {
set newval $to
}
} else {
set newval [expr {( int($oldval+.5) - int($increment+.5) )}]
if { $newval < $from } {
set newval $from
}
}
set newval [expr {( int($newval+.5) )}]
set $textvariable $newval
}

set ::myvar 50
ttk::spinbox .spin -from 20 -to 300 -increment 10 -textvariable ::myvar -width 5 -font {helvetica 16}
bind .spin <MouseWheel> {adjust_ttk %W %D}
pack .spin

Harald Oehlmann

unread,
May 26, 2020, 2:54:24 PM5/26/20
to
Am 26.05.2020 um 20:13 schrieb tedbr...@gmail.com:
> On Tuesday, May 26, 2020 at 8:19:18 AM UTC-7, Harald Oehlmann wrote:
>
>
>> Do you use Tk8.6.10 or newer ?
>
> Yes, I use Ashok's latest tclkit/gui with twapi
> on windows.
>
>> Are you aware of the scrollutil package ?
>
> I've seen it but my programs are pretty simple. My
> latest program is a Tivo remote controller via a mouse.
> It has 6 spinboxes to set various skipping parameters.
> They're now all wheel enabled.
>
> It's kinda cool to skip around a tv show using the
> mouse wheel. I also built a vlc video player remote
> that uses the mouse wheel.
>
>> If the spinbox in 8.6.10 has no scrollwheel bindings, I would consider
> this as a bug and you may issue a ticket.
>
> I didn't see it there, but if added, perhaps as a configure
> option with default off, to avoid any surprises.

As the combobox has a default mousewheel binding to rotate through the
possibilities, I would just call that a bug and add it without an option.

An option would require a TIP.
Thank you for the implementation.
The author of scrollutil, Csaba Nemethi, has proposed the implementation
for ttk::scrollbar mouse wheel binding.
You may contact him or he will speak up here ;-)

Thank you,
Harald

tedbr...@gmail.com

unread,
May 26, 2020, 3:14:04 PM5/26/20
to
On Tuesday, May 26, 2020 at 11:54:24 AM UTC-7, Harald Oehlmann wrote:
>
> An option would require a TIP.

Ah yes, however, are you aware of the new email TIP
system? Much easier now.

> Thank you for the implementation.

You're most welcome, and thanks for fixing that
spinbox wiki page :)

nemethi

unread,
May 26, 2020, 3:58:03 PM5/26/20
to
Am 26.05.20 um 17:18 schrieb Harald Oehlmann:
The ttk::spinbox widget *does have built-in* MouseWheel bindings,
implemented in the Tk library file ttk/spinbox.tcl. These bindings invoke

event generate $w <<Increment>>

and

event generate $w <<Decrement>>

which are the ttk::spinbox counterparts of "invoke buttonup" and "invoke
buttondown".

--
Csaba Nemethi https://www.nemethi.de mailto:csaba....@t-online.de

tedbr...@gmail.com

unread,
May 26, 2020, 6:32:01 PM5/26/20
to
On Tuesday, May 26, 2020 at 12:58:03 PM UTC-7, nemethi wrote:

> The ttk::spinbox widget *does have built-in* MouseWheel bindings,

Interesting, it was there all along. It's actually
regular spinbox which don't have those bindings
and so I rolled my own with invoke.

When I tacked on the ttk:: to my spinboxes and the
invoke failed, I could have just removed my own
<MouseWheel> bindings and then it would have worked.

Checking the manual at:

http://www.tcl.tk/man/tcl8.6/TkCmd/ttk_spinbox.htm

does not have the default bindings section like
in spinbox. Perhaps an update might be needed.

So, all is well, just one more thing, what would I
do if I want to disable that. It was something I
pondered given that the mouse wheel doesn't need
focus. I guess no good deed goes unpunished :)

But this is great news. And thanks so much for
the info.

And lastly, do you think it should still have
an invoke method? I could still submit a TIP
if others think it would be a good suggestion.

Harald Oehlmann

unread,
May 27, 2020, 2:35:19 AM5/27/20
to
If the binding is missing on spinbox (not ttk::spinbox), this is IMHO a
bug. You may provide a ticket and a patch.

Switching may be done like (untested sketch)
bind $w <ScrollWheel> break

I have no opinion on the invoke method, but most ttk widgets have a
smaller interface compared to the corresponding non-ttk widgets.

Harald

Harald Oehlmann

unread,
May 27, 2020, 2:39:39 AM5/27/20
to
Am 26.05.2020 um 21:58 schrieb nemethi:
> The ttk::spinbox widget *does have built-in* MouseWheel bindings,
> implemented in the Tk library file ttk/spinbox.tcl.  These bindings invoke
>
>   event generate $w <<Increment>>
>
> and
>
>   event generate $w <<Decrement>>
>
> which are the ttk::spinbox counterparts of "invoke buttonup" and "invoke
> buttondown".
>

Thank you!
Information now on:

https://wiki.tcl-lang.org/page/ttk%3A%3Aspinbox?V=23

Manual page may be enhanced but that is another project.
A ticket may be issued to guide that.

Thank you,
Harald

tedbr...@gmail.com

unread,
May 27, 2020, 1:09:59 PM5/27/20
to
On Tuesday, May 26, 2020 at 11:35:19 PM UTC-7, Harald Oehlmann wrote:

>
> Switching may be done like (untested sketch)
> bind $w <ScrollWheel> break
>

On my windows system, it appears to be <MouseWheel> that can disable it.

I think I will submit a ticket for the manual page but I'm not sure what category to use for the ticket besides "other" or [spinbox] and type of "support" seems closest. Or is there a better way to report on the manual?

I think something like this would be useful (if I got this right)


xxxxxxxx

Default Bindings

Being an extended ttk::entry widget, ttk::spinbox includes all the default bindings mentioned in ttk::entry, plus the following:

1. Mouse wheel rotates are the same as pressing <Up> and <Down>. In addition, a mouse with a tilt wheel found on some hardware acts like a shift rotate.

If this is not desired, the following can be used for a ttk::spinbox named .spin to disable this behavior:

bind .spin <MouseWheel> break

The following will leave the mouse wheel rotate active but disable the tilt-wheel or the wheel with the shift key down.

bind .spin <Shift-MouseWheel> break

2... (if there's any others that differ from ttk::entry)

xxxxx

This might also be a good place to mention the <MouseWheel>'s unique focus talent and perhaps mention tip 171. I didn't see it discussed in [focus] and I'm not sure where else it might be in the manual.

Harald Oehlmann

unread,
May 28, 2020, 2:42:18 AM5/28/20
to
Ted,
thank you for the ticket !

Am 27.05.2020 um 19:09 schrieb tedbr...@gmail.com:
> On Tuesday, May 26, 2020 at 11:35:19 PM UTC-7, Harald Oehlmann wrote:
>
>>
>> Switching may be done like (untested sketch)
>> bind $w <ScrollWheel> break
>>
>
> On my windows system, it appears to be <MouseWheel> that can disable it.
>
> I think I will submit a ticket for the manual page but I'm not sure what category to use for the ticket besides "other" or [spinbox] and type of "support" seems closest. Or is there a better way to report on the manual?

I have not observed that the category has any consequences. I would
choose "spinbox" or "ttk widgets".

> I think something like this would be useful (if I got this right)
>
>
> xxxxxxxx
>
> Default Bindings
>
> Being an extended ttk::entry widget, ttk::spinbox includes all the default bindings mentioned in ttk::entry, plus the following:
>
> 1. Mouse wheel rotates are the same as pressing <Up> and <Down>. In addition, a mouse with a tilt wheel found on some hardware acts like a shift rotate.
>
> If this is not desired, the following can be used for a ttk::spinbox named .spin to disable this behavior:
>
> bind .spin <MouseWheel> break
>
> The following will leave the mouse wheel rotate active but disable the tilt-wheel or the wheel with the shift key down.
>
> bind .spin <Shift-MouseWheel> break
>
> 2... (if there's any others that differ from ttk::entry)
>
> xxxxx
>
> This might also be a good place to mention the <MouseWheel>'s unique focus talent and perhaps mention tip 171. I didn't see it discussed in [focus] and I'm not sure where else it might be in the manual.
>

See my ticket here:
https://core.tcl-lang.org/tk/info/cd051b586ac481ed

I usually do the following:

- first document on the wiki
- then issue a ticket
- and eventually implenent it if there are positive signs.

Thank you,
Harald

nemethi

unread,
May 28, 2020, 3:40:46 PM5/28/20
to
Am 27.05.20 um 19:09 schrieb tedbr...@gmail.com:
> On Tuesday, May 26, 2020 at 11:35:19 PM UTC-7, Harald Oehlmann wrote:
>
>>
>> Switching may be done like (untested sketch)
>> bind $w <ScrollWheel> break
>>
>
> On my windows system, it appears to be <MouseWheel> that can disable it.
>
> I think I will submit a ticket for the manual page but I'm not sure what category to use for the ticket besides "other" or [spinbox] and type of "support" seems closest. Or is there a better way to report on the manual?
>
> I think something like this would be useful (if I got this right)
>
>
> xxxxxxxx
>
> Default Bindings
>
> Being an extended ttk::entry widget, ttk::spinbox includes all the default bindings mentioned in ttk::entry, plus the following:
>
> 1. Mouse wheel rotates are the same as pressing <Up> and <Down>. In addition, a mouse with a tilt wheel found on some hardware acts like a shift rotate.

What do you mean by "a mouse with a tilt wheel found on some hardware"?

Nowadays the scroll wheel of most mice is tiltable. However, tilting
the wheel left or right will only trigger a <Shift-MouseWheel> event on
Windows and Mac OS X Aqua or a <Shift-Button-4|5> event on X11 if the
mouse has 4 or 5 buttons (including the scroll wheel). Since the
TSpinbox class has no bindings for <Shift-MouseWheel> or
<Shift-Button-4|5>, these events will be handled just like the
corresponding ones w/o Shift, i.e., they have the same effect as
pressing <Up> and <Down>.

>
> If this is not desired, the following can be used for a ttk::spinbox named .spin to disable this behavior:
>
> bind .spin <MouseWheel> break
>
> The following will leave the mouse wheel rotate active but disable the tilt-wheel or the wheel with the shift key down.
>
> bind .spin <Shift-MouseWheel> break
>
> 2... (if there's any others that differ from ttk::entry)
>
> xxxxx
>
> This might also be a good place to mention the <MouseWheel>'s unique focus talent and perhaps mention tip 171. I didn't see it discussed in [focus] and I'm not sure where else it might be in the manual.
>

IMHO, TIPs should not be mentioned in manual pages. In addition, notice
that TIP 171 proposed to change the default <MouseWheel> bindings in
such a way that they scroll what the mouse is over, not what has the
focus. Instead of implementing this TIP, the Tk developers changed the
C code in such a way that on Windows, too, the mouse wheel events are no
longer reported to the widget having the focus, but to the one under the
pointer. That is, not the *handling* of the <MouseWheel> events was
changed, but the *reporting* of these events. This made TIP 171
obsolete, and IMHO, it was a good decision.

tedbr...@gmail.com

unread,
May 28, 2020, 10:29:03 PM5/28/20
to
On Thursday, May 28, 2020 at 12:40:46 PM UTC-7, nemethi wrote:

> Nowadays the scroll wheel of most mice is tiltable.

I have several 5 button tilt mice by Gearhead.
After they stopped selling them, I spent quite
some time searching for a replacement on ebay.
Maybe I set the price range too low :)

I was not expecting that the tilt-wheel would be
different depending on the existence of buttons
4-5. So, I will defer to you on this.

I have created a ticket, for the manual on
ttk::spinbox here,

https://core.tcl-lang.org/tk/tktview?name=2e07480f5f

Please feel free to add to it. You clearly understand
this better than I.

And thanks for letting me know that the feature was
there. I was going to try to write something to handle
the -value case, but that's not needed now.



> IMHO, TIPs should not be mentioned in manual pages.

I now agree, that was not a good suggestion to
mention it in the manual. Much better to explain it
in [bind] with Harald's ticket.

Harald Oehlmann

unread,
May 29, 2020, 2:10:06 AM5/29/20
to
Am 28.05.2020 um 21:40 schrieb nemethi:
> IMHO, TIPs should not be mentioned in manual pages.  In addition, notice
> that TIP 171 proposed to change the default <MouseWheel> bindings in
> such a way that they scroll what the mouse is over, not what has the
> focus.  Instead of implementing this TIP, the Tk developers changed the
> C code in such a way that on Windows, too, the mouse wheel events are no
> longer reported to the widget having the focus, but to the one under the
> pointer.  That is, not the *handling* of the <MouseWheel> events was
> changed, but the *reporting* of these events.  This made TIP 171
> obsolete, and IMHO, it was a good decision.
>

Thank you, Csaba. mousewheel wiki is updated.
Thanks,
Harald

Harald Oehlmann

unread,
May 29, 2020, 2:13:35 AM5/29/20
to
For the records, there is a marking prevued within the manpage format,
which indicates, which sections are new and it is common to cite a tip
number within the marking.
Nevertheless, this marking is not shown on html output of the man pages.

You may download the tcl file docs/msgcat.n and you will see that within
the source of the manpage.

Harald

tedbr...@gmail.com

unread,
May 29, 2020, 6:09:29 AM5/29/20
to
I want to thank everyone who responded to my post.

I would like to now for fun and in the spirit of RS
our great wiki contributor, who I was thrilled
to see post here recently, present a tk puzzle:

Can you determine the algorithm that each of spinbox
and ttk::spinbox use with the -values attribute to
decide which list element to display on clicking an
arrow (or rolling the wheel).

No looking at the tk source code. I give a hint
at the bottom.

Not quite an RS tcl Whizzlet, but something
I just ran across as my subconscious brain refused to
give up on how to simulate the invoke method
of my first post.

During this strange interlude I have been watching
Brian Greene's “your daily equation”. There's been
a lot of discussion about the true interpretation of
quantum mechanics. Is there spooky action at a
distance or as Einstein thought, hidden variables?

This tcl puzzle makes me think that Einstein
would choose the regular spinbox while Bohr would
choose ttk::spinbox.

Hint:

try

-values {one two three 4 5 two six}

I only have a belief - the actual answer is
somewhere deeper than I was able to penetrate.

tedbr...@gmail.com

unread,
May 29, 2020, 6:39:11 PM5/29/20
to
# Answer:

# this works, must be using a variable to track current position
spinbox .spin -values {one two three 4 5 two six}

# the "six" cannot be reached with <Up> and loops, must be using a search
ttk::spinbox .spin2 -values {one two three 4 5 two six}

pack .spin .spin2

# ttk::spinbox can't have duplicates (say as a history widget)

0 new messages