Code Comments
Programming Forum and web based access to our favorite programming groups.On Apr 2, 9:49=A0pm, selflearner <chenzhen1...@gmail.com> wrote:
> .c bind movline <Button-1> {canvasMark %x %y .c}
> #.c bind movline <B1-Motion> {canvasDrag %x %y .c}
>
> proc canvasMark { x y can} {
> =A0 ...
> =A0 set canvas($can,obj) [$can find withtag movline]
> ...
> }
Two things to change:
(1) "curry" the individual handlers so that they capture their
individual item is:
foreach it [.c find withtag movline] {
.c bind $it <Button-1> [list canvasMark %x %y .c $it]
}
# you can leave the B1-Motion "non-individualized" because
# the target is known at that time:
.c bind movline <B1-Motion> {canvasDrag %x %y .c}
(2) Don't use [.c find] in the canvasMark. Use the extra $it argument
instead:
proc canvasMark { x y can it} {
..
set canvas($can,obj) $it
..
}
-Alex
Post Follow-up to this messageselflearner wrote:
> On Apr 2, 3:34 pm, Bruce Hartweg <bruce-n...@hartweg.us> wrote:
>
> you mean the syntax to allow more than one searchspec in "find"?
>
ok - you are taking about different modes of find, i was thinking sloppy
you can only search onw way at a time (closest, withtag, above, etc)
but anyu of them that take a tagOrId can use an expression of more that
one tag, e.g. tag1 || (tag2&&!tag3)
>
> refer to the code, I just set a variable to the creation of line as
> follow:
> set lineID [.c create line 1 1 40 40 90 60 -width 2]
> .c bind $lineID <Button-1> {canvasMark %x %y .c}
>
i meant for you to pass the ID into the command
.c bind $lineID <Button-1> {canvaseMark %x %y .c $lineID}
and then in the body of the method, use the ID provided and
skip the find altogether.
>
> I would be really appreciated if you can give me the direct link
> because there are just so many of them!
I don't have a link, I am referring to the demos that come with the tk
distribution. running the Tk Demos gives you a screen with a list of demos
- each one is a link to running code which then has a way to view the code
the first canvas demo shows all the different types of items, and it has the
drag to move behavior right in it. You should have the following directory
<install root>/lib/tkX.y/demos/
where install root is wherever you have Tcl/Tk installed, and X.y is the ver
sion
you have. in that directopry, runt the widget.tcl script.
Bruce
Post Follow-up to this messageOn Apr 3, 12:43=A0am, Bruce Hartweg <bruce-n...@hartweg.us> wrote:
>
> .c bind $lineID <Button-1> {canvaseMark %x %y .c $lineID}
You mean:
.c bind $lineID <Button-1> [list canvaseMark %x %y .c $lineID]
-Alex
Post Follow-up to this messageOn Apr 2, 3:43 pm, Bruce Hartweg <bruce-n...@hartweg.us> wrote:
>
> .c bind $lineID <Button-1> {canvaseMark %x %y .c $lineID}
>
> and then in the body of the method, use the ID provided and
> skip the find altogether.
That gets him back to his original problem that it
is too hard to click directly on a thin line.
What I'd do is probably dumb, but I never let that stop me...
Try double-drawing the lines. Whenever you draw a line
on the canvas, draw a thicker, transparent one over it,
and do the bindings for the invisible thick line. Then
you can pass the IDs of both lines into your drag-handler
command.
Donald Arseneau asnd@triumf.ca
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.