| Deutsch English Français Italiano |
|
<vc37rg$1ajh6$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: greg <gregor.ebbing@gmx.de>
Newsgroups: comp.lang.tcl
Subject: Re: ISO a way to select programmatically an entry from a popup
Date: Sat, 14 Sep 2024 07:44:16 +0200
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <vc37rg$1ajh6$1@dont-email.me>
References: <l4t6ejp2n55d7dpkt497ntummfi1m7ns9h@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 14 Sep 2024 07:44:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d0be020874f76676317894402e841f0e";
logging-data="1396262"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fXVKuaumYr/GJdidHkpzyIuFTc2HNWpI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yCILatVzzEt7sW4UlZHoLvr3Zs8=
In-Reply-To: <l4t6ejp2n55d7dpkt497ntummfi1m7ns9h@4ax.com>
Content-Language: de-DE
Bytes: 3697
Am 13.09.24 um 01:31 schrieb Helmut Giese:
> Hello out there,
> it seems like as long as a popup is posted the app cannot do anything
> - in particular it cannot post any events. Consider this script:
> ---
> package require Tk
> foreach ch [winfo children "."] {destroy $ch}
>
> # Turn $x & $y into absolute coords
> proc mkAbsCoords {c x y} {
> # get the canvas's coord relative to the toplevel
> set xOfs [expr {[winfo rootx $c]}]
> set yOfs [expr {[winfo rooty $c]}]
> return [list [expr {$x + $xOfs}] [expr {$y + $yOfs}]]
> }
>
> proc popupMenu {c x y} {
> catch {destroy .popup}
> set popup [menu .popup -tearoff false]
> set inactiveBG #b2b2b2
> $popup add command -label "Choose an op" \
> -background #b2b2b2 -activebackground #b2b2b2 \
> -activeforeground [$popup cget -fg]
> $popup add command -label "Op 1" -command {puts "Op1 selected"}
> $popup add command -label "Op 2" -command {puts "Op2 selected"}
> lassign [mkAbsCoords $c $x $y] x y
> tk_popup $popup $x $y
> }
>
> set num [lindex $argv 0]
> set c [canvas .c -width 200 -height 200]
> pack $c
> set id [$c create rectangle 50 50 150 150 -fill lightyellow]
> $c bind $id <Button-3> [list popupMenu $c %x %y]
> update
> if {$num} {
> set event Button
> } else {
> set event ButtonPress
> }
> event generate $c <$event> -button 3 -x 100 -y 100 -warp 1
> puts "Back from '$event'"
> if {$num == 0} {
> event generate $c <ButtonRelease> -button 3 -x 100 -y 100 -warp 1
> puts "Back from 'ButtonRelease'"
> }
> ---
> and this output:
> ---
> Microsoft Windows [Version 10.0.19045.4894]
> (c) Microsoft Corporation. Alle Rechte vorbehalten.
>
> d:\proj\_ToolsSE\Skeleton\TclTests>tclsh tst.tcl 1
> Back from 'Button'
> Op1 selected
>
> d:\proj\_ToolsSE\Skeleton\TclTests>tclsh tst.tcl 0
> Back from 'ButtonPress'
> Back from 'ButtonRelease'
> Op1 selected
> ---
> To me this seems to clearly indicate that the selection cannot be
> influenced by the controlling app: control only returns when the
> selection has happened - which is too bad.
>
> Or is there a trick by which one can influence the selection from a
> popup?
> Any idea will be highly appreciated.
> Helmut
> Oh, this is on Windows 64 bit under Tcl 8.6.10
Hello
with event, invoke and unpost
https://www.tcl.tk/man/tcl8.6/TkCmd/menu.htm#M41
event generate $c <$event> -button 3 -x 100 -y 100 -warp 1
#num 1 or 2, 0 is the label
..popup invoke $num
..popup unpost