WJG
console show
pack [text .txt] -fill both
.txt insert end "aaaaa\nbbbbb\nccccc\nddddd\eeeeee"
.txt tag add cc 3.0 "3.0 lineend"
.txt tag configure cc -background pink
.txt tag bind cc <Key> { puts KEY-EVENT }
.txt tag bind cc <Button> { puts BUTTON-EVENT }
> If I add a tag the content of a text widget and then add some bindings,
> the mouse events are easily picked up but not the key events. What needs
> to be done to the code below to ensure that the Key binding occurs as
> expected.
It is practically un-doable (at least before someone cranks widget a big
time), [text] tag events occur only at mouse pointer, so you'd have to do
something like
event generate . <Motion> \
-warp 1 \
-x [lindex [.txt bbox 3.1] 0] \
-y [lindex [.txt bbox 3.1] 1]; focus -force .txt
but that is not, I repeat, not a good thing to do (1: users don't like
their mouse cursor being warped; 2: users don't like windows taking focus
without a reason; 3: Windows won't probably even let you focus like that;
4 (this is the worst): finding that index where to warp is major trouble).
So don't bind key-events to tags, they'll just let you down. Instead, bind
key-events to [text] itself and every time event fires, you check whether
[.txt tag names insert] includes your "bound" tag. Something like
pack [text .txt] -fill both
.txt insert end "aaaaa\nbbbbb\nccccc\nddddd\eeeeee"
.txt tag add cc 3.0 "3.0 lineend"
.txt tag configure cc -background pink
bind .txt <Key> { helper_proc %W }
.txt tag bind cc <Button> { puts BUTTON-EVENT }
proc helper_proc {wid} {
if {{cc} ni [$wid tag names insert]} {return -code continue}
puts KEY-EVENT
}
This one has a slight problem, that when insertion cursor is on the right
side of last tagged character, event doesn't fire. Making that happen (if
it is needed) is left as exercise, just as converting this to work with
8.4 series (hint: knights say so).
--
-Kaitzschu
s="TCL ";while true;do echo -en "\r$s";s=${s:1:${#s}}${s:0:1};sleep .1;done
Thanks for the reply. What's you've suggested is basically the solution
that I'm currently working with. If the tags bind key behaviour is not
genuingely supported, then it ought to be removed from the manual!
Thanks, again.
Will