Changeset 380


Ignore:
Timestamp:
10/02/08 12:33:07 (16 years ago)
Author:
smasson
Message:

improve printps to be used in batch mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Postscript/printps.pro

    r371 r380  
    4444; 
    4545;- 
    46 PRO printps_event, event 
     46PRO printps_event, event, uval = uval 
    4747; 
    4848  compile_opt idl2, strictarrsubs 
     
    5454;------------------------------------------------------------ 
    5555; What kind of event do we have ? 
    56   widget_control, event.id, get_uvalue = uval 
     56  IF NOT keyword_set(uval) THEN widget_control, event.id, get_uvalue = uval 
    5757; case on the event 
    5858  CASE uval.name OF 
     
    135135  ENDCASE 
    136136; we destroy the widget 
    137   widget_control, event.top, /destroy 
     137  IF n_tags(event) GT 1 THEN widget_control, event.top, /destroy 
    138138; if the file was originally gzipped, then we re-gzip it and exit 
    139139  IF uval.gzip THEN BEGIN 
     
    196196; be completed by .ps and/or .gz. 
    197197; 
     198; @keyword ARCHIVE {default=0} {type=integer 0 or 1} 
     199; activate to bypass the widget and directly archive the postcript 
     200; (useful to use printps in batch mode) 
     201; 
     202; @keyword DIRECTPRINT {default=not defined} {type=string} 
     203; bypass the widget and directly define the printer that must be used 
     204; to print the postcript file. DIRECTPRINT must correspond to one of 
     205; the names defined in the comoon variables printer_machine_names or 
     206; printer_human_names. useful to use printps in batch mode  
     207; 
    198208; @uses 
    199209; <pro>cm_4ps</pro> 
     
    214224; 
    215225;- 
    216 PRO printps, psfilename 
     226PRO printps, psfilename, ARCHIVE = archive, DIRECTPRINT = directprint 
    217227; 
    218228; this is working only with unix/linux/osX machines 
     
    263273  gzipped = strpos(nameps, '.gz') 
    264274; if the file is gzipped we call gunzip and change its name 
    265   IF gzipped NE -1 THEN BEGIN 
     275  IF gzipped NE -1 AND NOT keyword_set(archive) THEN BEGIN 
    266276    spawn, '\gunzip ' + nameps 
    267277    nameps = strmid(nameps, 0, gzipped) 
    268   endif 
     278  ENDIF 
     279;------------------------------------------------------------ 
     280; what should we do? 
     281;------------------------------------------------------------ 
     282  CASE 1 OF 
     283;------------------------------------------------------------ 
     284; direct archiving... 
     285;------------------------------------------------------------ 
     286    keyword_set(archive):IF gzipped EQ -1 THEN printps_event, uval = {name:'archive', nameps:nameps, gzip:gzipped NE -1} 
    269287;------------------------------------------------------------ 
    270288; build the widget 
    271289;------------------------------------------------------------ 
    272   base = widget_base(/row, title = 'Postscript file: ' $ 
    273                      + file_basename(nameps)) 
     290    keyword_set(directprint): BEGIN  
     291; check if directprint is well defined 
     292      printnumb = (where(strlowcase(printer_machine_names) EQ strlowcase(directprint)))[0] 
     293      IF printnumb EQ -1 THEN BEGIN 
     294        printnumb = (where(strlowcase(printer_human_names) EQ strlowcase(directprint)))[0] 
     295        IF printnumb EQ -1 THEN BEGIN 
     296          dummy = report('directprint does not correspond to any printer defined in printer_machine_names or printer_human_names common variable') 
     297          return 
     298        ENDIF 
     299      ENDIF 
     300; call printps_event with predefined event and uvalue 
     301      printps_event, {value:printnumb}, uval = {name:'print', nameps:nameps, gzip:gzipped NE -1} 
     302    END 
     303;------------------------------------------------------------ 
     304; build the widget 
     305;------------------------------------------------------------ 
     306    ELSE:BEGIN  
     307      base = widget_base(/row, title = 'Postscript file: ' $ 
     308                         + file_basename(nameps)) 
    274309; ps viewers grouped button 
    275   psviewers = ['no psviewers found'] 
    276   IF file_which(getenv('PATH'), 'gv') NE '' THEN $ 
    277     psviewers = [psviewers, 'GNU Ghostview'] 
    278   IF file_which(getenv('PATH'), 'ggv') NE '' THEN $ 
    279     psviewers = [psviewers, 'Gnome Ghostview'] 
    280   IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $ 
    281     psviewers = [psviewers, 'Ghostview'] 
    282   IF file_which(getenv('PATH'), 'gs') NE '' THEN $ 
    283     psviewers = [psviewers, 'Ghostscript'] 
    284   IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $ 
    285     psviewers = [psviewers, 'Kghostview'] 
     310      psviewers = ['no psviewers found'] 
     311      IF file_which(getenv('PATH'), 'gv') NE '' THEN $ 
     312         psviewers = [psviewers, 'GNU Ghostview'] 
     313      IF file_which(getenv('PATH'), 'ggv') NE '' THEN $ 
     314         psviewers = [psviewers, 'Gnome Ghostview'] 
     315      IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $ 
     316         psviewers = [psviewers, 'Ghostview'] 
     317      IF file_which(getenv('PATH'), 'gs') NE '' THEN $ 
     318         psviewers = [psviewers, 'Ghostscript'] 
     319      IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $ 
     320         psviewers = [psviewers, 'Kghostview'] 
    286321; if at least one of viewer was found we define these buttons 
    287   IF n_elements(psviewers) GT 1 THEN BEGIN 
    288     psviewers = psviewers[1:*] 
    289     notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $ 
    290                         , uvalue = {name:'visualize', nameps:nameps} $ 
    291                         , /column, /return_name) 
    292   ENDIF 
     322      IF n_elements(psviewers) GT 1 THEN BEGIN 
     323        psviewers = psviewers[1:*] 
     324        notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $ 
     325                            , uvalue = {name:'visualize', nameps:nameps} $ 
     326                            , /column, /return_name) 
     327      ENDIF 
    293328; printers list grouped buttons 
    294329; are the common variables printer_human_names and printer_human_names 
    295330; defined in a proper way? 
    296   CASE 1 OF 
    297     n_elements(printer_human_names) eq 0: $ 
    298       noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple) 
    299     n_elements(printer_human_names) NE n_elements(printer_machine_names): $ 
    300       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) 
    301     printer_human_names[0] EQ '': 
    302     ELSE:notused = $ 
    303       cw_bgroup(base, printer_human_names, /frame, /column $ 
    304                 , label_top = 'Select printer' $ 
    305                 , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1}) 
     331      CASE 1 OF 
     332        n_elements(printer_human_names) eq 0: $ 
     333           noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple) 
     334        n_elements(printer_human_names) NE n_elements(printer_machine_names): $ 
     335           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) 
     336        printer_human_names[0] EQ '': 
     337        ELSE:notused = $ 
     338           cw_bgroup(base, printer_human_names, /frame, /column $ 
     339                     , label_top = 'Select printer' $ 
     340                     , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1}) 
     341      ENDCASE 
     342; 'archive ps' button, can be created only if archive_ps ne 0 
     343      IF keyword_set(archive_ps) THEN $ 
     344         notused = widget_button(base, value = 'archive ps' $ 
     345                                 , uvalue = {name:'archive', nameps:nameps $ 
     346                                             , gzip:gzipped NE -1}) 
     347; quit button 
     348      notused = widget_button(base, value = 'quit' $ 
     349                              , uvalue = {name:'quit', nameps:nameps $ 
     350                                          , gzip:gzipped NE -1}) 
     351;------------------------------------------------------------ 
     352      widget_control, base, /realize 
     353;------------------------------------------------------------ 
     354      xmanager, 'printps', base, /no_block 
     355;------------------------------------------------------------ 
     356    END 
    306357  ENDCASE 
    307 ; 'archive ps' button, can be created only if archive_ps ne 0 
    308   IF keyword_set(archive_ps) THEN $ 
    309     notused = widget_button(base, value = 'archive ps' $ 
    310                             , uvalue = {name:'archive', nameps:nameps $ 
    311                                         , gzip:gzipped NE -1}) 
    312 ; quit button 
    313   notused = widget_button(base, value = 'quit' $ 
    314                           , uvalue = {name:'quit', nameps:nameps $ 
    315                                       , gzip:gzipped NE -1}) 
    316 ;------------------------------------------------------------ 
    317   widget_control, base, /realize 
    318 ;------------------------------------------------------------ 
    319   xmanager, 'printps', base, /no_block 
    320 ;------------------------------------------------------------ 
     358 
     359 
    321360  return 
    322361end 
Note: See TracChangeset for help on using the changeset viewer.