Subject: Re: Calling MrEd directly?
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 30 Jun 2001 11:20:24 GMT
Newsgroups: comp.lang.scheme
Message-ID: <9hkclo$kjee4$1@fido.engr.sgi.com>
Jordan Katz  <katz@underlevel.net> wrote:
+---------------
| ":";exec mred -r $0 "$@"
|
| (define my-frame (make-object frame% "My Frame"))
| (define my-button (make-object button% "My Button" my-frame
|                                (lambda (button-callback event)
|                                  (display "Button pressed."))))
| (send my-frame show #t)
+---------------

Note for others who may have been as confused as I when the above
didn't work (other than opening a blank window):

To get this to actually work when run as a stand-alone script from
a shell (rather than from a MrEd graphical-REPL) I found that I had
to add a "(yield (make-semaphore))" after the "send" to get the button
to actually appear. [Or "(yield/sleep {some-large-number})".]

A slightly more complicated example in which the semaphone actually
does something useful:

	#!/bin/sh
	":";exec mred -r $0 "$@"

	(define (make-print-button label parent msg)
	  (make-object button% label parent
		       (lambda (b e) (display msg) (newline))))

	(define f (make-object frame% "Hello"))
	(define v (make-object vertical-panel% f))
	(define m (make-object message% "Hello, World!" v))
	(define h (make-object horizontal-panel% v))
	(define b0 (make-print-button "This" h "You hit THIS one!"))
	(define b1 (make-print-button "That" h "You hit THAT one!"))

	(define quit-sema (make-semaphore))
	(define q (make-object button% "Quit" h
			       (lambda (b e) (semaphore-post quit-sema))))
	(send f show #t)
	(yield quit-sema)


-Rob

-----
Rob Warnock, 31-2-510		<rpw3@sgi.com>
SGI Network Engineering		<http://reality.sgi.com/rpw3/> [until 8/15]
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]