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

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

start to modify headers of Postscript *.pro files for better idldoc output + change the title of idldoc output in html to SAXO Documentation

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