[plt-scheme] Trouble with GUI
Oops, nevermind. All that lets you omit is the super-new at the end.
Daniel
On Sun, 17 Oct 2004 03:27:23 +0900, Daniel Silva <daniel.silva at gmail.com> wrote:
> On Fri, 15 Oct 2004 17:46:50 -0500, Arctic Fidelity <af at aaronhsu.com> wrote:
>
>
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > On 15 Oct 2004 at 8:49, Matthew Flatt wrote:
> >
> > > At Fri, 15 Oct 2004 08:46:13 -0500, "Arctic Fidelity" wrote:
> > > > I think I have the ouput buffer okay, but what's getting me is
> > > > processing the keys. I understand how I would process the buttons,
> > > > but how would I capture the key events from anywhere but the
> > > > output field, and then according to what key was pressed, update
> > > > my disabled text-field appropriately.
> > > >
> > > > The plan I had was to create a procedure for the main window
> > > > which would take the input from the keys, and process it from there.
> > > > However, I cannot seem to figure out how to use "on-subwindow-
> > > > char" or how to change what happens with that, as the frame% has
> > > > nowhere that I can specify a callback procedure.
> > >
> > > I think you're on the right track with `on-subwindow-char'. You need to
> > > derive a subclass of frame% that overrides `on-subwindow-char'.
> >
> > I was afraid you were going to say that, I was actually hoping there
> > was a way I could do that without having to override the defaults,
> > but I suppose that's just what happens. ;-)
>
> Try using a Java-style new operator too :)
> Examples in the test function:
>
> (module overriding-new mzscheme
>
> (provide overriding-new)
>
> (require (lib "class.ss"))
>
> (define-syntax (overriding-new stx)
> (syntax-case stx (local inherit)
> [(_ super%
> (local (inherit-field super-field ...) (define (fn args ...)
> bodies ...) ...)
> (field value) ...)
> #`(new (class super%
> (inherit-field super-field ...)
> (begin
> (define/override (fn args ...)
> bodies ...) ...)
> (super-new))
> (field value)
> ...)]
> [(_ super%
> (local (define (fn args ...) bodies ...) ...)
> (field value) ...)
> #`(_ super% (local (inherit-field) (define (fn args ...) bodies
> ...) ...) (field value) ...)]
> ))
>
> (define (test)
> (define C%
> (class object%
> (init-field x)
> (define/public (add y)
> (+ x y))
> (define/public (sub y)
> (- x y))
> (super-new)))
>
> (define c (new C% (x 1)))
> ;; oops, turn addition into multiplication, sub. into mult.
> (define d (overriding-new C%
> (local
> (inherit-field x)
> (define (add y)
> (* x y))
> (define (sub y)
> (/ x y)))
> (x 1)))
>
> (define (check expected actual)
> (unless (= expected actual)
> (error 'check (format "expected ~a, got ~a"
> expected actual))))
>
> (check 3 (send c add 2))
> (check -1 (send c sub 2))
> (check 2 (send d add 2))
> (check 1/2 (send d sub 2)))
>
> )
>