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

Last change on this file since 296 was 296, checked in by pinsard, 17 years ago

typo

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