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

Last change on this file since 121 was 121, checked in by pinsard, 18 years ago

correction of some *.pro using aspell list; introduction of default idldoc syntax

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