;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME: ; printps ; ; PURPOSE: postscript visualisation/archiving/printing ; ; CATEGORY: for the postscripts ; ; CALLING SEQUENCE: ; imprime [,psfilename] ; ; INPUTS: ; ; psfilename: the name of the postscript file we want to ; visualize and/or print and/or archive. It can also refer ; to a gzipped postscript file. If needed, this name will ; be completed by .ps and/or .gz ; ; KEYWORD PARAMETERS: None ; ; COMMON BLOCKS: cm_4ps ; ; SIDE EFFECTS: ; - archiving possibilities - ; ; if archive_ps (common variable of cm_4ps) ne 0 then the postscript ; can be saved for archiving if it is printed or if the button ; "archive ps" is pressed. if it is printed and archive_ps = 1 then ; the archiving is done automatically whereas we ask if the postscript ; file must be archived or not. ; If the postcript name is "idl.ps" (default name) then this name will ; be changed to number.ps (number automatically found to be 1 larger ; that any of the existing ps file). ; ; RESTRICTIONS: ; ; 1) this is working only with unix/linux/osX machines ; ; 2) definition of the printing command ; ; the printing command is defined by the common variable "print_command" ; in cm_4ps. This command must be defind/build in a way that it the ; instruction: ; print_command[i]+printer_machine_names[i]+' '+file.ps ; or ; print_command+printer_machine_names[i]+' '+file.ps ; is working. default definition is '\lpr -P' ; ; EXAMPLE: IDL> printps ; ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) ; 21/12/98 ; 25/8/19999 utilisation des widgets ; 8/9/1999 utilisation de cw_bgroup ; June 2005: Sebastien Masson: cleaning, english version with new commons ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ PRO printps_event, event ;------------------------------------------------------------ ; include commons @cm_4ps IF NOT keyword_set(key_forgetold) THEN BEGIN @updatenew ENDIF ;------------------------------------------------------------ ; What kind of event do we have ? widget_control, event.id, get_uvalue = uval ; case on the event CASE uval.name OF ;------------------------------------------------------------ ; visualize case : postscript visualization ;------------------------------------------------------------ 'visualize':BEGIN ; paper orientation if key_portrait EQ 1 then ori = 'portrait' ELSE ori = 'seascape' ; paper format CASE round(10*(total(page_size))) OF round(10*(83.9611 + 118.816)) : papsize = 'a0' round(10*(59.4078 + 83.9611)) : papsize = 'a1' round(10*(41.9806 + 59.4078)) : papsize = 'a2' round(10*(29.7039 + 41.9806)) : papsize = 'a3' round(10*(20.9903 + 29.7039)) : papsize = 'a4' round(10*(14.8519 + 20.9903)) : papsize = 'a5' round(10*(10.4775 + 14.8519)) : papsize = 'a6' round(10*(7.40833 + 10.4775)) : papsize = 'a7' round(10*(5.22111 + 7.40833)) : papsize = 'a8' round(10*(3.70417 + 5.22111)) : papsize = 'a9' round(10*(2.61056 + 3.70417)) : papsize = 'a10' round(10*(100.048 + 141.393)) : papsize = 'b0' round(10*(70.6967 + 100.048)) : papsize = 'b1' round(10*(50.0239 + 70.6967)) : papsize = 'b2' round(10*(35.3483 + 50.0239)) : papsize = 'b3' round(10*(25.0119 + 35.3483)) : papsize = 'b4' round(10*(17.6742 + 25.0119)) : papsize = 'b5' round(10*(22.86 + 30.48)) : papsize = 'archA' round(10*(30.48 + 45.72)) : papsize = 'archB' round(10*(45.72 + 60.96)) : papsize = 'archC' round(10*(60.96 + 91.44)) : papsize = 'archD' round(10*(91.44 + 121.92)) : papsize = 'archE' round(10*(21.59 + 33.02)) : papsize = 'flsa' round(10*(21.59 + 33.02)) : papsize = 'flse' round(10*(13.97 + 21.59)) : papsize = 'halfletter' round(10*(19.05 + 25.4)) : papsize = 'note' round(10*(21.59 + 27.94)) : papsize = 'letter' round(10*(21.59 + 35.56)) : papsize = 'legal' round(10*(27.94 + 43.18)) : papsize = '11x17' round(10*(43.18 + 27.94)) : papsize = 'ledger' ELSE:papsize = 'a4' ENDCASE ; call the viewers CASE event.value OF 'Ghostview':spawn, '\ghostview -'+papsize+' -quiet -'+ori+' '+uval.nameps 'Ghostscript':spawn, '\gs -sPAPERSIZE='+papsize+' -q '+uval.nameps 'Kghostview':spawn, '\kghostview '+uval.nameps ENDCASE return END ;------------------------------------------------------------ ; print case: print and archive the file if needed ;------------------------------------------------------------ 'print':BEGIN ; printer selection printer = printer_machine_names[event.value] ; print CASE n_elements(print_command) OF 0:ptcmd = '\lpr -P' 1:ptcmd = print_command[0] n_elements(printer_machine_names):ptcmd = print_command[event.value] ELSE:BEGIN ng = report('bad definition of print_command, common variable of cm_4ps. !C we did not print the postscript file', /simple) return END ENDCASE spawn, ptcmd + printer + ' ' + uval.nameps ; ; printing informations... ; spawn, '\lpq -P'+imprimante+' -l', info ; ; display them ; xdisplayfile, 'nothing', text = info $ ; , title = 'Printing Info '+file_basename(uval.nameps) $ ; , height = n_elements(info) < 24 END ELSE: ENDCASE ; we destroy the widget widget_control, event.top, /destroy ; if the file was originaly gzipped, then we re-gzip it and exit IF uval.gzip THEN BEGIN spawn, '\gzip ' + uval.nameps return ENDIF ;------------------------------------------------------------ ; archiving... ;------------------------------------------------------------ IF (uval.name EQ 'print' OR uval.name EQ 'archive') $ AND keyword_set(archive_ps) THEN BEGIN IF archive_ps NE 1 AND uval.name EQ 'print' then begin wesave = report('Shall we archive the postcript?', /defaul_no, /question) IF wesave EQ 0 THEN RETURN ENDIF ; if the name of the postscript is idl.ps then we change it IF file_basename(uval.nameps) EQ 'idl.ps' then BEGIN ; get the name of all the *.ps or *.ps.gz files available in psdir allps = file_search(psdir+'*[.ps|.ps.gz|.pdf]', /test_regular, /nosort) allps = file_basename(file_basename(allps,'.gz'),'.ps') allps = file_basename(allps,'.pdf') ; find which of these names corresponds to numbers... ; get ascii codes of the names testnumb = byte(allps) ; longest name maxstrlen = (size(testnumb, /dimensions))[0] ; ascii codes can be 0 or between byte('0') and byte('9') testnumb = testnumb EQ 0 OR $ (testnumb GE (byte('0'))[0] AND testnumb LE (byte('9'))[0]) testnumb = where(total(testnumb, 1) EQ maxstrlen, count) IF count NE 0 THEN BEGIN ; get the largest number psnumber = fix(allps[testnumb]) psnumber = (psnumber[reverse(sort(psnumber))])[0] + 1 ENDIF ELSE psnumber = 0 ; update uval.nameps dirname = file_dirname(uval.nameps, /mark_directory) uval.nameps = dirname+strtrim(psnumber, 2)+'.ps' ; change the name of the file file_move, dirname+'idl.ps', uval.nameps ENDIF spawn, '\gzip ' + uval.nameps ENDIF ; return end ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ pro printps, psfilename ; ; this is working only with unix/linux/osX machines thisOS = strupcase(strmid(!version.os_family, 0, 3)) CASE thisOS OF 'MAC':return 'WIN':return ELSE: ENDCASE ;------------------------------------------------------------ ; include commons @cm_4ps IF NOT keyword_set(key_forgetold) THEN BEGIN @updatenew ENDIF ;------------------------------------------------------------ ; we get the name of the latest created postscript. ;------------------------------------------------------------ psdir = isadirectory(psdir, title = 'Select psdir') CASE N_PARAMS() OF 0: BEGIN nameps = file_search(psdir+'*.ps', /test_regular, /nosort) IF nameps[0] EQ '' THEN BEGIN ras = report('no postsrcipt file (ending with .ps) found in : ' + psdir) RETURN ENDIF dates = (file_info(nameps)).mtime lastdate = (reverse(sort(temporary(dates))))[0] nameps = nameps[lastdate] END 1: nameps = psfilename ELSE: BEGIN ras = report('printps accept only one element: psfilename') RETURN END ENDCASE ;------------------------------------------------------------ ; we check if the file is exist in psdir. if necessary we complete ; its name with .ps and/or ,gz ;------------------------------------------------------------ nameps = find(nameps+'{.ps,}{.gz,}', iodir = psdir, /nopro) IF nameps EQ 'NOT FOUND' THEN BEGIN ng = report('file '+nameps+'[.ps][.gz] does not exist ') return ENDIF gzipped = strpos(nameps, '.gz') ; if the file is gzipped we call gunzip et change its name IF gzipped NE -1 THEN BEGIN spawn, '\gunzip ' + nameps nameps = strmid(nameps, 0, gzipped) endif ;------------------------------------------------------------ ; build the widget ;------------------------------------------------------------ base = widget_base(/row, title = 'Postscript file: ' $ + file_basename(nameps)) ; ps viewers grouped button psviewers = ['no psviewers found'] IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $ psviewers = [psviewers, 'Ghostview'] IF file_which(getenv('PATH'), 'gs') NE '' THEN $ psviewers = [psviewers, 'Ghostscript'] IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $ psviewers = [psviewers, 'Kghostview'] ; if at least one of viewer was found we define these buttons IF n_elements(psviewers) GT 1 THEN BEGIN psviewers = psviewers[1:*] notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $ , uvalue = {name:'visualize', nameps:nameps} $ , /column, /return_name) ENDIF ; printers list grouped buttons ; are the common variables printer_human_names and printer_human_names ; defined in a proper way? CASE 1 OF n_elements(printer_human_names) eq 0: $ noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple) n_elements(printer_human_names) NE n_elements(printer_machine_names): $ noting = report('the cm_4ps variables printer_human_names and !Cprinter_machine_names do not have the same number of arguments... !CWe could not propose any printer', /simple) printer_human_names[0] EQ '': ELSE:notused = $ cw_bgroup(base, printer_human_names, /frame, /column $ , label_top = 'Select printer' $ , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1}) ENDCASE ; 'archive ps' button, can be created only if archive_ps ne 0 IF keyword_set(archive_ps) THEN $ notused = widget_button(base, value = 'archive ps' $ , uvalue = {name:'archive', nameps:nameps $ , gzip:gzipped NE -1}) ; quit button notused = widget_button(base, value = 'quit' $ , uvalue = {name:'quit', nameps:nameps $ , gzip:gzipped NE -1}) ;------------------------------------------------------------ widget_control, base, /realize ;------------------------------------------------------------ xmanager, 'printps', base, /no_block ;------------------------------------------------------------ return end