Prev: Rotating lists clockwise - OOPS
Next: Basic TK question
From: M. Soyka on 29 Jul 2010 20:42 Hello all, I'm using the virtual event capability of Tk and noticed an inconsistency in how Tk reports the event ID using the %T descriptor. Specifically, I get one value when I use mouse clicks to generate the event and another when I use the "event generate" command. To illustrate, consider the following code sequence: canvas .c -width 100 -height 100 pack .c event add <<V1>> <Double-Button-1> bind .c <<V1>> {puts "mouse generates event Id %T"} If you double-click in the canvas, you get the expected output "mouse generates event Id 4" Now change the bind to output a different message and invoke event generate: bind .c <<V1>> {puts "event command generates event Id %T"} event generate .c <<V1>> What comes out is: "event command generates event Id 35" So we have two different event IDs for the same virtual event. I expected to see the same event ID so my question is why is this correct or expected behavior? Next, I noticed that "35" is one beyond the highest-numbered X event ID and wondered if I were to define an additional virtual event, would it generate 36. Modifying the above code to use the right mouse button instead of the left and proceeding exactly as above: event add <<V3>> <Double-Button-3> bind .c <<V3>> {puts "mouse generates event Id %T"} "mouse generates event Id 4" bind .c <<V3>> {puts "event command generates event Id %T"} event generate .c <<V3>> "event command generates event Id 35" So the answer is no, it generates the same ID and leads to two questions: Q1. Why doesn't it generate 36? Q2. How can a script that expects a %T argument and handles both events distinguish between the two? Thank you for the education I'm about to get! Mike
From: Harald Oehlmann on 30 Jul 2010 02:41 Hello Mike, On 30 Jul., 02:42, "M. Soyka" <mssr...(a)gmail.com> wrote: > To illustrate, consider the following code sequence: > > canvas .c -width 100 -height 100 > pack .c > > event add <<V1>> <Double-Button-1> > bind .c <<V1>> {puts "mouse generates event Id %T"} > > If you double-click in the canvas, you get the expected output > "mouse generates event Id 4" When I read the docs of bind: http://www.tcl.tk/man/tcl8.5/TkCmd/bind.htm#M51 The "Tag" %T is replaced by the event type. In my understanding this should be "Button" in the upper example. Why it returns 4 ? I don't know. > event generate .c <<V1>> > > What comes out is: > "event command generates event Id 35" I suppose "35" is for virtual events. The reason for the first event to fire was a Button-Event. The reason for the second was an event generate on a virtual event. If you do: 8 % event generate .c <Button-1> 9 % event generate .c <Button-1> mouse generates event Id 4 Strange... Sorry, no more knowledge on this side, Harald
From: M. Soyka on 30 Jul 2010 07:05 On 7/30/2010 2:41 AM, Harald Oehlmann wrote: > Hello Mike, > > On 30 Jul., 02:42, "M. Soyka"<mssr...(a)gmail.com> wrote: >> To illustrate, consider the following code sequence: >> >> canvas .c -width 100 -height 100 >> pack .c >> >> event add<<V1>> <Double-Button-1> >> bind .c<<V1>> {puts "mouse generates event Id %T"} >> >> If you double-click in the canvas, you get the expected output >> "mouse generates event Id 4" > > When I read the docs of bind: > http://www.tcl.tk/man/tcl8.5/TkCmd/bind.htm#M51 > > The "Tag" %T is replaced by the event type. > In my understanding this should be "Button" in the upper example. > Why it returns 4 ? I don't know. It is 4 because (I think) the X Window system defined button presses to be event ID 4. > >> event generate .c<<V1>> >> >> What comes out is: >> "event command generates event Id 35" > > I suppose "35" is for virtual events. Seems plausible. Again, the X Window system defines event IDs up to 34 for events like "Enter", "Leave". I forget what #34 is but it makes some sense that virtual events would be assigned 35 and up. > The reason for the first event to fire was a Button-Event. > The reason for the second was an event generate on a virtual event. > > If you do: > 8 % event generate .c<Button-1> > 9 % event generate .c<Button-1> > mouse generates event Id 4 > > Strange... > > Sorry, no more knowledge on this side, > Harald
|
Pages: 1 Prev: Rotating lists clockwise - OOPS Next: Basic TK question |