home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!agate!sprite.Berkeley.EDU!ouster
- From: ouster@sprite.Berkeley.EDU (John Ousterhout)
- Newsgroups: comp.lang.tcl
- Subject: Re: Question on binding
- Date: 17 Aug 1992 15:32:12 GMT
- Organization: U.C. Berkeley Sprite Project
- Lines: 49
- Distribution: world
- Message-ID: <16ogpsINNll1@agate.berkeley.edu>
- References: <1992Aug14.201600.26716@bnr.ca>
- NNTP-Posting-Host: tyranny.berkeley.edu
- Keywords: binding
-
- Subject: Re: Question on binding
- Keywords: binding
-
- In article <1992Aug14.201600.26716@bnr.ca>, tewei@bnr.ca (Te-Wei Sun) writes:
- |>
- |> Hi,
- |>
- |> I wrote a short script in tk trying to bind several mouse events for
- |> canvas. The goal I am trying to achieve here is as follows:
- |>
- |> If I click button 1 once on the canvas, I would like to see the message
- |> "b1 pressed once".
- |>
- |> If I double click button 1 on the canvas, I would like to see ONLY the
- |> message "b1 pressed twice", not "b1 pressed once" and "b1 pressed twice",
- |> The same applied for triple click.
- |>
- |> If I click button 1 on the rectangle widget, I would like to see ONLY the
- |> message "b1 pressed once on rectangle", not "b1 pressed once" and "b1 pressed once on rectangle".
- |>
- |> If I double click button 1 on the rectangle widget, I would like to see ONLY
- |> the message "b1 pressed twice on rectangle" and so on for triple click.
- |>
- |>
- |> Is there any way I can achieve the way I would like to have my bindings?
- |>
-
- There are a couple of things to realize here. First bindings on widgets
- (e.g. "bind .c <1> ...") are independent of bindings on individual items or
- tags within canvases (e.g. ".c bind 2 <1> ..."). If you set up a binding on
- a rectangle within a canvas and also a separate binding on the canvas, both
- will trigger when you click with the mouse in the rectangle. It sounds like
- you want a way to distinguish between a click over an item and a click when
- the mouse isn't over any item. You can distinguish these by checking to see
- if there is a "current" item. If the command ".c find withtag current"
- returns an empty string then the mouse isn't over an item. You can use this
- in the binding for the whole canvas to do nothing when there is a current
- item.
-
- Second, you will always get a single-click event before a double-click event.
- The reason for this is that at the time of the single-click event there's no
- way to know whether or not a second click is going to follow, so Tk always
- issues the single-click event. If you don't want to process the single-click
- in cases where there is (eventually) a double click, then use the "after"
- command in your single-click event handler to delay the real work you want
- to do for a while. If a double-click event follows in the interim, then
- you can cancel the real work. This has the disadvantage of introducing a
- delay in processing single clicks, but I don't see any alternative, given
- your desires.
-