ISO tooltips for ttk::treeview

62 views
Skip to first unread message

Helmut Giese

unread,
Jul 18, 2021, 4:04:36 PMJul 18
to
Hello out there,
I want to add tooltips to a ttk::treeview. I found code by Keith
Vetter on the wiki, which creates virtual events for entering and
leaving a row. To actually add tooltips 'is left as an exersize for
the reader' :(

The tooltip package in tklib doesn't work because it is intended for
menus, canvases or listboxes or text widgets as the widget underlying
the treeview. Apparently ttk:treeview isn't based on any of these.

If anyone knows of a tooltip package usable for ttk::treeview this
info would be greatly appreciated.
Helmut

PS: Hm, I just got the idea maybe I should just implement it myself:
Create a label and place it the (known) position. However, this
shoudn't stop you from posting all the links that you know of (:
Message has been deleted

Christian Gollwitzer

unread,
Jul 19, 2021, 12:45:23 AMJul 19
to
Am 18.07.21 um 22:04 schrieb Helmut Giese:
> Hello out there,
> I want to add tooltips to a ttk::treeview. I found code by Keith
> Vetter on the wiki, which creates virtual events for entering and
> leaving a row. To actually add tooltips 'is left as an exersize for
> the reader' :(
>
> The tooltip package in tklib doesn't work because it is intended for
> menus, canvases or listboxes or text widgets as the widget underlying
> the treeview. Apparently ttk:treeview isn't based on any of these.

ttk::treeview is its own type of widget. IMHO it is a very barebones one.

My suggestion would be to use tablelist instead of ttk::treeview, first
it is based on the text widget, so maybe you could use the tooltip
package, and second, there are already some hooks in it
https://www.nemethi.de/tablelist/tablelistWidget.html#tooltipaddcommand


I've not used this concrete functionality of tablelist, but otherwise I
can highly recommend it.

Christian

Alex Plotnikov

unread,
Jul 19, 2021, 12:48:09 AMJul 19
to
воскресенье, 18 июля 2021 г. в 23:04:36 UTC+3, Helmut Giese:
> If anyone knows of a tooltip package usable for ttk::treeview this
> info would be greatly appreciated.

Can this package fit:
https://github.com/aplsimple/baltip
?

It's used in
https://github.com/aplsimple/alited
where the left "unit tree" and bottom "favorites" are both ttk::treeview widgets.

Alex Plotnikov

unread,
Jul 19, 2021, 11:07:55 AMJul 19
to
Probably, Keith meant the following: you should bind a tooltip to some events on ttk::treeview.

These events are:
<Motion> - to show a tip
<Leave> - to hide a tip (optionally)

The <Motion> handler can (and should anyway) take %W %x %y %X %Y arguments to calculate a current treeview item and show a tip under the mouse pointer.

