Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: strange item moving behavior in tk canvas
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

Report this thread to moderator Post Follow-up to this message
Old Post
Alexandre Ferrieux
04-03-08 12:58 AM


Re: strange item moving behavior in tk canvas
selflearner 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

Report this thread to moderator Post Follow-up to this message
Old Post
Bruce Hartweg
04-03-08 12:58 AM


Re: strange item moving behavior in tk canvas
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Alexandre Ferrieux
04-03-08 12:58 AM


Re: strange item moving behavior in tk canvas
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Donald Arseneau
04-03-08 04:02 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): « 1 [2]
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:10 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.