[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Top window garbage collected in standalone?
I must say, I'm very impressed by the ease at which the technique
outlined here works under 102. This is really cool.
http://www.cs.utah.edu/plt/mailarch/plt-scheme-2000/msg00661.html
I just built my first standalone MrEd EXE.
It weighs in at 1,426KB (including a 2KB scheme file) under NT 4.0.
I'm not complaining about the size -- I can live with this, as I know a
bigger app will probably scale nicely.
Also, I'm impressed with how fast the app starts up -- literally maybe a
second on a 180Mhz Pentium Pro system.
This is the contents of my bat file to do the build:
======================
c:\plt\mzc --gui-exe FileViewer.exe FileViewer.scm
pause
=========================
The application puts up a window which has a button, a drop down
listbox, and an edit box. Basically, the button lets you pick files
which are added to the combo box and displayed in the tex field. When
you pick a previously opened file from the drop down list box, it
updates the text box for that file.
I wanted this utility for trying to understand other Scheme packagaes.
It seemed nice to be able to easily flip between all the files.
Actually, I wanted to read all the files in a directory, but I couldn't
figure out an easy way to pick a directory... And I still need to add
code to recurse over the files in a directory..
Which brings me to the difficulty I'm having.
It appears the top level window seems to be immediately garbage
collected because it opens up and then closes right away. If I start the
EXE up having added extra code to open the file chooser, everything
stays around until I close the file chooser, and then the main window
goes away too.
This is different behavior than under DrScheme.
I find if I put in a:
(sleep/yield 10000000000000)
at the end of the file, the window stays up.
Unfortunately in that case even after I close the window the EXE hangs
around in the application manager.
Can anyone tell me how to fix this?
I define the window frame as a top level variable.
Somehow, this must not be enough.
Here's the source in case anyone is interested,
(released if you like under an MIT/X-type license).
================== FileViewer.scm =============================
; reads files and lets you view them
; By Paul D. Fernhout pdfernhout@kurtz-fernhout.com
(define (directory-chooser)
(get-file "Pick a directory by choosing a file" #f #f #f #f null))
;(directory-chooser)
(define windowFrame (make-object frame% "File Viewer" #f 200 200))
(define (choice-callback widget event)
(load-file-contents (open-input-file (send widget
get-string-selection) 'text))
)
(define (load-file-contents file)
(send windowText insert (read-string 10000 file) 0 100000 #f)
)
(define (directoryButton-callback a b )
(let ((choice (directory-chooser)))
(if choice
(begin
(send directoryChoice append choice)
'(call-with-input-file choice load-file-contents)
(load-file-contents (open-input-file choice 'text))
))
))
(define directoryButton
(make-object button% "Choose file" windowFrame
directoryButton-callback))
(define directoryChoice
(make-object choice% "File:" null windowFrame choice-callback null))
(send directoryChoice stretchable-width #t)
;(send directoryChoice accept-drop-files #t)
(define windowText (make-object text%))
(define windowCanvas (make-object editor-canvas% windowFrame))
(send windowCanvas set-editor windowText)
(send windowFrame show #t)
;pdf added for launching test
;(directory-chooser)
;(sleep/yield 10000000000000)
====================================================
-Paul Fernhout
Kurtz-Fernhout Software
=========================================================
Developers of custom software and educational simulations
Creators of the Garden with Insight(TM) garden simulator
http://www.kurtz-fernhout.com