You can bind this way (supposedly, *wtree* is the ttk::treeview's path):

# you create a tag to bind the tree items
$wtree tag configure tagTip -font TkDefaultFont ;# any font you like, e.g. a small one

# when creating a tree, you add the tag to each created treeview item
# which needs a tip:
...
$wtree tag add tagTip $treeID
...

Then you bind the <Motion> event and its handler for this tag:

$wtree tag bind tagTip <Motion> {after idle {::NS::TreeViewMotion %W %x %y %X %Y}}
...

The handler calculates the tree item's ID from %x and %y and shows the tip at %X and %Y coordinates, something like this:

proc ::NS::TreeViewMotion {w x y X Y} {
set ID [$w identify item $x $y] ;# to get ID of current tree item
set rg [$w identify region $x $y] ;# region of <Motion>
if {[$w exists $ID] && $::NS::tipID ne $ID && $rg in {tree cell}} {
# get a tip from ID ---- this depends on the treeview's content
set tip [SomeProc $ID]
# show a tip ---- this can be substituted with the tooltip proc made by Keith
::baltip tip $w $tip -geometry +$X+$Y
}
# ::NS::tipID is a saved ID, defined so: namespace ::NS {variable tipID {}}
# just to avoid repainting a tip at mouse moving
set ::NS::tipID $ID
}

An advice to use *tablelist* instead is very good, esp. when you need a widget more complex than ttk::treeview that is nonetheless useful in many cases as well.

Helmut Giese

unread,
Jul 22, 2021, 10:33:04 AMJul 22
to
Hi Christian,

>My suggestion would be to use tablelist instead of ttk::treeview, first
>it is based on the text widget, so maybe you could use the tooltip
>package, and second, there are already some hooks in it
>https://www.nemethi.de/tablelist/tablelistWidget.html#tooltipaddcommand
>
sorry for the delay - I was busy fighting with tablelist.
You don't know it, but it was precisely your suggestion to use
tablelist (a suggestion you made some 6 years ago here on clt) that
made me try my hands on tablelist - before turning to treeview.

I am in the mood of writing - so read on if you like.
This is my situation: I want to use a treeview of what ever brand to
display infos about the internals of a microprocessor: its
perpiherals, registers, etc.
But to be really useful tooltips are essential: While a tooltip cannot
possibly explain the complete function of a register or one of its
bitfields it might give someone enough of a hint to remember something
- without having to turn to the data sheets for every littlte detail
to look it up.
With this in mind I looked for 'treeview tooltip' and found
- on the wiki the posting by Keith Vetter mentioned earlier from which
I learned that I might have to implement tooltips myself, and
- via Google your recommendation mentioned above.

Since I have got the impression over the years that you are a very
knowledgable person (wrt Tcl), I considered this to be sound advice
(especially your mentioning of the 'tooltipaddcommand' was probably
decisive) and so I decided to turn to tablelist. Oh, had I only known
... :)

To acknowledge it up front: tablelist is a great widget with an
outstanding documentation. But for a first time user like me its
features are overwhelming. Add to this my missing knowledge of the
terminology used - to give you an example: I thought of 'opening' and
'closing' a node (like you open or close a file), but the terms used
by tablelist are 'expand' and 'collapse' - which are arguably the
better choice, but still: all this eats time.

But over time I made progress: I integrated my tooltips where I found
the '-formatcommand ' option especially useful: It allows you to put
several things for a cell together and when it is to be displayed the
command you passed to this option can take what it needs (e.g. via
[lindex ... 0]) and the tooltip can show its tip via [lindex ... 1] -
very nice.

During development I had been using the data of just one peripheral,
but when it came to use it on a whole processor I was in for a bad
surprise: You see, the processor I want to work (or rather 'hobby')
with is a really complex beast - probably the most complex I have ever
seen: its reference manual is a some 3400 pages long.
Well, to make it short: When tablelist had to work with the info of
the complete chip it became unbearingly slow - just an attempt to
resize it took ages. Sadly, not usable.

Therefore it was time to try out treeview which eventually lead me
here with my tooltip question. As it turned out tooltips aren't all
that difficult - but somehow the tablelist version looked much nicer.

It nagged me: Saving tablelist's content into a file was not a
problem, but when you re-loaded it all the "tree information" was
lost. But then I had an idea: How about 'on demand' expanding?
- load the saved data, but don't feed it into the tree yet,
- only insert (and by this: display) the top level nodes
- and on expanding any node insert its children into the tree.
- On collapsing reverse the operation.

This is what kept me busy the last few days. I think I am almost there
- but not quite yet. I will keep y'all informed. :)
Thanks for reading this far.
Helmut

Helmut Giese

unread,
Jul 22, 2021, 10:33:15 AMJul 22
to
Hi Alex,
many thanks for your tips - they were very helpful. And sorry for the
delay - if you want to know the whole story: read my (rather longish)
answer to Christian.
Thanks again and best regards
Helmut
Reply all
Reply to author
Forward
0 new messages