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