• tooltip with a tk_popup menu

    From et99@21:1/5 to All on Tue Dec 19 16:10:00 2023
    Is it possible to have a tooltip with a popup menu in a toplevel window?

    Here's the example in the manual which works:

    package require tooltip

    Demonstrate menu tooltip
    . configure -menu [menu .menu]
    .menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
    .menu.test add command -label Tooltip
    tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"


    Here's my code (which doesn't work):

    package require tooltip

    toplevel .mytop
    console show

    set ::testcb 0

    # Create a menu
    label .mytop.label -text "Menu"
    set m [menu .mytop.menu -tearoff 0 ]
    $m add command -label "testcmd" -command "puts hello-testcmd"
    $m add checkbutton -label "testcb" -variable ::testcb -indicatoron 1 -command {puts "$::testcb/checkbutton"}

    pack .mytop.label

    bind .mytop <1> {tk_popup .mytop.menu %X %Y}

    tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0" tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to All on Tue Dec 19 22:58:01 2023
    On Tue, 19 Dec 2023 16:10:00 -0800, et99 wrote:

    Is it possible to have a tooltip with a popup menu in a toplevel window?

    Here's the example in the manual which works:

    package require tooltip

    Demonstrate menu tooltip
    . configure -menu [menu .menu]
    .menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
    .menu.test add command -label Tooltip
    tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"


    Here's my code (which doesn't work):

    package require tooltip

    toplevel .mytop
    console show

    set ::testcb 0

    # Create a menu
    label .mytop.label -text "Menu"
    set m [menu .mytop.menu -tearoff 0 ]
    $m add command -label "testcmd" -command "puts hello-testcmd"
    $m add checkbutton -label "testcb" -variable ::testcb -indicatoron
    1 -command {puts "$::testcb/checkbutton"}

    pack .mytop.label

    bind .mytop <1> {tk_popup .mytop.menu %X %Y}

    tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0" >tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"

    **************************

    I tried it in many ways and I could only make the tooltip appear by
    removing the -index options, but then it appears whenever the menu is
    clicked, with no specific tooltips for each menu item like you very
    probably meant.

    I poked it a lot and it seems to me that tooltip is broken, or maybe
    the manual is wrong.


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Luc on Tue Dec 19 23:22:51 2023
    On 12/19/2023 5:58 PM, Luc wrote:
    On Tue, 19 Dec 2023 16:10:00 -0800, et99 wrote:

    Is it possible to have a tooltip with a popup menu in a toplevel window?

    Here's the example in the manual which works:

    package require tooltip

    Demonstrate menu tooltip
    . configure -menu [menu .menu]
    .menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
    .menu.test add command -label Tooltip
    tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"


    Here's my code (which doesn't work):

    package require tooltip

    toplevel .mytop
    console show

    set ::testcb 0

    # Create a menu
    label .mytop.label -text "Menu"
    set m [menu .mytop.menu -tearoff 0 ]
    $m add command -label "testcmd" -command "puts hello-testcmd"
    $m add checkbutton -label "testcb" -variable ::testcb -indicatoron >> 1 -command {puts "$::testcb/checkbutton"}

    pack .mytop.label

    bind .mytop <1> {tk_popup .mytop.menu %X %Y}

    tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0"
    tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"

    **************************

    I tried it in many ways and I could only make the tooltip appear by
    removing the -index options, but then it appears whenever the menu is clicked, with no specific tooltips for each menu item like you very
    probably meant.

    I poked it a lot and it seems to me that tooltip is broken, or maybe
    the manual is wrong.




    Thanks for looking into this. Yes, I want each menu item to have its own tooltip (or none).

    Well, I have the tooltip code and first thing is,

    for the code that works, there's a mirror copy of the .menu and .menu.test as:

    w= |.#menu|
    w= |.#menu.#menu#test|

    And there's this:

    # Menu events come from a funny path, map to the real path.
    set m [string map {"#" "."} [winfo name $w]]
    set cur [$w index active]

    Although

    % string map {"#" "."} .#menu.#menu#test
    ..menu..menu.test

    So does Tk allow for multiple .. in a path, like with :::: in namespaces?


    But my menu's don't have those built by tooltip. So, from there, when it enters the code menuMotion, it doesn't seem to be what that code wants to see.

    When moving the mouse into the menu's his has the above values for w, while mine are just

    w= |.mytop.menu|

    This is from adding some code at the top of

    proc ::tooltip::menuMotion {w} {
    variable G
    puts "w= |$w| "



    I added 2 more menu items in the working code (the first tearoff doesn't work):

    . configure -menu [menu .menu -tearoff 1]
    .menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
    .menu.test add command -label Tooltip1
    .menu.test add command -label Tooltip2
    .menu.test add command -label Tooltip3
    tooltip::tooltip .menu.test -index 0 "This is a menu tooltip0"
    tooltip::tooltip .menu.test -index 1 "This is a menu tooltip1"
    tooltip::tooltip .menu.test -index 2 "This is a menu tooltip2"

    Here's what's he's storing, for his and mine

    ::::tooltip::tooltip(.menu.test,0) = This is a menu tooltip0 ::::tooltip::tooltip(.menu.test,1) = This is a menu tooltip1 ::::tooltip::tooltip(.menu.test,2) = This is a menu tooltip2 ::::tooltip::tooltip(.mytop.menu,0) = this is a tooltip 0 ::::tooltip::tooltip(.mytop.menu,testcb) = this is a tooltip 1

    I'm thinking that you can't do this with another toplevel besides . or it's the configure -menu that's the problem, as I'm not using the menu bar.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to greg on Wed Dec 20 16:57:30 2023
    On 12/20/2023 12:30 PM, greg wrote:
    greg schrieb am Mittwoch, 20. Dezember 2023 um 21:18:01 UTC+1:
    et99 schrieb am Mittwoch, 20. Dezember 2023 um 08:22:57 UTC+1:
    On 12/19/2023 5:58 PM, Luc wrote:
    On Tue, 19 Dec 2023 16:10:00 -0800, et99 wrote:

    Is it possible to have a tooltip with a popup menu in a toplevel window? >>>>>
    Here's the example in the manual which works:

    package require tooltip

    Demonstrate menu tooltip
    . configure -menu [menu .menu]
    .menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
    .menu.test add command -label Tooltip
    tooltip::tooltip .menu.test -index 0 "This is a menu tooltip"


    Here's my code (which doesn't work):

    package require tooltip

    toplevel .mytop
    console show

    set ::testcb 0

    # Create a menu
    label .mytop.label -text "Menu"
    set m [menu .mytop.menu -tearoff 0 ]
    $m add command -label "testcmd" -command "puts hello-testcmd"
    $m add checkbutton -label "testcb" -variable ::testcb -indicatoron
    1 -command {puts "$::testcb/checkbutton"}

    pack .mytop.label

    bind .mytop <1> {tk_popup .mytop.menu %X %Y}

    tooltip::tooltip .mytop.menu -index 0 "this is a tooltip 0"
    tooltip::tooltip .mytop.menu -index "testcb" "this is a tooltip 1"

    **************************

    I tried it in many ways and I could only make the tooltip appear by
    removing the -index options, but then it appears whenever the menu is
    clicked, with no specific tooltips for each menu item like you very
    probably meant.

    I poked it a lot and it seems to me that tooltip is broken, or maybe
    the manual is wrong.


    Thanks for looking into this. Yes, I want each menu item to have its own tooltip (or none).

    Well, I have the tooltip code and first thing is,

    for the code that works, there's a mirror copy of the .menu and .menu.test as:

    w= |.#menu|
    w= |.#menu.#menu#test|

    And there's this:

    # Menu events come from a funny path, map to the real path.
    set m [string map {"#" "."} [winfo name $w]]
    set cur [$w index active]

    Although

    % string map {"#" "."} .#menu.#menu#test
    ..menu..menu.test

    So does Tk allow for multiple .. in a path, like with :::: in namespaces? >>>

    But my menu's don't have those built by tooltip. So, from there, when it enters the code menuMotion, it doesn't seem to be what that code wants to see.

    When moving the mouse into the menu's his has the above values for w, while mine are just

    w= |.mytop.menu|

    This is from adding some code at the top of

    proc ::tooltip::menuMotion {w} {
    variable G
    puts "w= |$w| "



    I added 2 more menu items in the working code (the first tearoff doesn't work):

    . configure -menu [menu .menu -tearoff 1]
    .menu add cascade -label Test -menu [menu .menu.test -tearoff 0]
    .menu.test add command -label Tooltip1
    .menu.test add command -label Tooltip2
    .menu.test add command -label Tooltip3
    tooltip::tooltip .menu.test -index 0 "This is a menu tooltip0"
    tooltip::tooltip .menu.test -index 1 "This is a menu tooltip1"
    tooltip::tooltip .menu.test -index 2 "This is a menu tooltip2"

    Here's what's he's storing, for his and mine

    ::::tooltip::tooltip(.menu.test,0) = This is a menu tooltip0
    ::::tooltip::tooltip(.menu.test,1) = This is a menu tooltip1
    ::::tooltip::tooltip(.menu.test,2) = This is a menu tooltip2
    ::::tooltip::tooltip(.mytop.menu,0) = this is a tooltip 0
    ::::tooltip::tooltip(.mytop.menu,testcb) = this is a tooltip 1

    I'm thinking that you can't do this with another toplevel besides . or it's the configure -menu that's the problem, as I'm not using the menu bar.
    Hello,
    with baltip
    https://github.com/aplsimple/baltip
    https://wiki.tcl-lang.org/page/baltip%2C+balloon+tip

    #package require tooltip
    package require baltip
    toplevel .mytop
    console show

    set ::testcb 0

    # Create a menu
    label .mytop.label -text "Menu"
    set m [menu .mytop.menu -tearoff 0 ]
    $m add command -label "testcmd" -command "puts hello-testcmd"
    $m add checkbutton -label "testcb" -variable ::testcb -indicatoron 1 -command {puts "$::testcb/checkbutton"}

    pack .mytop.label

    bind .mytop <1> {tk_popup .mytop.menu %X %Y}
    ::baltip::tip $m "this is tooltip 0" -index 0
    ::baltip::tip $m "this is tooltip 1" -index 1

    a small change that is not necessary:
    menu post instead of tk_popup

    ########
    package require Tk
    #package require tooltip
    package require baltip
    toplevel .mytop
    #console show

    set ::testcb 0

    # Create a menu
    label .mytop.label -text "Menu"
    set m [menu .mytop.menu -tearoff 0 ]
    $m add command -label "testcmd" -command "puts hello-testcmd"
    $m add checkbutton -label "testcb" -variable ::testcb -indicatoron 1 -command {puts "$::testcb/checkbutton"}

    pack .mytop.label

    #menu post instead of tk_popup
    #bind .mytop <1> {tk_popup .mytop.menu %X %Y}
    bind .mytop <1> {.mytop.menu post %X %Y}

    ::baltip::tip $m "this is tooltip 0" -index 0
    ::baltip::tip $m "this is tooltip 1" -index 1


    Wow, interesting package. If I had read your post earlier, I would have been quite tempted to use this.

    However, I was successful at finding the problem in the existing tooltip package. Also, when I used the latest baltip version off github (1.6.0) it displays the tips underneath the menu items - although when using magicsplat's distro, with baltip 1.3.7
    it doesn't do that. I tried several 8.6's and even 9.0b1 and the problem follows baltip 1.6.0.

    Funny though, baltip also has the same problem that my fix has which is the tip doesn't go away when you move off the menu item (unless you move to another item that also has or hasn't a tip). I was debating whether to track that down in tooltip or not.
    Probably not.

    And I also see that it creates menus with # in the name. This is something which I wasn't able to find the code that actually does that. However, these are only for menubar menus and I'm beginning to wonder if it's in Tk that it's actually done.

    ---------------------

    Anyway, my fix to tooltip for anyone who might be curious, is that when they didn't find the menu item they were looking for in the tooltip array after the mapping of # for dots, I just use the one that was saved in the tooltip array, in menuMotion:

    proc ::tooltip::menuMotion {w} {
    variable G
    <snip>
    set m [string map {"#" "."} [winfo name $w]] ;# here's that # magic mapping
    <snip>

    catch {wm withdraw $G(TOPLEVEL)}

    if { ! [info exists tooltip($m,$cur)]} { ;# fix here when not finding this
    if { [info exists tooltip($w,$cur)] } {
    set m $w ;# just use the one before the # mapping
    }

    }


    I do like how baltip allows for much more customization of the tips. Many programs I use are almost entirely documented using tooltips, and many allow for multiple fonts and styles, bold etc. in the tips.

    I did notice, though, that one can use Unicode in the tips. I've been spicing mine up a bit using some pointing hands etc like \u261B.

    I was going to play a bit more with the tooltip package after investing so much in figuring it out. They use a single label widget for all the tips and keep reusing it. I haven't yet found where they set the -text attribute, but I can see it keeps
    changing. I was gonna try making it a text widget instead and then do some of my own rendering for simple stuff like bold, underlined, and italic.

    One advantage I have with tooltip is it's very small and I actually embed it into one of my own packages so its self-contained and works with all my smaller tclkits.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)