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

Last change on this file since 219 was 219, checked in by smasson, 17 years ago

get back to changeset:217

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