David Steffen writes 5th June 98: > I have started experimenting with QD.pl and the toolbox routines. >My goal is a program that will draw a graph on the screen and save >it to disk as a PICT file. I can do the former with the Toolbox >calls and the latter with QD, but not vice versa. One of the most >serious limitations to my understanding is how one goes back and >forth between handles and scalars (used by QuickDraw) and MacPerl >(which doesn't use raw memory reverences, AFAIK). > > Second question: could someone point me to sample code which >sends a PICT to the printer in the "normal" Mac way? I'd like >to have the option of printing the graph. You could do as you suggest and 'write' the graph using 'qd.pl' and save the file as a 'PICT'. (Maybe you could also do this starting from QuickDraw.pm, but I don't know how to save the drawing as a file.) Your example works but for a minor slip of the pen -- you wrote: >$temp = substr($data, 512); >$myPict = PicHandle->new( $data ); ^^^^^ and in the last line above you meant 'PicHandle($temp). With this change the picture comes up, and in particular '$y = $x->bottom' has the expected value. If you want, btw, to put a 'PICT' file into a MacWindow you need to make a string of the file: hence you would do something like this: open(IN, $pict) $f = join('', <IN>); $f = substr($f, 512); In your example '$data' is already a string, avoiding the second line above. There are other ways of doing it set out in Chris Nandor's chapters in MacPerl:Power & Ease, pp. 207 et sec. Having got the 'PICT' file (which MacPerl will save as a MPS 'TEXT' file I believe), you could change the creator to R*ch (BBEdit) and the type to 'PICT' using 'Files.pm'. Then, with the file in that form you can look at it on the screen and print it it the usual way. I think that might be one of the simplest solutions to your problem. (Another solution would be to write the file in PostScript and convert it with 'Distiller' to '.pdf' for viewing, but I would be burned at the stake for even dreaming of thinking of suggesting such a thing here, so I won't.) You could also (if it would be useful) use AppleScript to get the finder to open the BBEdit file for viewing (or printing) automatically from the MacPerl script. > Last question: when programs exit abnormally, windows I create >don't get deallocated, and the only way I have found to get rid >of them is to quit MacPerl. Is there a better way? You need an END block: END { $win->dispose } That will usually look after unexpected hang-ups, the menu-bar "Stop Script" and the key-board equivalent 'cmd-period'. A script which I hope might be helpful is appended below. More information on AppleEvents.pm and Files.pm can be found in MacPerl:Power & Ease (pp. 252 & pp. 182 et sec.) Alan Fry MacPerl Power & Ease by Vicki Brown and Chris Nandor ISBN1-881957-32-2 Published by: Prime Time Freeware info@ptf.com =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #!perl use Mac::Events; use Mac::Windows; use Mac::QuickDraw; use Mac::Files; use Mac::AppleEvents; require "qd.pl"; my($has, $obj, $evt, $rep, $file, $data); qd::SetRect(*win_r,0,0,200,200); qd::SetRect(*circ,20,10,70,60); qd::OpenPicture($win_r); qd::ClipRect($win_r); qd::RGBForeColor(38665, 7864, 7208); qd::PaintOval($circ); qd::MoveTo(20, 120); qd::TextSize(24); qd::RGBForeColor(0, 16000, 0); qd::DrawString('Hello there'); $data = qd::ClosePicture(); $file = "picFile\.pic"; open OUTFILE, ">$file" or die "Can't open output file: $!\n"; print OUTFILE $data; close OUTFILE; $has = FSpGetFInfo($file); $has->fdCreator("R*ch"); $has->fdType("PICT"); FSpSetFInfo($file, $has); $obj = "obj{want:type(file), from:null(), form:name, seld:TEXT(\@)}"; $evt = AEBuildAppleEvent('aevt', 'odoc', 'sign', 'MACS', 0, 0, "'----':$obj", $file) or die $^E; $rep = AESend($evt, kAEWaitReply) or die $^E; AEDisposeDesc $evt; AEDisposeDesc $rep; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch