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

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

some improvements and corrections in some .pro file according to
aspell and idldoc log file

  • 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 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 originally 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 postscript?', /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
189; postscript visualisation/archiving/printing
190;
191; @param psfilename {in}{optional} the name of the postscript file we want to
192;           visualize and/or print and/or archive. It can also refer
193;           to a gzipped postscript file. If needed, this name will
194;           be completed by .ps and/or .gz
195;
196; @uses cm_4ps
197;
198; @examples
199; IDL> printps
200;
201; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
202;                       21/12/98
203;                       25/8/19999 utilisation des widgets
204;                       8/9/1999 utilisation de cw_bgroup
205; June 2005: Sebastien Masson: cleaning, English version with new commons
206;
207; @version $Id$
208;
209;-
210;------------------------------------------------------------
211;------------------------------------------------------------
212PRO printps, psfilename
213;
214; this is working only with unix/linux/osX machines
215;
216  compile_opt idl2, strictarrsubs
217;
218  thisOS = strupcase(strmid(!version.os_family, 0, 3))
219  CASE thisOS OF
220    'MAC':return
221    'WIN':return
222    ELSE:
223  ENDCASE
224;------------------------------------------------------------
225; include commons
226@cm_4ps
227  IF NOT keyword_set(key_forgetold) THEN BEGIN
228@updatenew
229  ENDIF
230;------------------------------------------------------------
231; we get the name of the latest created postscript.
232;------------------------------------------------------------
233  psdir = isadirectory(psdir, title = 'Select psdir')
234  CASE N_PARAMS() OF
235    0: BEGIN
236      nameps = file_search(psdir+'*.ps', /test_regular, /nosort)
237      IF nameps[0] EQ '' THEN BEGIN
238        ras = report('no postsrcipt file (ending with .ps) found in : ' + psdir)
239        RETURN
240      ENDIF
241      dates = (file_info(nameps)).mtime
242      lastdate = (reverse(sort(temporary(dates))))[0]
243      nameps = nameps[lastdate]
244    END
245    1: nameps = psfilename
246    ELSE: BEGIN
247      ras = report('printps accept only one element: psfilename')
248      RETURN
249    END
250  ENDCASE
251;------------------------------------------------------------
252; we check if the file is exist in psdir. if necessary we complete
253; its name with .ps and/or ,gz
254;------------------------------------------------------------
255  nameps = find(nameps+'{.ps,}{.gz,}', iodir = psdir, /nopro)
256  IF nameps EQ 'NOT FOUND' THEN BEGIN
257    ng = report('file '+nameps+'[.ps][.gz] does not exist ')
258    return
259  ENDIF
260  gzipped = strpos(nameps, '.gz')
261; if the file is gzipped we call gunzip et change its name
262  IF gzipped NE -1 THEN BEGIN
263    spawn, '\gunzip ' + nameps
264    nameps = strmid(nameps, 0, gzipped)
265  endif
266;------------------------------------------------------------
267; build the widget
268;------------------------------------------------------------
269  base = widget_base(/row, title = 'Postscript file: ' $
270                     + file_basename(nameps))
271; ps viewers grouped button
272  psviewers = ['no psviewers found']
273  IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $
274    psviewers = [psviewers, 'Ghostview']
275  IF file_which(getenv('PATH'), 'gs') NE '' THEN $
276    psviewers = [psviewers, 'Ghostscript']
277  IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $
278    psviewers = [psviewers, 'Kghostview']
279; if at least one of viewer was found we define these buttons
280  IF n_elements(psviewers) GT 1 THEN BEGIN
281    psviewers = psviewers[1:*]
282    notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $
283                        , uvalue = {name:'visualize', nameps:nameps} $
284                        , /column, /return_name)
285  ENDIF
286; printers list grouped buttons
287; are the common variables printer_human_names and printer_human_names
288; defined in a proper way?
289  CASE 1 OF
290    n_elements(printer_human_names) eq 0: $
291      noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple)
292    n_elements(printer_human_names) NE n_elements(printer_machine_names): $
293      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)
294    printer_human_names[0] EQ '':
295    ELSE:notused = $
296      cw_bgroup(base, printer_human_names, /frame, /column $
297                , label_top = 'Select printer' $
298                , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1})
299  ENDCASE
300; 'archive ps' button, can be created only if archive_ps ne 0
301  IF keyword_set(archive_ps) THEN $
302    notused = widget_button(base, value = 'archive ps' $
303                            , uvalue = {name:'archive', nameps:nameps $
304                                        , gzip:gzipped NE -1})
305; quit button
306  notused = widget_button(base, value = 'quit' $
307                          , uvalue = {name:'quit', nameps:nameps $
308                                      , gzip:gzipped NE -1})
309;------------------------------------------------------------
310  widget_control, base, /realize
311;------------------------------------------------------------
312  xmanager, 'printps', base, /no_block
313;------------------------------------------------------------
314  return
315end
Note: See TracBrowser for help on using the repository browser.