Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #76: Unoptimized hard drive


comp / comp.lang.tcl / Generate <Shift-Button> event on a canvas (on Windows)

SubjectAuthor
* Generate <Shift-Button> event on a canvas (on Windows)Helmut Giese
+- Re: Generate <Shift-Button> event on a canvas (on Windows)Helmut Giese
`* Re: Generate <Shift-Button> event on a canvas (on Windows)Helmut Giese
 `* Re: Generate <Shift-Button> event on a canvas (on Windows)Schelte
  `- Re: Generate <Shift-Button> event on a canvas (on Windows)Helmut Giese

1
Subject: Generate <Shift-Button> event on a canvas (on Windows)
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Mon, 5 Aug 2024 15:27 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Generate <Shift-Button> event on a canvas (on Windows)
Date: Mon, 05 Aug 2024 17:27:31 +0200
Organization: ratiosoft
Lines: 13
Message-ID: <qfq1bj95rbgdrlnth8qp03c22cbqrhkn4h@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 05 Aug 2024 17:27:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7a7a087ddb149b4ff3b77ebfffc2ff2a";
logging-data="876400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7NYi3Ti3d8tvKRRUPc/gt"
Cancel-Lock: sha1:BaEKKaUAF2KdZF9u/3ww1qTVOWc=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello out there,
I am writing tests (using tcltest) to avoid any regression during
development but I hit something like a brick wall: 'event generate'
appears not to work on items of a canvas. On regular widgets no
problem: It can produce events like <Button-1>, <Shift-Button-1> ,
etc.
With twapi on the other hand I can produce <Button-1> events
everywhere: canvas, widgets - but no <Shift-Button-1>, so I'm stuck.
So the question is: How to make 'event generate' work on canvas items
or how to tweak twapi to also produce <Shift-Button> events.
Any help will be greatly apppreciated
Helmut
PS: I am running Tcl 8.6.10 under Windows 10, 64 bit

Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Tue, 6 Aug 2024 12:10 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
Date: Tue, 06 Aug 2024 14:10:30 +0200
Organization: ratiosoft
Lines: 29
Message-ID: <v634bjhn84dkb3easgcapqlpfdi26ujm2e@4ax.com>
References: <qfq1bj95rbgdrlnth8qp03c22cbqrhkn4h@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 06 Aug 2024 14:10:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8376e6914f4eb196635c2c2c3b96b7e2";
logging-data="1672834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Icx3gNuCfrXpVh/gOfiq3"
Cancel-Lock: sha1:2TLFvQul2wdlz6Yla4ZjSZ9NnTY=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

To answer my own question: The following script does the trick.
---
package require Tk
foreach ch [winfo children .] {destroy $ch}

set fr [ttk::frame .fr]
set btn1 [ttk::button $fr.btn1 -text "Simple click"]
set btn2 [ttk::button $fr.btn2 -text "Shift click"]
pack $btn1 $btn2
pack $fr

bind $btn1 <Button-1> {puts "Simple click"}
bind $btn2 <Shift-Button-1> {puts "Shift click"}

puts -nonewline "Press <Enter> to watch a message appear ... "
gets stdin
event generate $btn1 <Button-1>
puts -nonewline "Press <Enter> to watch another message appear ... "
gets stdin
event generate $btn2 <Button-1> -state 31
---
The trick is the '-state 31' to achieve a 'Shift click'. I discovered
this flag / option on the event manual page where it was mentioned
that it 'Corresponds to the %s substitution for binding scripts.'
Then it was only a matter of trying out what a 'Shift click' produced
with '%s'.

I hope this will be useful to some of you some time ...
Helmut

Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Tue, 6 Aug 2024 12:31 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
Date: Tue, 06 Aug 2024 14:31:50 +0200
Organization: ratiosoft
Lines: 6
Message-ID: <je54bjdejuk03doi5as4rcabb7fsk9kt20@4ax.com>
References: <qfq1bj95rbgdrlnth8qp03c22cbqrhkn4h@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 06 Aug 2024 14:31:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8376e6914f4eb196635c2c2c3b96b7e2";
logging-data="1684979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+U4L4qSL107ZiWX5PneigY"
Cancel-Lock: sha1:tSRahsZOKutnuBR/8C8rFeR6vuc=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Well the joy was premature: It works with e.g. buttons but not with
canvas items. And I believre now that it cannot be done:
The 'event generate' command expects a window - in this case the
canvas - and delivers the event there. So I do not see a chance to
deliver different events to individual items on this canvas.
Too bad ...

Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
From: Schelte
Newsgroups: comp.lang.tcl
Organization: KPN B.V.
Date: Tue, 6 Aug 2024 13:51 UTC
References: 1 2
Date: Tue, 6 Aug 2024 15:51:42 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
Newsgroups: comp.lang.tcl
References: <qfq1bj95rbgdrlnth8qp03c22cbqrhkn4h@4ax.com>
<je54bjdejuk03doi5as4rcabb7fsk9kt20@4ax.com>
Content-Language: nl-NL, en-US
From: nospam@wanadoo.nl (Schelte)
In-Reply-To: <je54bjdejuk03doi5as4rcabb7fsk9kt20@4ax.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$167f9b5c$6fba712c@2eb89406819444b7>
Organization: KPN B.V.
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!weretis.net!feeder8.news.weretis.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe007.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 26
Injection-Date: Tue, 06 Aug 2024 15:51:43 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1733
View all headers

On 06/08/2024 14:31, Helmut Giese wrote:
> Well the joy was premature: It works with e.g. buttons but not with
> canvas items. And I believre now that it cannot be done:
> The 'event generate' command expects a window - in this case the
> canvas - and delivers the event there. So I do not see a chance to
> deliver different events to individual items on this canvas.
> Too bad ...

You have to provide an x- and y coordinate for the canvas to be able to
determine which item is affected:

canvas .c -width 500 -height 500
set sq1 [.c create rectangle 100 100 200 200 -fill blue]
set sq2 [.c create rectangle 300 300 400 400 -fill red]
pack .c
..c bind $sq1 <1> {puts "Square 1"}
..c bind $sq2 <1> {puts "Square 2"}
after 1000 {event generate .c <Button-1> -x 120 -y 180}
after 2000 {event generate .c <Button-1> -x 320 -y 380}

The coordinates will have to be adjusted if the canvas is scrolled.

Schelte

Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Tue, 6 Aug 2024 20:21 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Generate <Shift-Button> event on a canvas (on Windows)
Date: Tue, 06 Aug 2024 22:21:49 +0200
Organization: ratiosoft
Lines: 17
Message-ID: <pk05bjht6pamnc8kspa1ca954lr9pskk4e@4ax.com>
References: <qfq1bj95rbgdrlnth8qp03c22cbqrhkn4h@4ax.com> <je54bjdejuk03doi5as4rcabb7fsk9kt20@4ax.com> <nnd$167f9b5c$6fba712c@2eb89406819444b7>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 06 Aug 2024 22:21:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8376e6914f4eb196635c2c2c3b96b7e2";
logging-data="1931043"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lXJKPMC62n0gC6NLFvo3R"
Cancel-Lock: sha1:Ycxy05LBSw6pvVJ4MiQDQDeyLY4=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Schlau müsste man sein ... (Appr. translation: It would help to be
smart ...)
Hi Schelte,
it works - of course it does.
I read the event man page over and over, up and down. I was even a
little proud to have found the '-state' option which helped with my
'shift click' problem. Of course I read the section with the -x and -y
options but it never occurred to me to make a connection:
- I want to generate an event on a canvas.
- I have different items there and I want to direct the event to a
particular item.
And no, it didn't occur to me that using the item's coordinates could
help with that. As I said above: Schlau müsste man sein ...

Many, many thanks Schelte. I'm so grateful for all you smart and
helpful guys hanging around here.
Helmut

1

rocksolid light 0.9.8
clearnet tor