Discussion:
scrolling ::ttk::treeview from keyboard
(too old to reply)
eugene
2011-04-04 21:15:59 UTC
Permalink
Hi everyone,
I'm trying to use ::ttk::treeview (Windows XP, ActiveTcl 8.5.9.1) and
I see the following behavior when scrolling the contents of this
control with PgUp/PgDn keys: current selection doesn't follow the
view, it stays unchanged and so can be easily lost out of sight. In
other words, if I select some item and scroll away pressing PgDn, and
then use Up/Down arrow keys, current view suddenly jumps back to show
the selected item and change the selection to previous/next item. I
find this inconsistent with the typical expected list control behavior
under Windows - i.e. the selection always stays inside the current
view. So, is there any way to make ::ttk::treeview move the selection
just like SysListView32 does?
Gerald W. Lester
2011-04-04 21:22:57 UTC
Permalink
Post by eugene
Hi everyone,
I'm trying to use ::ttk::treeview (Windows XP, ActiveTcl 8.5.9.1) and
I see the following behavior when scrolling the contents of this
control with PgUp/PgDn keys: current selection doesn't follow the
view, it stays unchanged and so can be easily lost out of sight. In
other words, if I select some item and scroll away pressing PgDn, and
then use Up/Down arrow keys, current view suddenly jumps back to show
the selected item and change the selection to previous/next item. I
find this inconsistent with the typical expected list control behavior
under Windows - i.e. the selection always stays inside the current
view. So, is there any way to make ::ttk::treeview move the selection
just like SysListView32 does?
The behavior you want is rather counter-intuitive.

That being said, the answer is sure -- all the binding are in Tcl. Just
make the page up/down do what you want (you can change the selection).
--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: ***@kng-consulting.net |
+------------------------------------------------------------------------+
eugene
2011-04-05 08:02:25 UTC
Permalink
Post by Gerald W. Lester
The behavior you want is rather counter-intuitive.
It might well be counter-intuitive, but unfortunately this is the way all standard listboxes (based on SysListView32) work in Windows, so it's perfectly normal a user would expect this behavior from ::ttk::treeview.
Post by Gerald W. Lester
That being said, the answer is sure -- all the binding are in Tcl. Just
make the page up/down do what you want (you can change the selection).
Yes, I know about bindings, and, for example, I can easily add appropriate actions for Home/End keys (which are unbound by default so pressing them does nothing) like this:

bind .tree <Home> {
set item [ lindex [ %W children {} ] 0 ]
%W see $item
%W focus $item
%W selection set $item
}

However, to add appropriate bindings for PgDn it takes the following approach:

bind $t <Next> {
# Find the last visible item and select it.
set item [ %W identify item 1 [ winfo height %W ] ]
%W see $item
%W focus $item
%W selection set $item
}

And even that is not working as I'd expect - after PdDn it selects first visible item, not the last one. So my question was - is there any easy way to make ::ttk::treeview response to PgUp/PgDn the same way SysListView32 does without too much hassle like writing some obscure binding code and then trying for hours to make it work correctly?
nedbrek
2011-04-05 11:53:36 UTC
Permalink
Post by eugene
Post by Gerald W. Lester
The behavior you want is rather counter-intuitive.
It might well be counter-intuitive, but unfortunately this is the way all
standard listboxes (based on SysListView32) work in Windows, so it's
perfectly
normal a user would expect this behavior from ::ttk::treeview.
The treeview in Outlook Express (not sure how it's implemented) works like
the one in Tcl, but anyway...
Post by eugene
bind $t <Next> {
# Find the last visible item and select it.
set item [ %W identify item 1 [ winfo height %W ] ]
%W see $item
%W focus $item
%W selection set $item
}
And even that is not working as I'd expect - after PdDn it selects first
visible item, not the last one. So my question was - is there any easy way
to
make ::ttk::treeview response to PgUp/PgDn the same way SysListView32 does
without too much hassle like writing some obscure binding code and then
trying
for hours to make it work correctly?
I don't know any surefire way (you can't be certain what the underlying
implementation will be, on say Linux or MacOS). If you get stuck, usually
someone in the group can help out...

bind $t <Next> {
set yv [lindex [%W yview] 1]
%W yview moveto $yv

set i [%W identify row 1 [winfo height %W]]
set item [%W prev $i]
%W focus $item
%W selection set $item
}

You had a good start. I used yview instead of "see". I noticed it was
selecting one past the end (first item on the next page), so I put the
"prev" in there.

Hope that helps!
Ned
eugene
2011-04-05 12:38:34 UTC
Permalink
Post by nedbrek
The treeview in Outlook Express (not sure how it's implemented) works like
the one in Tcl, but anyway...
That's mighty strange, because on my system (WinXP SP3) both in Outlook Express and Windows Live Mail treeviews/listboxes act exactly the same way I described in my original post - selection moves with the view, last visible item is selected (may be it's affected by some OS setting, I'm not sure).
Post by nedbrek
I don't know any surefire way (you can't be certain what the underlying
implementation will be, on say Linux or MacOS). If you get stuck, usually
someone in the group can help out...
bind $t <Next> {
set yv [lindex [%W yview] 1]
%W yview moveto $yv
set i [%W identify row 1 [winfo height %W]]
set item [%W prev $i]
%W focus $item
%W selection set $item
}
You had a good start. I used yview instead of "see". I noticed it was
selecting one past the end (first item on the next page), so I put the
"prev" in there.
Hope that helps!
Yes, it worked like a charm, thanx Ned! I didn't see I could've put yview to such a good use :)
Loading...