Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 733dcbcd56ab77dca4332bb1de4362f007cedf9ddf08a89a71cff2e4663ef81e
Ticket: 91b3a5bb14e6e8ae1d1c5349af12e08879ea152d
msgcat with oo: error "self may only be called from inside a method"
User & Date: oehhar on 2024-07-14 13:42:41
Changes

  1. comment changed to:
    MSGCat may issue an error with the following stack trace:
    <verbatim>
    self may only be called from inside a method
        while executing
    "self "
        ("uplevel" body line 1)
        invoked from within
    "uplevel 2 { self }"
        (procedure "PackageNamespaceGet" line 17)
        invoked from within
    "PackageNamespaceGet"
        (procedure "::msgcat::mc" line 2)
        invoked from within
    "::msgcat::mc {One fails on tooltip}"
        (in namespace eval "::oo::Obj135" script line 1)
        invoked from within
    "namespace eval $nscaller [list ::msgcat::mc $text {*}$msgargs]"
        (procedure "show" line 22)
        invoked from within
    "show .toolbar.one {{One fails on tooltip} {} {} ::oo::Obj135 {} {}} cursor"
        (in namespace inscope "::tooltip" script line 1)
        invoked from within
    "::namespace inscope ::tooltip {show .toolbar.one {{One fails on tooltip} {} {} ::oo::Obj135 {} {}} cursor}"
        ("after" script)</verbatim>
    
    Mark described on clt how to show this:
    
    In the script below, clicking button two works fine, but even hovering 
    over button One produces an error (shown at the end).
    
    The difference is that button one's tooltip is created in a method and 
    button two's tooltip is created in a function. If you comment out button 
    one's tooltip, the button works fine just like button two. I'm using Tcl/
    Tk 9.0b2 on Linux.
    
    <verbatim>
    #!/usr/bin/env wish9
    
    package require tooltip
    package require widget::toolbar
    
    if {[info exists env(TK_SCALING)]} {tk scaling $env(TK_SCALING)}
    
    proc main {} {
        tk appname "Tooltip Bug?"
        set application [App new]
        $application show
    }
    
    namespace eval toolbar {}
    
    proc toolbar::add_two app {
        .toolbar add [ttk::button .toolbar.two -text Two \
            -command [list $app on_two]]
        ::tooltip::tooltip .toolbar.two "Two works fine"
    }
    
    oo::class create App {}
    oo::define App {
        constructor {} {
            wm withdraw .
            wm title . [tk appname]
            widget::toolbar .toolbar
            my add_one
            toolbar::add_two [self]
            pack .toolbar
            bind . <Escape> {destroy .}
        }
        method add_one {} {
            .toolbar add [ttk::button .toolbar.one  -text One \
                -command [callback on_one]]
            ::tooltip::tooltip .toolbar.one "One fails on tooltip" ;# BUG
        }
        method on_one {} { puts "on_one" }
        method on_two {} { puts "on_two" }
        method show {} { wm deiconify . ; raise . }
    }
    
    main
    </verbatim>
    
    Note that if you comment out the ";# BUG" line, button one works fine.
    
    -----
    
    Any idea welcome.
    
    This ticket may be of relevance: [e02798626dfbcd7b33db]
    
    The eventually relevant Tklib ticket is [https://core.tcl-lang.org/tklib/info/3300362].
    
    As this may be within TkLib, the ticket is duplicated here: [https://core.tcl-lang.org/tklib/tktview/6e85abae9e49281b3b1212e25082f73239f7ea9e].
    
    Thank you,
    Harald
    
  2. login: "oehhar"
  3. mimetype: "text/plain"