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