[plt-scheme] clicking in an editor window

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Oct 8 09:50:01 EDT 2005

At Sat, 08 Oct 2005 09:32:28 -0400, Prabhakar Ragde wrote:
> Do I have to create a new class inheriting from editor% and override 
> on-event in it, or is there a simpler way? That's question one.

An alternative is to get the editor's keymap, and then install an
action for "leftbutton", etc.:

 (define k (send an-editor get-keymap))
 (send k add-function "do-click" (lambda (k e)
                                   (printf "ouch\n")))
 (send k map-function "leftbutton" "do-click")

> Question two concerns the clickback. I thought that my wait-for-user 
> function could just call semaphore-wait, and my clickback function could 
> call semaphore-post. So I created a function mytest which writes a line, 
> calls my wait-for-user function, then writes a line. When I run 
> (mytest), a window comes up, the first line is written, and then I 
> cannot get it to respond when I click in it; I have to hit the Stop 
> button. But when I run (thread mytest), it works the way I want it to. 

Each DrScheme program runs in an "eventspace" that groups all of the
program's GUI elements. The eventspace has a designated handler thread,
which is the thread used to run callbacks, etc. The program's initial
evaluation also runs in the eventspace's main thread.

So, by using `semaphore-wait', the program's handler thread is blocked,
and it can't handle GUI events. Putting the `semaphore-wait' in a
separate thread allows the handler thread to process GUI events.
(Putting the `semaphore-post' in a separate thread doesn't help,
because the problem is handling the GUI event that eventually triggers
the post.)

Instead of `semaphore-wait', you can use `yield', which handles GUI
events while it waits for the given synchronized object to be ready.
I think that's probably the right approach in this case.


Posted on the users mailing list.