From: Jim Newton
Subject: callbacks on graphical objects
Date: 
Message-ID: <34vgnhF4g31rpU1@individual.net>
Another TK / ltk question.  does TK support callbacks on polygons?
I.e., how can i specify a callback :function on a shape such that the
callback gets called with i click the mouse in the interior of that
shape?  Is it possible to set up 3 different callbacks?

1) to call with the mouse is clicked over the shape
2) to call when the mouse moves from the exterior to the interior
      of the shape
3) to call when the mouse leaves the shape.

I.e., i'd like to change the shapes color when the mouse is over
the shape, that way the user sees which shape has "focus".

Does TK support these types of callbacks? and does ltk support them?

-jim

From: Bruce Stephens
Subject: Re: callbacks on graphical objects
Date: 
Message-ID: <87fz119m0g.fsf@cenderis.demon.co.uk>
Jim Newton <·····@rdrop.com> writes:

> Another TK / ltk question.  does TK support callbacks on polygons?
> I.e., how can i specify a callback :function on a shape such that the
> callback gets called with i click the mouse in the interior of that
> shape?  Is it possible to set up 3 different callbacks?
>
> 1) to call with the mouse is clicked over the shape
> 2) to call when the mouse moves from the exterior to the interior
>       of the shape
> 3) to call when the mouse leaves the shape.
>
> I.e., i'd like to change the shapes color when the mouse is over
> the shape, that way the user sees which shape has "focus".
>
> Does TK support these types of callbacks? and does ltk support them?

Tk does, kind of, anyway.  It certainly supports 1, but 2 and 3 are a
bit different: 

    Enter and Leave events trigger for an item when it becomes the
    current item or ceases to be the current item; note that these
    events are different than Enter and Leave events for windows.

I don't know about ltk, but presumably it supports binding in
canvases, and presumably the event types carry across.
From: Peter Herth
Subject: Re: callbacks on graphical objects
Date: 
Message-ID: <csha19$ab7$02$1@news.t-online.com>
Jim Newton wrote:
> Another TK / ltk question.  does TK support callbacks on polygons?
> I.e., how can i specify a callback :function on a shape such that the
> callback gets called with i click the mouse in the interior of that
> shape?  Is it possible to set up 3 different callbacks?
> 
> 1) to call with the mouse is clicked over the shape
> 2) to call when the mouse moves from the exterior to the interior
>      of the shape
> 3) to call when the mouse leaves the shape.
> 
> I.e., i'd like to change the shapes color when the mouse is over
> the shape, that way the user sees which shape has "focus".
> 
> Does TK support these types of callbacks? and does ltk support them?
> 
> -jim

You can bind events to canvas items like to any widgets, though
you have to use the itembind function at the moment (need to extend
the bind generic function on canvas items in 0.8.8)

Peter

-- 
pet project: http://dawn.netcologne.de
homepage:    http://www.peter-herth.de
lisp stuff:  http://www.peter-herth.de/lisp.html
get Ltk here: http://www.peter-herth.de/ltk/
From: Bruce Stephens
Subject: Re: callbacks on graphical objects
Date: 
Message-ID: <87sm4zob9z.fsf@cenderis.demon.co.uk>
Peter Herth <·······@t-online.de> writes:

[...]

> You can bind events to canvas items like to any widgets, though you
> have to use the itembind function at the moment (need to extend the
> bind generic function on canvas items in 0.8.8)

That will be a nice improvement on Tcl/Tk.  (In general callbacks are
likely to be an improvement on Tcl/Tk, since Tcl lacks anonymous
functions, closures, etc.)

As I mentioned, <Enter>/<Leave> events on canvas items don't
necessarily behave in the way one would want.  However, there's a
decent chance their behaviour will be acceptable, so it's worth
trying, IMHO.