[plt-scheme] MrEd Learning

From: mike (mh983 at netscape.net)
Date: Mon Aug 25 09:32:17 EDT 2003

Alex, I think you're right about the canvas being a component that
normally doesn't receive the focus.  Here's one solution I thought of:

Just before specifying the overrides in your subclass of canvas, add this:

(rename (super-focus focus))

That gives us access to the superclass implementation of the focus method.

Now, in our implementation of on-event, we can set the focus by calling
super-focus:

(define on-event (lambda (event) (send msg set-label "Canvas mouse")
(super-focus)))

This sets the focus when you just hover the mouse as well, because I
haven't learned how to differeniate between mouse-hover and mouse-click yet.

I tried doing the same for super-on-event.  I thought maybe the Canvas
superclass by default would set the focus for us on a mouse-click and we
just weren't calling it, but that didn't work.  So I think the Canvas
just does not normally receive the focus when you click on it, which
probably makes sense since it's a drawing area and not a control.

mike


alex.peake at comac.com wrote:
> Many thanks Mike.
> 
> It worked, until you click the button. It appears that giving the canvas the focus is the problem.
> Your code change starts it off with the focus, but once lost it cannot regain it. Perhaps canvas is
> too "low level" an object to receive focus?
> 
> Alex
> 
> 
>>-----Original Message-----
>>From: mike [mailto:mh983 at netscape.net]
>>Sent: Friday, August 22, 2003 7:22 PM
>>To: alex.peake at comac.com
>>Subject: Re: [plt-scheme] MrEd Learning
>>
>>
>>Hey there Alex.  I just tried the exact code from your email again (this
>>time on Windows XP) and it didn't work.  I think I know what will make
>>yours work now though.
>>
>>Try moving your (send frame show #t) to the very end instead of right
>>before defining the canvas, where you have it now.  When I did that,
>>your code worked fine.  Hope that works for you.
>>
>>Maybe next we can come up with an explanation for why showing the frame
>>before creating the canvas breaks only the keyboard even handler.
>>
>>mike
>>
>>alex.peake at comac.com wrote:
>>
>>>Thanks for looking at this Mike.
>>>
>>>Just to be absolutely sure, I copied and pasted the below code back to DrScheme (I use Windows
>>>2000):
>>>Still no response to keyboard.
>>>
>>>For the second example, I figured that if you change:
>>>(append-editor-operation-menu-items m-edit)
>>>To:
>>>(append-editor-operation-menu-items m-edit #f)
>>>
>>>It works! (Documentation bug).
>>>
>>>Alex
>>>
>>>
>>>
>>>
>>>>Date: Thu, 21 Aug 2003 12:35:47 -0500
>>>>From: mike <mh983 at netscape.net>
>>>>To: plt-scheme at list.cs.brown.edu
>>>>Subject: [plt-scheme] RE: MrEd Learning
>>>>
>>>>Hello Alex.  As far as the first example, assuming you copied/pasted the
>>>>example so there are no typos, then clicking on the canvas first, then
>>>>pressing a keyboard key worked for me.  I'm using plt on a Mandrake
>>>>Linux/Gnome machine.
>>>>
>>>>mike
>>>>
>>>>
>>>>
>>>>>From: "Alex Peake" <apeake at comac.com>
>>>>>To: <plt-scheme at list.cs.brown.edu>
>>>>>Date: Sat, 16 Aug 2003 21:48:19 -0700
>>>>>Subject: [plt-scheme] MrEd Learning
>>>>>
>>>>>I am trying out MrEd - following the manual.
>>>>>
>>>>>In 2. Windowing Toolbox Overview, the example is:
>>>>>
>>>>>;; Make a frame by instantiating the frame% class
>>>>>(define frame (instantiate frame% ("Example")))
>>>>>;; Make a static text message in the frame
>>>>>(define msg (instantiate message% ("No events so far..." frame)))
>>>>>;; Make a button in the frame (using keyword-based arguments, for demonstration)
>>>>>(instantiate button% () (label "Click Me") (parent frame)
>>>>>;; Callback procedure for a button click
>>>>>(callback (lambda (button event) (send msg set-label "Button click"))))
>>>>>;; Show the frame by calling its show method
>>>>>(send frame show #t)
>>>>>
>>>>>;; Derive a new canvas (a generic drawing window) class to handle events
>>>>>(define my-canvas%
>>>>> (class canvas% ; The base class is canvas%
>>>>>;; Declare overrides:
>>>>>(override on-event on-char)
>>>>>;; Define overriding method to handle mouse events
>>>>>(define on-event (lambda (event) (send msg set-label "Canvas mouse")))
>>>>>;; Define overriding method to handle keyboard events
>>>>>(define on-char (lambda (event) (send msg set-label "Canvas keyboard")))
>>>>>;; Call the superclass initialization (and pass on all init args)
>>>>>(super-instantiate ())))
>>>>>;; Make a canvas that handles events in the frame
>>>>>(instantiate my-canvas% (frame))
>>>>>
>>>>>The following text says: Clicking on the canvas calls on-event. While the canvas has
>>>>
>>>>the keyboard
>>>>
>>>>
>>>>>focus, typing on the keyboard invokes the canvas’s on-char method.
>>>>>
>>>>>However, this never happens - the message never gets changed to "Canvas keyboard"?
>>>>>
>>>>>
>>>>>In 8. Editor Toolbox, the example is:
>>>>>
>>>>>(define f (instantiate frame% ("Simple Edit" #f 200 200)))
>>>>>(define c (instantiate editor-canvas% (f )))
>>>>>(define t (instantiate text% ()))
>>>>>(send c set-editor t)
>>>>>(send f show #t)
>>>>>
>>>>>(define mb (instantiate menu-bar% (f )))
>>>>>(define m-edit (instantiate menu% ("Edit" mb)))
>>>>>(define m-font (instantiate menu% ("Font" mb)))
>>>>>(append-editor-operation-menu-items m-edit)
>>>>>(append-editor-font-menu-items m-font)
>>>>>
>>>>>The following text says: The user can also insert an embedded editor by selecting
>>>>
>>>>Insert Text from
>>>>
>>>>
>>>>>the Edit menu;
>>>>>
>>>>>However, there is no  Insert Text choice?
>>>>>
>>>>>
>>>>>-- __--__--
>>>>>
>>>
>>>
> 






Posted on the users mailing list.