source: trunk/SRC/Postscript/printps.pro @ 378

Last change on this file since 378 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:keywords set to Id
File size: 11.9 KB
RevLine 
[16]1;+
2;
[118]3; @file_comments
4; - archiving possibilities -
[16]5;
6; if archive_ps (common variable of cm_4ps) ne 0 then the postscript
7; can be saved for archiving if it is printed or if the button
8; "archive ps" is pressed. if it is printed and archive_ps = 1 then
9; the archiving is done automatically whereas we ask if the postscript
10; file must be archived or not.
[136]11; If the postscript name is "idl.ps" (default name) then this name will
[16]12; be changed to number.ps (number automatically found to be 1 larger
13; that any of the existing ps file).
14;
[223]15; @categories
[157]16; Postscripts
[16]17;
[118]18; @param event
19;
[104]20; @restrictions
21;
[16]22; 1) this is working only with unix/linux/osX machines
23;
24; 2) definition of the printing command
25;
26; the printing command is defined by the common variable "print_command"
[121]27; in cm_4ps. This command must be defined/build in a way that it the
[16]28; instruction:
29;     print_command[i]+printer_machine_names[i]+' '+file.ps
30; or
31;     print_command+printer_machine_names[i]+' '+file.ps
32; is working. default definition is '\lpr -P'
33;
34;
[230]35; @history
36; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[16]37;                       21/12/98
38;                       25/8/19999 utilisation des widgets
39;                       8/9/1999 utilisation de cw_bgroup
[136]40; June 2005: Sebastien Masson: cleaning, English version with new commons
[118]41;
[230]42; @version
43; $Id$
[118]44;
[16]45;-
46PRO printps_event, event
[114]47;
48  compile_opt idl2, strictarrsubs
49;
[16]50@cm_4ps
51  IF NOT keyword_set(key_forgetold) THEN BEGIN
52@updatenew
53  ENDIF
54;------------------------------------------------------------
55; What kind of event do we have ?
56  widget_control, event.id, get_uvalue = uval
57; case on the event
58  CASE uval.name OF
59;------------------------------------------------------------
[118]60; visualize case : postscript visualization
[16]61;------------------------------------------------------------
[118]62    'visualize':BEGIN
[16]63; paper orientation
64      if key_portrait EQ 1 then ori = 'portrait' ELSE ori = 'seascape'
65; paper format
66      CASE round(10*(total(page_size))) OF
67        round(10*(83.9611 + 118.816)) : papsize = 'a0'
68        round(10*(59.4078 + 83.9611)) : papsize = 'a1'
69        round(10*(41.9806 + 59.4078)) : papsize = 'a2'
70        round(10*(29.7039 + 41.9806)) : papsize = 'a3'
71        round(10*(20.9903 + 29.7039)) : papsize = 'a4'
72        round(10*(14.8519 + 20.9903)) : papsize = 'a5'
73        round(10*(10.4775 + 14.8519)) : papsize = 'a6'
74        round(10*(7.40833 + 10.4775)) : papsize = 'a7'
75        round(10*(5.22111 + 7.40833)) : papsize = 'a8'
76        round(10*(3.70417 + 5.22111)) : papsize = 'a9'
77        round(10*(2.61056 + 3.70417)) : papsize = 'a10'
78        round(10*(100.048 + 141.393)) : papsize = 'b0'
79        round(10*(70.6967 + 100.048)) : papsize = 'b1'
80        round(10*(50.0239 + 70.6967)) : papsize = 'b2'
81        round(10*(35.3483 + 50.0239)) : papsize = 'b3'
82        round(10*(25.0119 + 35.3483)) : papsize = 'b4'
83        round(10*(17.6742 + 25.0119)) : papsize = 'b5'
84        round(10*(22.86 + 30.48)) : papsize = 'archA'
85        round(10*(30.48 + 45.72)) : papsize = 'archB'
86        round(10*(45.72 + 60.96)) : papsize = 'archC'
87        round(10*(60.96 + 91.44)) : papsize = 'archD'
88        round(10*(91.44 + 121.92)) : papsize = 'archE'
89        round(10*(21.59 + 33.02)) : papsize = 'flsa'
90        round(10*(21.59 + 33.02)) : papsize = 'flse'
91        round(10*(13.97 + 21.59)) : papsize = 'halfletter'
92        round(10*(19.05 + 25.4)) : papsize = 'note'
93        round(10*(21.59 + 27.94)) : papsize = 'letter'
94        round(10*(21.59 + 35.56)) : papsize = 'legal'
95        round(10*(27.94 + 43.18)) : papsize = '11x17'
96        round(10*(43.18 + 27.94)) : papsize = 'ledger'
97        ELSE:papsize = 'a4'
[118]98      ENDCASE
[16]99; call the viewers
100      CASE event.value OF
[220]101        'GNU Ghostview':cmd = '\gv --media='+papsize+' --orientation='+ori+' '+uval.nameps
102        'Gnome Ghostview':cmd = '\ggv '+uval.nameps
103        'Ghostview':cmd = '\ghostview -'+papsize+' -quiet -'+ori+' '+uval.nameps
104        'Ghostscript':cmd = '\gs -sPAPERSIZE='+papsize+' -q '+uval.nameps
105        'Kghostview':cmd = '\kghostview '+uval.nameps
[16]106      ENDCASE
[220]107      spawn, cmd
[118]108      return
[16]109    END
110;------------------------------------------------------------
111; print case: print and archive the file if needed
112;------------------------------------------------------------
[118]113    'print':BEGIN
[16]114; printer selection
115      printer = printer_machine_names[event.value]
116; print
117      CASE n_elements(print_command) OF
118        0:ptcmd = '\lpr -P'
119        1:ptcmd = print_command[0]
120        n_elements(printer_machine_names):ptcmd = print_command[event.value]
121        ELSE:BEGIN
122          ng = report('bad definition of print_command, common variable of cm_4ps. !C we did not print the postscript file', /simple)
123          return
124        END
125      ENDCASE
126      spawn, ptcmd + printer + ' ' + uval.nameps
127; ; printing informations...
128;       spawn, '\lpq -P'+imprimante+' -l', info
129; ; display them
130;       xdisplayfile, 'nothing', text = info $
131;                     , title = 'Printing Info '+file_basename(uval.nameps) $
132;                     , height = n_elements(info) <  24
133    END
134    ELSE:
[118]135  ENDCASE
[16]136; we destroy the widget
[118]137  widget_control, event.top, /destroy
[136]138; if the file was originally gzipped, then we re-gzip it and exit
[16]139  IF uval.gzip THEN BEGIN
140    spawn, '\gzip ' + uval.nameps
141    return
142  ENDIF
143;------------------------------------------------------------
144; archiving...
145;------------------------------------------------------------
146  IF (uval.name EQ 'print' OR uval.name EQ 'archive') $
147    AND keyword_set(archive_ps) THEN BEGIN
148    IF archive_ps NE 1 AND uval.name EQ 'print' then begin
[136]149      wesave = report('Shall we archive the postscript?', /default_no, /question)
[16]150      IF wesave EQ 0 THEN RETURN
151    ENDIF
152; if the name of the postscript is idl.ps then we change it
153    IF file_basename(uval.nameps) EQ 'idl.ps' then BEGIN
154; get the name of all the *.ps or *.ps.gz files available in psdir
155       allps = file_search(psdir+'*[.ps|.ps.gz|.pdf]', /test_regular, /nosort)
156       allps = file_basename(file_basename(allps,'.gz'),'.ps')
157       allps = file_basename(allps,'.pdf')
158; find which of these names corresponds to numbers...
[136]159; get ASCII codes of the names
[16]160       testnumb = byte(allps)
161; longest name
162       maxstrlen = (size(testnumb, /dimensions))[0]
[136]163; ASCII codes can be 0 or between byte('0') and byte('9')
[16]164       testnumb = testnumb EQ 0 OR $
165                  (testnumb GE (byte('0'))[0] AND testnumb LE (byte('9'))[0])
166       testnumb = where(total(testnumb, 1) EQ maxstrlen, count)
167       IF count NE 0 THEN BEGIN
168; get the largest number
169         psnumber = fix(allps[testnumb])
170         psnumber = (psnumber[reverse(sort(psnumber))])[0] + 1
171       ENDIF ELSE psnumber = 0
172; update uval.nameps
173      dirname = file_dirname(uval.nameps, /mark_directory)
174      uval.nameps = dirname+strtrim(psnumber, 2)+'.ps'
175; change the name of the file
176      file_move, dirname+'idl.ps', uval.nameps
177    ENDIF
178    spawn, '\gzip ' + uval.nameps
179  ENDIF
[118]180;
[16]181  return
182end
183;------------------------------------------------------------
184;------------------------------------------------------------
[104]185;+
[129]186; @file_comments
187; postscript visualisation/archiving/printing
[104]188;
[223]189; @categories
[157]190; Postscripts
[104]191;
[223]192; @param psfilename {in}{optional}
[157]193; The name of the postscript file we want to
194; visualize and/or print and/or archive. It can also refer
195; to a gzipped postscript file. If needed, this name will
[230]196; be completed by .ps and/or .gz.
[157]197;
[230]198; @uses
[371]199; <pro>cm_4ps</pro>
[104]200;
201; @examples
202;
[371]203;   IDL> printps
204;
[230]205; @history
206; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[104]207;                       21/12/98
208;                       25/8/19999 utilisation des widgets
209;                       8/9/1999 utilisation de cw_bgroup
[136]210; June 2005: Sebastien Masson: cleaning, English version with new commons
[118]211;
[230]212; @version
213; $Id$
[118]214;
[104]215;-
216PRO printps, psfilename
[16]217;
218; this is working only with unix/linux/osX machines
[114]219;
220  compile_opt idl2, strictarrsubs
221;
[16]222  thisOS = strupcase(strmid(!version.os_family, 0, 3))
[118]223  CASE thisOS OF
[16]224    'MAC':return
225    'WIN':return
226    ELSE:
227  ENDCASE
[231]228;
[16]229@cm_4ps
230  IF NOT keyword_set(key_forgetold) THEN BEGIN
231@updatenew
232  ENDIF
233;------------------------------------------------------------
234; we get the name of the latest created postscript.
235;------------------------------------------------------------
236  psdir = isadirectory(psdir, title = 'Select psdir')
237  CASE N_PARAMS() OF
238    0: BEGIN
239      nameps = file_search(psdir+'*.ps', /test_regular, /nosort)
240      IF nameps[0] EQ '' THEN BEGIN
[223]241        ras = report('no postscript file (ending with .ps) found in : ' + psdir)
[16]242        RETURN
243      ENDIF
244      dates = (file_info(nameps)).mtime
245      lastdate = (reverse(sort(temporary(dates))))[0]
246      nameps = nameps[lastdate]
247    END
248    1: nameps = psfilename
[118]249    ELSE: BEGIN
[16]250      ras = report('printps accept only one element: psfilename')
251      RETURN
[118]252    END
253  ENDCASE
[16]254;------------------------------------------------------------
255; we check if the file is exist in psdir. if necessary we complete
256; its name with .ps and/or ,gz
257;------------------------------------------------------------
258  nameps = find(nameps+'{.ps,}{.gz,}', iodir = psdir, /nopro)
[118]259  IF nameps EQ 'NOT FOUND' THEN BEGIN
[16]260    ng = report('file '+nameps+'[.ps][.gz] does not exist ')
261    return
[118]262  ENDIF
[16]263  gzipped = strpos(nameps, '.gz')
[296]264; if the file is gzipped we call gunzip and change its name
[16]265  IF gzipped NE -1 THEN BEGIN
266    spawn, '\gunzip ' + nameps
267    nameps = strmid(nameps, 0, gzipped)
268  endif
269;------------------------------------------------------------
270; build the widget
271;------------------------------------------------------------
272  base = widget_base(/row, title = 'Postscript file: ' $
273                     + file_basename(nameps))
274; ps viewers grouped button
275  psviewers = ['no psviewers found']
[220]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']
[16]280  IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $
[118]281    psviewers = [psviewers, 'Ghostview']
[16]282  IF file_which(getenv('PATH'), 'gs') NE '' THEN $
[118]283    psviewers = [psviewers, 'Ghostscript']
[16]284  IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $
[118]285    psviewers = [psviewers, 'Kghostview']
[16]286; if at least one of viewer was found we define these buttons
[118]287  IF n_elements(psviewers) GT 1 THEN BEGIN
[16]288    psviewers = psviewers[1:*]
289    notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $
290                        , uvalue = {name:'visualize', nameps:nameps} $
291                        , /column, /return_name)
[118]292  ENDIF
[16]293; printers list grouped buttons
294; are the common variables printer_human_names and printer_human_names
295; 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})
306  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;------------------------------------------------------------
321  return
322end
Note: See TracBrowser for help on using the repository browser.