| 1 |
#!/usr/bin/env python |
| 2 |
#PPD to XML translator/generator |
| 3 |
#Written by David Crosby |
| 4 |
version='0.21' |
| 5 |
|
| 6 |
import sys |
| 7 |
import os |
| 8 |
import time |
| 9 |
import datetime |
| 10 |
import pygtk |
| 11 |
pygtk.require('2.0') |
| 12 |
import gtk |
| 13 |
from xml.dom import minidom |
| 14 |
|
| 15 |
class PPDtoXML: |
| 16 |
__manufacturerlist__=[ |
| 17 |
'Alps', |
| 18 |
'Anitech', |
| 19 |
'Apollo', |
| 20 |
'Apple', |
| 21 |
'Avery', |
| 22 |
'Benq', |
| 23 |
'Brother', |
| 24 |
'Cltoh', |
| 25 |
'CalComp', |
| 26 |
'Canon', |
| 27 |
'Casio', |
| 28 |
'Citizen', |
| 29 |
'Compaq', |
| 30 |
'DEC', |
| 31 |
'Dell', |
| 32 |
'Dymo', |
| 33 |
'Dymo-CoStar', |
| 34 |
'Epson', |
| 35 |
'Extech', |
| 36 |
'FenixImvico', |
| 37 |
'FujiXerox', |
| 38 |
'Fujifilm', |
| 39 |
'Fujitsu', |
| 40 |
'GCCPrinters', |
| 41 |
'Gestetner', |
| 42 |
'Heidelberg', |
| 43 |
'Hitachi', |
| 44 |
'HP', |
| 45 |
'IBM', |
| 46 |
'Imagen', |
| 47 |
'Imagistics', |
| 48 |
'InfoPrint', |
| 49 |
'Infotec', |
| 50 |
'Kodak', |
| 51 |
'KONICA MINOLTA', |
| 52 |
'Kyocera', |
| 53 |
'Lanier', |
| 54 |
'LaserMaster', |
| 55 |
'Lexmark', |
| 56 |
'Minolta', |
| 57 |
'Minolta QMS', |
| 58 |
'Mitsubishi', |
| 59 |
'NEC', |
| 60 |
'NRG', |
| 61 |
'Oce', |
| 62 |
'Oki', |
| 63 |
'Olivetti', |
| 64 |
'Olympus', |
| 65 |
'Panasonic', |
| 66 |
'PCPI', |
| 67 |
'Pentax', |
| 68 |
'Printrex', |
| 69 |
'QMS', |
| 70 |
'Raven', |
| 71 |
'Ricoh', |
| 72 |
'RisoKagaku', |
| 73 |
'Samsung', |
| 74 |
'Savin', |
| 75 |
'Seiko', |
| 76 |
'Sharp', |
| 77 |
'SiPix', |
| 78 |
'Siemens', |
| 79 |
'Sony', |
| 80 |
'Star', |
| 81 |
'Tally', |
| 82 |
'Tektronix', |
| 83 |
'Texas Instruments', |
| 84 |
'TohokuRicoh', |
| 85 |
'Toshiba', |
| 86 |
'Xante' |
| 87 |
'Xerox'] |
| 88 |
|
| 89 |
__driverlist__=[ |
| 90 |
'ap3250', |
| 91 |
'appledmp', |
| 92 |
'bj10', |
| 93 |
'bj10e', |
| 94 |
'bj10v', |
| 95 |
'bj10vh', |
| 96 |
'bj200', |
| 97 |
'bj8gc12f.upp', |
| 98 |
'bj8hg12f.upp', |
| 99 |
'bj8oh06n.upp', |
| 100 |
'bj8pa06n.upp', |
| 101 |
'bj8pp12f.upp', |
| 102 |
'bj8ts06n.upp', |
| 103 |
'bjc250gs', |
| 104 |
'bjc600', |
| 105 |
'bjc6000a1.upp', |
| 106 |
'bjc6000b1.upp', |
| 107 |
'bjc610a0.upp', |
| 108 |
'bjc610a1.upp', |
| 109 |
'bjc610a2.upp', |
| 110 |
'bjc610a3.upp', |
| 111 |
'bjc610a4.upp', |
| 112 |
'bjc610a5.upp', |
| 113 |
'bjc610a6.upp', |
| 114 |
'bjc610a7.upp', |
| 115 |
'bjc610a8.upp', |
| 116 |
'bjc610b1.upp', |
| 117 |
'bjc610b2.upp', |
| 118 |
'bjc610b3.upp', |
| 119 |
'bjc610b4.upp', |
| 120 |
'bjc610b6.upp', |
| 121 |
'bjc610b7.upp', |
| 122 |
'bjc610b8.upp', |
| 123 |
'bjc800', |
| 124 |
'bjc800j', |
| 125 |
'bjc880j', |
| 126 |
'c2050', |
| 127 |
'c2070', |
| 128 |
'cZ11', |
| 129 |
'cZ11somsom', |
| 130 |
'capt', |
| 131 |
'cdj1600', |
| 132 |
'cdj500', |
| 133 |
'cdj550', |
| 134 |
'cdj550.upp', |
| 135 |
'cdj670', |
| 136 |
'cdj850', |
| 137 |
'cdj880', |
| 138 |
'cdj890', |
| 139 |
'cdj970', |
| 140 |
'chp2200', |
| 141 |
'cjet', |
| 142 |
'cljet5', |
| 143 |
'cljet5c', |
| 144 |
'cp50', |
| 145 |
'declj250', |
| 146 |
'deskjet', |
| 147 |
'dj505j', |
| 148 |
'djet500', |
| 149 |
'dnj650c', |
| 150 |
'drv_x125', |
| 151 |
'drv_z42', |
| 152 |
'eplaser', |
| 153 |
'ep-laser', |
| 154 |
'eps9high', |
| 155 |
'eps9mid', |
| 156 |
'epson', |
| 157 |
'epsonc', |
| 158 |
'epsonepl', |
| 159 |
'escpage', |
| 160 |
'fmlbp', |
| 161 |
'fmpr', |
| 162 |
'foo2hp', |
| 163 |
'foo2kyo', |
| 164 |
'foo2lava', |
| 165 |
'foo2qpdl', |
| 166 |
'foo2xqx', |
| 167 |
'foo2zjs', |
| 168 |
'gdi', |
| 169 |
'gimp-print', |
| 170 |
'gutenprint', |
| 171 |
'gutenprint52', |
| 172 |
'hl1250', |
| 173 |
'hl7x0', |
| 174 |
'hpdj', |
| 175 |
'hpijs-pcl3', |
| 176 |
'hpijs-pcl5c', |
| 177 |
'hpijs-pcl5e', |
| 178 |
'hplip', |
| 179 |
'ibmpro', |
| 180 |
'imagen', |
| 181 |
'iwhi', |
| 182 |
'iwlo', |
| 183 |
'iwlq', |
| 184 |
'jetp3852', |
| 185 |
'jj100', |
| 186 |
'la50', |
| 187 |
'la70', |
| 188 |
'la75', |
| 189 |
'la75plus', |
| 190 |
'laserjet', |
| 191 |
'lbp310', |
| 192 |
'lbp320', |
| 193 |
'lbp660', |
| 194 |
'lbp8', |
| 195 |
'lex5700', |
| 196 |
'lex7000', |
| 197 |
'lips2p', |
| 198 |
'lips3', |
| 199 |
'lips4', |
| 200 |
'lips4v', |
| 201 |
'lj250', |
| 202 |
'lj4dith', |
| 203 |
'lj4dithp', |
| 204 |
'lj5gray', |
| 205 |
'lj5mono', |
| 206 |
'ljet2p', |
| 207 |
'ljet3', |
| 208 |
'ljet3d', |
| 209 |
'ljet4', |
| 210 |
'ljet4d', |
| 211 |
'ljetplus', |
| 212 |
'lm1100', |
| 213 |
'ln03', |
| 214 |
'lp2000', |
| 215 |
'lp2563', |
| 216 |
'lp8000', |
| 217 |
'lpstyl', |
| 218 |
'lq850', |
| 219 |
'lx5000', |
| 220 |
'lxm3200', |
| 221 |
'lxm3200-tweaked', |
| 222 |
'lxm3200x', |
| 223 |
'lxm3200m', |
| 224 |
'lxm3200p', |
| 225 |
'lxm5700m', |
| 226 |
'lxx74', |
| 227 |
'lz11-V2', |
| 228 |
'm2300w', |
| 229 |
'm2400w', |
| 230 |
'm8510', |
| 231 |
'mdx1Mono', |
| 232 |
'md2k', |
| 233 |
'md50Eco', |
| 234 |
'md50Mono', |
| 235 |
'md5k', |
| 236 |
'min12xxw', |
| 237 |
'mj500c', |
| 238 |
'mj6000c', |
| 239 |
'mj700v2c', |
| 240 |
'mj8000c', |
| 241 |
'ml600', |
| 242 |
'ml85p', |
| 243 |
'necp2x.upp', |
| 244 |
'necp2x6.upp', |
| 245 |
'necp6', |
| 246 |
'npdl', |
| 247 |
'nwp533', |
| 248 |
'oce9050', |
| 249 |
'oki182', |
| 250 |
'oki4drv', |
| 251 |
'oki4w', |
| 252 |
'okiibm', |
| 253 |
'omni', |
| 254 |
'paintjet', |
| 255 |
'pbm2l2030', |
| 256 |
'pbm2l7k', |
| 257 |
'pbm2lwxl', |
| 258 |
'pbm2ppa', |
| 259 |
'pbmtozjs', |
| 260 |
'pcl3', |
| 261 |
'pegg', |
| 262 |
'pentaxpj', |
| 263 |
'picty180', |
| 264 |
'pj', |
| 265 |
'pjetxl', |
| 266 |
'pjxl', |
| 267 |
'pjxl300', |
| 268 |
'PM760p.upp', |
| 269 |
'PM760pl.upp', |
| 270 |
'PM820p.upp', |
| 271 |
'PM820pl.upp', |
| 272 |
'pnm2ppa', |
| 273 |
'Postscript', |
| 274 |
'Postscript-Brother', |
| 275 |
'Postscript-Epson', |
| 276 |
'Postscript-Gestetner', |
| 277 |
'Postscript-HP', |
| 278 |
'Postscript-InfoPrint', |
| 279 |
'Postscript-Infotec', |
| 280 |
'Postscript-KONICA_MINOLTA', |
| 281 |
'Postscript-Kyocera', |
| 282 |
'Postscript-Lanier', |
| 283 |
'Postscript-NRG', |
| 284 |
'Postscript-Oce', |
| 285 |
'Postscript-Oki', |
| 286 |
'Postscript-Ricoh', |
| 287 |
'Postscript-Savin', |
| 288 |
'Postscript-Sharp', |
| 289 |
'Postscript-Toshiba', |
| 290 |
'Postscript1', |
| 291 |
'Postscript2-Oce', |
| 292 |
'ppmtocpva', |
| 293 |
'ppmtomd', |
| 294 |
'pr150', |
| 295 |
'pr201', |
| 296 |
'ptouch', |
| 297 |
'pxl1010', |
| 298 |
'pxlcolor', |
| 299 |
'pxlcolor-Gestetner', |
| 300 |
'pxlcolor-InfoPrint', |
| 301 |
'pxlcolor-Infotex', |
| 302 |
'pxlcolor-Lanier', |
| 303 |
'pxlcolor-NRG', |
| 304 |
'pxlcolor-Ricoh', |
| 305 |
'pxlcolor-Savin', |
| 306 |
'pxldpl', |
| 307 |
'pxljr', |
| 308 |
'pxlmono', |
| 309 |
'pxlmono-Gestetner', |
| 310 |
'pxlmono-InfoPrint', |
| 311 |
'pxlmono-Infotex', |
| 312 |
'pxlmono-Lanier', |
| 313 |
'pxlmono-NRG', |
| 314 |
'pxlmono-Ricoh', |
| 315 |
'pxlmono-Savin', |
| 316 |
'r4081', |
| 317 |
'ras1.upp', |
| 318 |
'ras24.upp', |
| 319 |
'ras3.upp', |
| 320 |
'ras32.upp', |
| 321 |
'ras4.upp', |
| 322 |
'ras8m.upp', |
| 323 |
'rastertokmXXXXdl', |
| 324 |
'rpdl', |
| 325 |
's400a1.upp', |
| 326 |
's400b1.upp', |
| 327 |
'sharp.upp', |
| 328 |
'sipixa6.upp', |
| 329 |
'slap', |
| 330 |
'sparc', |
| 331 |
'splix', |
| 332 |
'st640ih.upp', |
| 333 |
'st640igh.upp', |
| 334 |
'st640p.upp', |
| 335 |
'st640pg.upp', |
| 336 |
'st640pl.upp', |
| 337 |
'st640plg.upp', |
| 338 |
'st800', |
| 339 |
'stc.upp', |
| 340 |
'stc1520h.upp', |
| 341 |
'stc2.upp', |
| 342 |
'stc2_h.upp', |
| 343 |
'stc2s_h.upp', |
| 344 |
'stc300.upp', |
| 345 |
'stc300bl.upp', |
| 346 |
'stc300bm.upp', |
| 347 |
'stc500p.upp', |
| 348 |
'stc500ph.upp', |
| 349 |
'stc600ih.upp', |
| 350 |
'stc600p.upp', |
| 351 |
'stc600pl.upp', |
| 352 |
'stc640p.upp', |
| 353 |
'Stc670p.upp', |
| 354 |
'Stc670pl.upp', |
| 355 |
'Stc680p.upp', |
| 356 |
'Stc680pl.upp', |
| 357 |
'stc740ih.upp', |
| 358 |
'stc740p.upp', |
| 359 |
'stc740il.upp', |
| 360 |
'Stc760p.upp', |
| 361 |
'Stc760pl.upp', |
| 362 |
'Stc777p.upp', |
| 363 |
'Stc777pl.upp', |
| 364 |
'stc800ih.upp', |
| 365 |
'stc800p.upp', |
| 366 |
'stc800pl.upp', |
| 367 |
'stc_h.upp', |
| 368 |
'stc_l.upp', |
| 369 |
'stcany.upp', |
| 370 |
'stcolor', |
| 371 |
'Stp720p.upp', |
| 372 |
'Stp720pl.upp', |
| 373 |
'Stp870p.upp', |
| 374 |
'Stp870pl.upp', |
| 375 |
't4693d2', |
| 376 |
't4693d4', |
| 377 |
't4693d8', |
| 378 |
'tek4696', |
| 379 |
'xes'] |
| 380 |
|
| 381 |
__mechanismlist__=[ |
| 382 |
'Mechanism', |
| 383 |
'laser', |
| 384 |
'inkjet', |
| 385 |
'led', |
| 386 |
'dotmatrix', |
| 387 |
'impact', |
| 388 |
'sublimation', |
| 389 |
'transfer'] |
| 390 |
|
| 391 |
def __init__(self): |
| 392 |
|
| 393 |
window = gtk.Window() |
| 394 |
window.connect('destroy', lambda w: gtk.main_quit()) |
| 395 |
|
| 396 |
vbox = gtk.VBox() |
| 397 |
vbox.show() |
| 398 |
|
| 399 |
make_label = gtk.Label('Make') |
| 400 |
vbox.pack_start(make_label) |
| 401 |
make_label.show() |
| 402 |
|
| 403 |
|
| 404 |
#This is for the make and model of the printer |
| 405 |
p_make = gtk.Entry() |
| 406 |
p_make.set_text('Make') |
| 407 |
p_make_dropdown = gtk.EntryCompletion() |
| 408 |
self.makelist = gtk.ListStore(str) |
| 409 |
for manufacturer in self.__manufacturerlist__: |
| 410 |
self.makelist.append([manufacturer]) |
| 411 |
p_make_dropdown.set_model(self.makelist) |
| 412 |
p_make.set_completion(p_make_dropdown) |
| 413 |
p_make_dropdown.set_text_column(0) |
| 414 |
vbox.pack_start(p_make) |
| 415 |
window.add(vbox) |
| 416 |
p_make.show() |
| 417 |
|
| 418 |
model_label = gtk.Label('Model') |
| 419 |
vbox.pack_start(model_label) |
| 420 |
model_label.show() |
| 421 |
|
| 422 |
p_model = gtk.Entry() |
| 423 |
p_model.set_text('Model') |
| 424 |
vbox.pack_start(p_model) |
| 425 |
p_model.show() |
| 426 |
|
| 427 |
#This is for selecting the printer mechanism |
| 428 |
p_mechanism_combo = gtk.combo_box_new_text() |
| 429 |
for mechanism in self.__mechanismlist__: |
| 430 |
p_mechanism_combo.append_text(mechanism) |
| 431 |
p_mechanism_combo.set_active(0) |
| 432 |
vbox.pack_start(p_mechanism_combo) |
| 433 |
p_mechanism_combo.show() |
| 434 |
|
| 435 |
hbox_dpi = gtk.HBox() |
| 436 |
vbox.add(hbox_dpi) |
| 437 |
hbox_dpi.show() |
| 438 |
|
| 439 |
#Select whether the printer is color or not |
| 440 |
p_color = gtk.CheckButton("Color") |
| 441 |
hbox_dpi.pack_start(p_color) |
| 442 |
p_color.show() |
| 443 |
|
| 444 |
separator1 = gtk.HSeparator() |
| 445 |
hbox_dpi.pack_start(separator1) |
| 446 |
separator1.show() |
| 447 |
|
| 448 |
#Select the DPI of the printer |
| 449 |
x_dpi_label = gtk.Label('X:') |
| 450 |
hbox_dpi.pack_start(x_dpi_label) |
| 451 |
x_dpi_label.show() |
| 452 |
|
| 453 |
p_x_dpi = gtk.Entry() |
| 454 |
p_x_dpi.set_width_chars(6) |
| 455 |
hbox_dpi.pack_start(p_x_dpi) |
| 456 |
p_x_dpi.show() |
| 457 |
|
| 458 |
y_dpi_label = gtk.Label('Y:') |
| 459 |
hbox_dpi.pack_start(y_dpi_label) |
| 460 |
y_dpi_label.show() |
| 461 |
|
| 462 |
p_y_dpi = gtk.Entry() |
| 463 |
p_y_dpi.set_width_chars(6) |
| 464 |
hbox_dpi.pack_start(p_y_dpi) |
| 465 |
p_y_dpi.show() |
| 466 |
|
| 467 |
#Text box to enter what consumables are used in the printer (toner/drum/cartridge/blahblahblah) |
| 468 |
consumables_label = gtk.Label('Consumables') |
| 469 |
vbox.pack_start(consumables_label) |
| 470 |
#consumables_label.show() |
| 471 |
|
| 472 |
p_consumables = gtk.Entry() |
| 473 |
vbox.pack_start(p_consumables) |
| 474 |
#p_consumables.show() |
| 475 |
|
| 476 |
#The manufacturer URL for the printer |
| 477 |
url_label = gtk.Label('Manufacturer URL') |
| 478 |
vbox.pack_start(url_label) |
| 479 |
url_label.show() |
| 480 |
|
| 481 |
p_url = gtk.Entry() |
| 482 |
vbox.pack_start(p_url) |
| 483 |
p_url.show() |
| 484 |
|
| 485 |
#LANGUAGES |
| 486 |
hbox_languages = gtk.HBox() |
| 487 |
vbox.add(hbox_languages) |
| 488 |
hbox_languages.show() |
| 489 |
|
| 490 |
#This part is for determining the printer's PS ability |
| 491 |
p_is_postscript = gtk.CheckButton("Postscript?") |
| 492 |
hbox_languages.pack_start(p_is_postscript) |
| 493 |
p_is_postscript.show() |
| 494 |
|
| 495 |
p_postscript_level = gtk.Entry() |
| 496 |
p_postscript_level.set_max_length(1) |
| 497 |
p_postscript_level.set_width_chars(1) |
| 498 |
hbox_languages.pack_start(p_postscript_level) |
| 499 |
|
| 500 |
p_postscript_url = gtk.Entry() |
| 501 |
hbox_languages.pack_start(p_postscript_url) |
| 502 |
|
| 503 |
ps_ppd_location_button = gtk.Button('Find/Grok:') |
| 504 |
hbox_languages.pack_start(ps_ppd_location_button) |
| 505 |
#ps_ppd_location_button.connect('clicked', self.grok_ppd_file_def, p_make, p_model, p_color, p_is_postscript, p_postscript_level, p_pjl, p_throughput) |
| 506 |
p_is_postscript.connect("toggled", self.postscript_select, p_postscript_level, p_postscript_url, ps_ppd_location_button) |
| 507 |
|
| 508 |
#This is for determining the printer's PCL ability |
| 509 |
p_is_pcl = gtk.CheckButton("PCL?") |
| 510 |
hbox_languages.pack_start(p_is_pcl) |
| 511 |
p_is_pcl.show() |
| 512 |
|
| 513 |
p_pcl_level = gtk.Entry() |
| 514 |
p_pcl_level.set_max_length(3) |
| 515 |
p_pcl_level.set_width_chars(3) |
| 516 |
hbox_languages.pack_start(p_pcl_level) |
| 517 |
|
| 518 |
p_is_pcl.connect("toggled", self.pcl_select, p_pcl_level) |
| 519 |
|
| 520 |
#For the <tiff> tag |
| 521 |
p_tiff = gtk.CheckButton("TIFF") |
| 522 |
hbox_languages.pack_start(p_tiff) |
| 523 |
p_tiff.show() |
| 524 |
|
| 525 |
#For the <escp> tag |
| 526 |
p_escp = gtk.CheckButton("ESCP") |
| 527 |
hbox_languages.pack_start(p_escp) |
| 528 |
p_escp.show() |
| 529 |
|
| 530 |
#For the <hpgl2> tag |
| 531 |
p_hpgl2 = gtk.CheckButton("HPGL/2") |
| 532 |
hbox_languages.pack_start(p_hpgl2) |
| 533 |
p_hpgl2.show() |
| 534 |
|
| 535 |
#For the <proprietary> tag |
| 536 |
p_proprietary = gtk.CheckButton("Proprietary") |
| 537 |
hbox_languages.pack_start(p_proprietary) |
| 538 |
p_proprietary.show() |
| 539 |
|
| 540 |
lang_sep = gtk.VSeparator() |
| 541 |
hbox_languages.pack_start(lang_sep) |
| 542 |
lang_sep.show() |
| 543 |
|
| 544 |
#Print Job Language support |
| 545 |
p_pjl = gtk.CheckButton("PJL") |
| 546 |
hbox_languages.pack_start(p_pjl) |
| 547 |
p_pjl.show() |
| 548 |
|
| 549 |
#ASCII printing |
| 550 |
p_charset = gtk.CheckButton("US-ASCII") |
| 551 |
hbox_languages.pack_start(p_charset) |
| 552 |
p_charset.show() |
| 553 |
|
| 554 |
#AUTODETECTION |
| 555 |
autodetect_label = gtk.Label("Autodetection") |
| 556 |
vbox.pack_start(autodetect_label) |
| 557 |
autodetect_label.show() |
| 558 |
|
| 559 |
hbox_autodetect = gtk.HBox() |
| 560 |
vbox.add(hbox_autodetect) |
| 561 |
hbox_autodetect.show() |
| 562 |
|
| 563 |
#USB AUTODETECTION |
| 564 |
vbox_autodetect_usb = gtk.VBox() |
| 565 |
hbox_autodetect.add(vbox_autodetect_usb) |
| 566 |
vbox_autodetect_usb.show() |
| 567 |
p_autodetect_usb = gtk.CheckButton("USB?") |
| 568 |
vbox_autodetect_usb.pack_start(p_autodetect_usb) |
| 569 |
p_autodetect_usb.show() |
| 570 |
usb_ieee1284 = gtk.Entry() |
| 571 |
vbox_autodetect_usb.pack_start(usb_ieee1284) |
| 572 |
usb_manufacturer = gtk.Entry() |
| 573 |
vbox_autodetect_usb.pack_start(usb_manufacturer) |
| 574 |
usb_model = gtk.Entry() |
| 575 |
vbox_autodetect_usb.pack_start(usb_model) |
| 576 |
usb_description = gtk.Entry() |
| 577 |
vbox_autodetect_usb.pack_start(usb_description) |
| 578 |
usb_commandset = gtk.Entry() |
| 579 |
vbox_autodetect_usb.pack_start(usb_commandset) |
| 580 |
p_autodetect_usb.connect("toggled", self.usb_select, usb_ieee1284, usb_manufacturer, usb_model, usb_description, usb_commandset) |
| 581 |
|
| 582 |
#PARALLEL PORT AUTODETECTION |
| 583 |
vbox_autodetect_parallel = gtk.VBox() |
| 584 |
hbox_autodetect.add(vbox_autodetect_parallel) |
| 585 |
vbox_autodetect_parallel.show() |
| 586 |
p_autodetect_parallel = gtk.CheckButton("Parallel?") |
| 587 |
vbox_autodetect_parallel.pack_start(p_autodetect_parallel) |
| 588 |
p_autodetect_parallel.show() |
| 589 |
parallel_ieee1284 = gtk.Entry() |
| 590 |
vbox_autodetect_parallel.pack_start(parallel_ieee1284) |
| 591 |
parallel_manufacturer = gtk.Entry() |
| 592 |
vbox_autodetect_parallel.pack_start(parallel_manufacturer) |
| 593 |
parallel_model = gtk.Entry() |
| 594 |
vbox_autodetect_parallel.pack_start(parallel_model) |
| 595 |
parallel_commandset = gtk.Entry() |
| 596 |
vbox_autodetect_parallel.pack_start(parallel_commandset) |
| 597 |
p_autodetect_parallel.connect("toggled", self.parallel_select, parallel_ieee1284, parallel_manufacturer, parallel_model, parallel_commandset) |
| 598 |
|
| 599 |
#SNMP AUTODETECTION |
| 600 |
vbox_autodetect_snmp = gtk.VBox() |
| 601 |
hbox_autodetect.add(vbox_autodetect_snmp) |
| 602 |
vbox_autodetect_snmp.show() |
| 603 |
p_autodetect_snmp = gtk.CheckButton("SNMP?") |
| 604 |
vbox_autodetect_snmp.pack_start(p_autodetect_snmp) |
| 605 |
p_autodetect_snmp.show() |
| 606 |
snmp_description = gtk.Entry() |
| 607 |
vbox_autodetect_snmp.pack_start(snmp_description) |
| 608 |
p_autodetect_snmp.connect("toggled", self.snmp_select, snmp_description) |
| 609 |
|
| 610 |
#Determine the functionality level of the printer |
| 611 |
hbox_functionality = gtk.HBox() |
| 612 |
vbox.add(hbox_functionality) |
| 613 |
hbox_functionality.show() |
| 614 |
|
| 615 |
p_functionality_combo = gtk.combo_box_new_text() |
| 616 |
p_functionality_combo.append_text('Functionality') |
| 617 |
p_functionality_combo.append_text('A') |
| 618 |
p_functionality_combo.append_text('B') |
| 619 |
p_functionality_combo.append_text('D') |
| 620 |
p_functionality_combo.append_text('F') |
| 621 |
p_functionality_combo.set_active(0) |
| 622 |
vbox.pack_start(p_functionality_combo) |
| 623 |
p_functionality_combo.show() |
| 624 |
|
| 625 |
#Now some fancy footwork so other drivers can join the band |
| 626 |
hboxdriverrow = gtk.HBox() |
| 627 |
vbox.add(hboxdriverrow) |
| 628 |
hboxdriverrow.show() |
| 629 |
|
| 630 |
vbdrcol1 = gtk.VBox() |
| 631 |
hboxdriverrow.add(vbdrcol1) |
| 632 |
vbdrcol1.show() |
| 633 |
|
| 634 |
vbdrcol2 = gtk.VBox() |
| 635 |
hboxdriverrow.add(vbdrcol2) |
| 636 |
vbdrcol2.show() |
| 637 |
|
| 638 |
vbdrcol2row1 = gtk.HBox() |
| 639 |
vbdrcol2.add(vbdrcol2row1) |
| 640 |
vbdrcol2row1.show() |
| 641 |
|
| 642 |
vbdrcol2row2 = gtk.HBox() |
| 643 |
vbdrcol2.add(vbdrcol2row2) |
| 644 |
vbdrcol2row2.show() |
| 645 |
|
| 646 |
#The recommended driver for the printer |
| 647 |
p_recommended_driver_label = gtk.Label('Recommended Driver') |
| 648 |
vbdrcol1.pack_start(p_recommended_driver_label) |
| 649 |
p_recommended_driver_label.show() |
| 650 |
|
| 651 |
p_recommended_driver = gtk.Entry() |
| 652 |
p_recommended_driver.set_width_chars(12) |
| 653 |
vbdrcol1.pack_start(p_recommended_driver) |
| 654 |
p_recommended_driver_dropdown = gtk.EntryCompletion() |
| 655 |
self.driverlistdropdown_r = gtk.ListStore(str) |
| 656 |
for driver in self.__driverlist__: |
| 657 |
self.driverlistdropdown_r.append([driver]) |
| 658 |
p_recommended_driver_dropdown.set_model(self.driverlistdropdown_r) |
| 659 |
p_recommended_driver.set_completion(p_recommended_driver_dropdown) |
| 660 |
p_recommended_driver_dropdown.set_text_column(0) |
| 661 |
p_recommended_driver.show() |
| 662 |
|
| 663 |
#Now the additional print drivers |
| 664 |
p_extra_drivers_label = gtk.Label('Other drivers') |
| 665 |
vbdrcol2row1.add(p_extra_drivers_label) |
| 666 |
p_extra_drivers_label.show() |
| 667 |
|
| 668 |
p_extra_drivers_1 = gtk.Entry() |
| 669 |
p_extra_drivers_1.set_width_chars(12) |
| 670 |
vbdrcol2row2.add(p_extra_drivers_1) |
| 671 |
p_extra_drivers_1.show() |
| 672 |
|
| 673 |
p_extra_drivers_2 = gtk.Entry() |
| 674 |
p_extra_drivers_2.set_width_chars(12) |
| 675 |
vbdrcol2row2.add(p_extra_drivers_2) |
| 676 |
p_extra_drivers_2.show() |
| 677 |
|
| 678 |
p_extra_drivers_3 = gtk.Entry() |
| 679 |
p_extra_drivers_3.set_width_chars(12) |
| 680 |
vbdrcol2row2.add(p_extra_drivers_3) |
| 681 |
p_extra_drivers_3.show() |
| 682 |
|
| 683 |
p_extra_drivers_4 = gtk.Entry() |
| 684 |
p_extra_drivers_4.set_width_chars(12) |
| 685 |
vbdrcol2row2.add(p_extra_drivers_4) |
| 686 |
p_extra_drivers_4.show() |
| 687 |
|
| 688 |
#Text box to enter comments about the printer |
| 689 |
comments_label = gtk.Label('Comments') |
| 690 |
vbox.pack_start(comments_label) |
| 691 |
comments_label.show() |
| 692 |
|
| 693 |
p_comments = gtk.Entry() |
| 694 |
vbox.pack_start(p_comments) |
| 695 |
p_comments.show() |
| 696 |
|
| 697 |
#Throughput of the printer |
| 698 |
throughput_label = gtk.Label('Throughput (optional)') |
| 699 |
vbox.pack_start(throughput_label) |
| 700 |
throughput_label.show() |
| 701 |
|
| 702 |
p_throughput = gtk.Entry() |
| 703 |
vbox.pack_start(p_throughput) |
| 704 |
p_throughput.show() |
| 705 |
|
| 706 |
#This connect statement here so that things don't get blowed up |
| 707 |
ps_ppd_location_button.connect('clicked', self.grok_ppd_file_def, p_make, p_model, p_color, p_is_postscript, p_postscript_level, p_postscript_url, p_pjl, p_throughput) |
| 708 |
|
| 709 |
#And now the sexy part of the program - the action buttons |
| 710 |
hbox_buttons = gtk.HBox() |
| 711 |
vbox.add(hbox_buttons) |
| 712 |
hbox_buttons.show() |
| 713 |
|
| 714 |
grok_configuration_button = gtk.Button("Configuration") |
| 715 |
hbox_buttons.pack_start(grok_configuration_button) |
| 716 |
# grok_configuration_button.connect('clicked', self.grok_configuration) |
| 717 |
grok_configuration_button.connect('clicked', self.choose_directory_drop) |
| 718 |
grok_configuration_button.show() |
| 719 |
|
| 720 |
open_printer_xml_file_button = gtk.Button("Open printer XML file") |
| 721 |
hbox_buttons.pack_start(open_printer_xml_file_button) |
| 722 |
open_printer_xml_file_button.connect('clicked', self.open_printer_xml_file_def, p_make, p_model, p_x_dpi, p_y_dpi, p_url, p_pjl, p_charset, p_color, p_mechanism_combo, p_comments, p_functionality_combo, p_proprietary, p_recommended_driver, p_is_postscript, p_is_pcl, p_tiff, p_escp, p_hpgl2, p_postscript_level, p_postscript_url, p_pcl_level, p_consumables) |
| 723 |
open_printer_xml_file_button.show() |
| 724 |
|
| 725 |
#Gives user option to not enter data to printer XML entry |
| 726 |
add_to_driver_check = gtk.CheckButton("Add to driver file?") |
| 727 |
|
| 728 |
write_xml_button = gtk.Button("Write printer XML file") |
| 729 |
hbox_buttons.pack_start(write_xml_button) |
| 730 |
write_xml_button.connect('clicked', self.write_printer_xml_file, p_make, p_model, p_color, p_mechanism_combo, p_x_dpi, p_y_dpi, p_consumables, p_url, p_is_postscript, p_postscript_level, p_postscript_url, p_is_pcl, p_pcl_level, p_tiff, p_escp, p_hpgl2, p_proprietary, p_pjl, p_charset, p_autodetect_usb, usb_ieee1284, usb_manufacturer, usb_model, usb_description, usb_commandset, p_autodetect_parallel, parallel_ieee1284, parallel_manufacturer, parallel_model, parallel_commandset, snmp_description, p_functionality_combo, p_recommended_driver, p_extra_drivers_1, p_extra_drivers_2, p_extra_drivers_3, p_extra_drivers_4, p_comments, p_throughput, add_to_driver_check) |
| 731 |
write_xml_button.show() |
| 732 |
|
| 733 |
hbox_buttons.pack_start(add_to_driver_check) |
| 734 |
add_to_driver_check.show() |
| 735 |
|
| 736 |
window.show() |
| 737 |
return |
| 738 |
|
| 739 |
def open_printer_xml_file_def(self, button, p_make, p_model, p_x_dpi, p_y_dpi, p_url, p_pjl, p_charset, p_color, p_mechanism_combo, p_comments, p_functionality_combo, p_proprietary, p_recommended_driver, p_is_postscript, p_is_pcl, p_tiff, p_escp, p_hpgl2, p_postscript_level, p_postscript_url, p_pcl_level, p_consumables): |
| 740 |
#This is the mechanism to get the XML file |
| 741 |
print "This feature is not %100 complete, but hold tight" |
| 742 |
xml_file_location = '' |
| 743 |
dialog = gtk.FileChooserDialog("Open a printer XML to grok...", |
| 744 |
None, |
| 745 |
gtk.FILE_CHOOSER_ACTION_OPEN, |
| 746 |
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, |
| 747 |
gtk.STOCK_OPEN, gtk.RESPONSE_OK)) |
| 748 |
dialog.set_default_response(gtk.RESPONSE_OK) |
| 749 |
|
| 750 |
filter = gtk.FileFilter() |
| 751 |
filter.set_name("XML Files") |
| 752 |
filter.add_pattern("*.xml") |
| 753 |
filter.add_pattern("*.Xml") |
| 754 |
filter.add_pattern("*.XML") |
| 755 |
dialog.add_filter(filter) |
| 756 |
|
| 757 |
filter = gtk.FileFilter() |
| 758 |
filter.set_name("All files") |
| 759 |
filter.add_pattern("*") |
| 760 |
dialog.add_filter(filter) |
| 761 |
|
| 762 |
response = dialog.run() |
| 763 |
if response == gtk.RESPONSE_OK: |
| 764 |
xml_file_location = dialog.get_filename() |
| 765 |
elif response == gtk.RESPONSE_CANCEL: |
| 766 |
xml_file_location = '' |
| 767 |
dialog.destroy() |
| 768 |
|
| 769 |
#This reads the XML file |
| 770 |
comments_fix = 0 |
| 771 |
if xml_file_location is not '': |
| 772 |
xmldoc = minidom.parse(xml_file_location) |
| 773 |
for node in xmldoc.getElementsByTagName('make'): |
| 774 |
xml_make = node.firstChild.data |
| 775 |
p_make.set_text(xml_make) |
| 776 |
for node in xmldoc.getElementsByTagName('model'): |
| 777 |
xml_model = node.firstChild.data |
| 778 |
p_model.set_text(xml_model) |
| 779 |
for node in xmldoc.getElementsByTagName('consumables'): |
| 780 |
if node.firstChild: |
| 781 |
consumables = node.firstChild.data |
| 782 |
p_consumables.set_text(consumables) |
| 783 |
for node in xmldoc.getElementsByTagName('url'): |
| 784 |
if node.firstChild: |
| 785 |
xml_url = node.firstChild.data |
| 786 |
p_url.set_text(xml_url) |
| 787 |
#This is for <mechanism> |
| 788 |
for node in xmldoc.getElementsByTagName('mechanism'): |
| 789 |
for node in xmldoc.getElementsByTagName('color'): |
| 790 |
p_color.set_active(True) |
| 791 |
for node in xmldoc.getElementsByTagName('x'): |
| 792 |
xml_xdpi = node.firstChild.data |
| 793 |
p_x_dpi.set_text(xml_xdpi) |
| 794 |
for node in xmldoc.getElementsByTagName('y'): |
| 795 |
xml_ydpi = node.firstChild.data |
| 796 |
p_y_dpi.set_text(xml_ydpi) |
| 797 |
for node in xmldoc.getElementsByTagName('laser'): |
| 798 |
p_mechanism_combo.set_active(1) |
| 799 |
for node in xmldoc.getElementsByTagName('inkjet'): |
| 800 |
p_mechanism_combo.set_active(2) |
| 801 |
for node in xmldoc.getElementsByTagName('led'): |
| 802 |
p_mechanism_combo.set_active(3) |
| 803 |
for node in xmldoc.getElementsByTagName('dotmatrix'): |
| 804 |
p_mechanism_combo.set_active(4) |
| 805 |
for node in xmldoc.getElementsByTagName('impact'): |
| 806 |
p_mechanism_combo.set_active(5) |
| 807 |
for node in xmldoc.getElementsByTagName('sublimation'): |
| 808 |
p_mechanism_combo.set_active(6) |
| 809 |
for node in xmldoc.getElementsByTagName('transfer'): |
| 810 |
p_mechanism_combo.set_active(7) |
| 811 |
#This is for <lang> |
| 812 |
for node in xmldoc.getElementsByTagName('lang'): |
| 813 |
for node in xmldoc.getElementsByTagName('postscript'): |
| 814 |
p_is_postscript.set_active(True) |
| 815 |
ps_level = node.getAttribute('level') |
| 816 |
p_postscript_level.set_text(ps_level) |
| 817 |
#if node.firstChild: |
| 818 |
# for node in xmldoc.getElementsByTageName('ppd'): |
| 819 |
# ps_url = node.firstChild.data |
| 820 |
# p_postscript_url(ps_url) |
| 821 |
for node in xmldoc.getElementsByTagName('pcl'): |
| 822 |
p_is_pcl.set_active(True) |
| 823 |
pcl_level = node.getAttribute('level') |
| 824 |
p_pcl_level.set_text(pcl_level) |
| 825 |
for node in xmldoc.getElementsByTagName('tiff'): |
| 826 |
p_tiff.set_active(True) |
| 827 |
for node in xmldoc.getElementsByTagName('escp'): |
| 828 |
p_escp.set_active(True) |
| 829 |
for node in xmldoc.getElementsByTagName('hpgl2'): |
| 830 |
p_hpgl2.set_active(True) |
| 831 |
for node in xmldoc.getElementsByTagName('pjl'): |
| 832 |
p_pjl.set_active(True) |
| 833 |
for node in xmldoc.getElementsByTagName('charset'): |
| 834 |
p_charset.set_active(True) |
| 835 |
for node in xmldoc.getElementsByTagName('proprietary'): |
| 836 |
p_proprietary.set_active(True) |
| 837 |
|
| 838 |
for node in xmldoc.getElementsByTagName('driver'): |
| 839 |
xml_recommended_driver = node.firstChild.data |
| 840 |
p_recommended_driver.set_text(xml_recommended_driver) |
| 841 |
#And now for <functionality> |
| 842 |
for node in xmldoc.getElementsByTagName('functionality'): |
| 843 |
xml_functionality = node.firstChild.data |
| 844 |
if xml_functionality == 'A': |
| 845 |
p_functionality_combo.set_active(1) |
| 846 |
if xml_functionality == 'B': |
| 847 |
p_functionality_combo.set_active(2) |
| 848 |
if xml_functionality == 'D': |
| 849 |
p_functionality_combo.set_active(3) |
| 850 |
if xml_functionality == 'F': |
| 851 |
p_functionality_combo.set_active(4) |
| 852 |
|
| 853 |
for node in xmldoc.getElementsByTagName('comments'): |
| 854 |
for node in xmldoc.getElementsByTagName('en'): |
| 855 |
xml_comments = node.lastChild.data |
| 856 |
p_comments.set_text(xml_comments) |
| 857 |
|
| 858 |
def choose_directory_drop(self, button): |
| 859 |
dialog = gtk.FileChooserDialog("Select directory that has drivers, opt, PPD, and printers...", |
| 860 |
None, |
| 861 |
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, |
| 862 |
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, |
| 863 |
gtk.STOCK_OPEN, gtk.RESPONSE_OK)) |
| 864 |
dialog.set_default_response(gtk.RESPONSE_OK) |
| 865 |
|
| 866 |
filter = gtk.FileFilter() |
| 867 |
filter.set_name("All files") |
| 868 |
filter.add_pattern("*") |
| 869 |
dialog.add_filter(filter) |
| 870 |
|
| 871 |
response = dialog.run() |
| 872 |
if response == gtk.RESPONSE_OK: |
| 873 |
main_folder_location = dialog.get_filename() |
| 874 |
directory_drop = main_folder_location |
| 875 |
self.save_configuration_def(directory_drop) |
| 876 |
elif response == gtk.RESPONSE_CANCEL: |
| 877 |
main_folder_location = directory_drop.get_text() |
| 878 |
dialog.destroy() |
| 879 |
#directory_drop.set_text(main_folder_location) |
| 880 |
|
| 881 |
def save_configuration_def(self, directory_drop): |
| 882 |
#This is the configuration file that is saved as ppdtoxml.conf |
| 883 |
parent_directory = directory_drop |
| 884 |
print parent_directory |
| 885 |
|
| 886 |
temp = sys.stdout |
| 887 |
sys.stdout = open("ppdtoxml.conf", 'w') |
| 888 |
|
| 889 |
print "This is the PPD to XML converter translator configuration file. Mess with this how you want, but otherwise just let the GUI do its thing." |
| 890 |
print "FOODIR=%s" %parent_directory |
| 891 |
|
| 892 |
sys.stdout.close() |
| 893 |
sys.stdout = temp |
| 894 |
|
| 895 |
def grok_ppd_file_def(self, button, p_make, p_model, p_color, p_is_postscript, p_postscript_level, p_postscript_url, p_pjl, p_throughput): |
| 896 |
#This is the part which goes through the PPD and grabs the necessary bits for the XML files |
| 897 |
print "This feature is not %100 complete, be sure to double check the XML file and hold tight" |
| 898 |
|
| 899 |
dialog = gtk.FileChooserDialog("Open a PPD to grok...", |
| 900 |
None, |
| 901 |
gtk.FILE_CHOOSER_ACTION_OPEN, |
| 902 |
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, |
| 903 |
gtk.STOCK_OPEN, gtk.RESPONSE_OK)) |
| 904 |
dialog.set_default_response(gtk.RESPONSE_OK) |
| 905 |
|
| 906 |
filter = gtk.FileFilter() |
| 907 |
filter.set_name("PPD Files") |
| 908 |
filter.add_pattern("*.ppd") |
| 909 |
filter.add_pattern("*.Ppd") |
| 910 |
filter.add_pattern("*.PPD") |
| 911 |
dialog.add_filter(filter) |
| 912 |
|
| 913 |
filter = gtk.FileFilter() |
| 914 |
filter.set_name("All files") |
| 915 |
filter.add_pattern("*") |
| 916 |
dialog.add_filter(filter) |
| 917 |
|
| 918 |
response = dialog.run() |
| 919 |
if response == gtk.RESPONSE_OK: |
| 920 |
ppd_file_location = dialog.get_filename() |
| 921 |
p_postscript_url.set_text(ppd_file_location) |
| 922 |
elif response == gtk.RESPONSE_CANCEL: |
| 923 |
ppd_file_location = '' |
| 924 |
dialog.destroy() |
| 925 |
|
| 926 |
if ppd_file_location is not '': |
| 927 |
for line in open(ppd_file_location): |
| 928 |
if line.find('*PPD-Adobe:') != -1: |
| 929 |
print line |
| 930 |
if line.find('*Manufacturer:') != -1: |
| 931 |
line = line.replace('*Manufacturer:', '') |
| 932 |
p_make.set_text(self.line_cleaner(line)) |
| 933 |
if line.find('*ModelName:') != -1: |
| 934 |
line = line.replace('*ModelName:', '') |
| 935 |
line = line.replace(p_make.get_text(), '') |
| 936 |
p_model.set_text(self.line_cleaner(line)) |
| 937 |
if line.find('*Throughput:') != -1: |
| 938 |
line = line.replace('*Throughput:', '') |
| 939 |
p_throughput.set_text(self.line_cleaner(line)) |
| 940 |
if line.find('*Protocol') != -1: |
| 941 |
if line.find('PJL') != -1: |
| 942 |
p_pjl.set_active(True) |
| 943 |
if line.find('*ColorDevice') != -1: |
| 944 |
if line.find('True' or 'true'): |
| 945 |
p_color.set_active(True) |
| 946 |
print "color device true" |
| 947 |
#if line.find('False' or 'false'): |
| 948 |
# p_color.set_active(False) |
| 949 |
if line.find('*LanguageLevel:') != -1: |
| 950 |
line = line.replace('*LanguageLevel:', '') |
| 951 |
line = self.line_cleaner(line) |
| 952 |
p_is_postscript.set_active(True) |
| 953 |
p_postscript_level.set_text(line) |
| 954 |
|
| 955 |
def line_cleaner(self, line): |
| 956 |
#line_cleaner properly formats the strings going into the XML file |
| 957 |
line = line.replace('\"', '') |
| 958 |
line = line.replace('\f', '') |
| 959 |
line = line.replace('\r', '') |
| 960 |
line = line.replace(' ', '') |
| 961 |
line = line.replace('\n', '') |
| 962 |
line = line.replace('\t', '') |
| 963 |
return line |
| 964 |
|
| 965 |
def postscript_select(self, p_is_postscript, p_postscript_level, p_postscript_url, ps_ppd_location_button): |
| 966 |
if p_is_postscript.get_active(): |
| 967 |
p_postscript_level.show() |
| 968 |
p_postscript_url.show() |
| 969 |
ps_ppd_location_button.show() |
| 970 |
p_postscript_url.set_text('') |
| 971 |
else: |
| 972 |
p_postscript_level.hide() |
| 973 |
p_postscript_level.set_text('') |
| 974 |
p_postscript_url.hide() |
| 975 |
ps_ppd_location_button.hide() |
| 976 |
p_postscript_url.set_text('') |
| 977 |
|
| 978 |
def pcl_select(self, p_is_pcl, p_pcl_level): |
| 979 |
if p_is_pcl.get_active(): |
| 980 |
p_pcl_level.show() |
| 981 |
else: |
| 982 |
p_pcl_level.hide() |
| 983 |
p_pcl_level.set_text('') |
| 984 |
|
| 985 |
def usb_select(self, p_autodetect_usb, usb_ieee1284, usb_manufacturer, usb_model, usb_description, usb_commandset): |
| 986 |
if p_autodetect_usb.get_active(): |
| 987 |
usb_ieee1284.show() |
| 988 |
usb_ieee1284.set_text('IEEE 1284') |
| 989 |
usb_manufacturer.show() |
| 990 |
usb_manufacturer.set_text('Manufacturer') |
| 991 |
usb_model.show() |
| 992 |
usb_model.set_text('Model') |
| 993 |
usb_description.show() |
| 994 |
usb_description.set_text('Description') |
| 995 |
usb_commandset.show() |
| 996 |
usb_commandset.set_text('Commandset') |
| 997 |
else: |
| 998 |
usb_ieee1284.hide() |
| 999 |
usb_ieee1284.set_text('') |
| 1000 |
usb_manufacturer.hide() |
| 1001 |
usb_manufacturer.set_text('') |
| 1002 |
usb_model.hide() |
| 1003 |
usb_model.set_text('') |
| 1004 |
usb_description.hide() |
| 1005 |
usb_description.set_text('') |
| 1006 |
usb_commandset.hide() |
| 1007 |
usb_commandset.set_text('') |
| 1008 |
|
| 1009 |
def parallel_select(self, p_autodetect_parallel, parallel_ieee1284, parallel_manufacturer, parallel_model, parallel_commandset): |
| 1010 |
if p_autodetect_parallel.get_active(): |
| 1011 |
parallel_ieee1284.show() |
| 1012 |
parallel_ieee1284.set_text('IEEE 1284') |
| 1013 |
parallel_manufacturer.show() |
| 1014 |
parallel_manufacturer.set_text('Manufacturer') |
| 1015 |
parallel_model.show() |
| 1016 |
parallel_model.set_text('Model') |
| 1017 |
parallel_commandset.show() |
| 1018 |
parallel_commandset.set_text('Commandset') |
| 1019 |
else: |
| 1020 |
parallel_ieee1284.hide() |
| 1021 |
parallel_ieee1284.set_text('') |
| 1022 |
parallel_manufacturer.hide() |
| 1023 |
parallel_manufacturer.set_text('') |
| 1024 |
parallel_model.hide() |
| 1025 |
parallel_model.set_text('') |
| 1026 |
parallel_commandset.hide() |
| 1027 |
parallel_commandset.set_text('') |
| 1028 |
|
| 1029 |
def snmp_select(self, p_autodetect_snmp, snmp_description): |
| 1030 |
if p_autodetect_snmp.get_active(): |
| 1031 |
snmp_description.show() |
| 1032 |
snmp_description.set_text('SNMP description') |
| 1033 |
else: |
| 1034 |
snmp_description.hide() |
| 1035 |
snmp_description.set_text('') |
| 1036 |
|
| 1037 |
def special_char_cleanup(self, stringthing): |
| 1038 |
#This formats punctuation properly |
| 1039 |
stringthing = stringthing.replace('&', '&') |
| 1040 |
stringthing = stringthing.replace('<', '<') |
| 1041 |
stringthing = stringthing.replace('>', '>') |
| 1042 |
stringthing = stringthing.replace('"', '"') |
| 1043 |
stringthing = stringthing.replace("'", ''') |
| 1044 |
return stringthing |
| 1045 |
|
| 1046 |
def write_printer_xml_file(self, button, p_make, p_model, p_color, p_mechanism_combo, p_x_dpi, p_y_dpi, p_consumables, p_url, p_is_postscript, p_postscript_level, p_postscript_url, p_is_pcl, p_pcl_level, p_tiff, p_escp, p_hpgl2, p_proprietary, p_pjl, p_charset, p_autodetect_usb, usb_ieee1284, usb_manufacturer, usb_model, usb_description, usb_commandset, p_autodetect_parallel, parallel_ieee1284, parallel_manufacturer, parallel_model, parallel_commandset, snmp_description, p_functionality_combo, p_recommended_driver, p_extra_drivers_1, p_extra_drivers_2, p_extra_drivers_3, p_extra_drivers_4, p_comments, p_throughput, add_to_driver_check): |
| 1047 |
|
| 1048 |
make_text = p_make.get_text() |
| 1049 |
filename_make = make_text.replace(' ', '_') |
| 1050 |
model_text = p_model.get_text() |
| 1051 |
filename_model = model_text.replace(' ', '_') |
| 1052 |
|
| 1053 |
mechanism_model = p_mechanism_combo.get_model() |
| 1054 |
mechanism_active = p_mechanism_combo.get_active() |
| 1055 |
mechanism_text = '' |
| 1056 |
if mechanism_active: |
| 1057 |
mechanism_text = mechanism_model[mechanism_active][0] |
| 1058 |
mechanism_text = mechanism_text + '/' |
| 1059 |
else: |
| 1060 |
mechanism_text = '' |
| 1061 |
|
| 1062 |
x_dpi_text = p_x_dpi.get_text() |
| 1063 |
y_dpi_text = p_y_dpi.get_text() |
| 1064 |
consumables_text = p_consumables.get_text() |
| 1065 |
consumables_text = self.special_char_cleanup(consumables_text) |
| 1066 |
url_text = p_url.get_text() |
| 1067 |
url_text = self.special_char_cleanup(url_text) |
| 1068 |
postscript_level_text = p_postscript_level.get_text() |
| 1069 |
postscript_url_text = p_postscript_url.get_text() |
| 1070 |
pcl_level_text = p_pcl_level.get_text() |
| 1071 |
|
| 1072 |
#Adds today's date to the XML file |
| 1073 |
todaysdate = datetime.date.today() |
| 1074 |
|
| 1075 |
#Autodetection variables |
| 1076 |
usb_ieee1284_text = usb_ieee1284.get_text() |
| 1077 |
usb_manufacturer_text = usb_manufacturer.get_text() |
| 1078 |
usb_model_text = usb_model.get_text() |
| 1079 |
usb_description_text = usb_description.get_text() |
| 1080 |
usb_commandset_text = usb_commandset.get_text() |
| 1081 |
parallel_ieee1284_text = parallel_ieee1284.get_text() |
| 1082 |
parallel_manufacturer_text = parallel_manufacturer.get_text() |
| 1083 |
parallel_model_text = parallel_model.get_text() |
| 1084 |
parallel_commandset_text = parallel_commandset.get_text() |
| 1085 |
snmp_text = snmp_description.get_text() |
| 1086 |
|
| 1087 |
functionality_model = p_functionality_combo.get_model() |
| 1088 |
functionality_active = p_functionality_combo.get_active() |
| 1089 |
if functionality_active: |
| 1090 |
functionality_text = functionality_model[functionality_active][0] |
| 1091 |
else: |
| 1092 |
print >> sys.stderr, "You need to assign a functionality grade!" |
| 1093 |
functionality_text = "!!! NO FUNCTIONALITY SET !!!" |
| 1094 |
|
| 1095 |
recommended_driver_text = p_recommended_driver.get_text() |
| 1096 |
extra_driver_text_1 = p_extra_drivers_1.get_text() |
| 1097 |
extra_driver_text_2 = p_extra_drivers_2.get_text() |
| 1098 |
extra_driver_text_3 = p_extra_drivers_3.get_text() |
| 1099 |
extra_driver_text_4 = p_extra_drivers_4.get_text() |
| 1100 |
|
| 1101 |
comments_text = p_comments.get_text() |
| 1102 |
comments_text = self.special_char_cleanup(comments_text) |
| 1103 |
|
| 1104 |
throughput_text = p_throughput.get_text() |
| 1105 |
|
| 1106 |
foodir = '' |
| 1107 |
if os.path.isfile("ppdtoxml.conf"): |
| 1108 |
for line in open("ppdtoxml.conf"): |
| 1109 |
if line.find('FOODIR=') != -1: |
| 1110 |
line = line.replace('FOODIR=', '') |
| 1111 |
line = line.replace('\n', '') |
| 1112 |
foodir = line |
| 1113 |
else: |
| 1114 |
pass |
| 1115 |
|
| 1116 |
xml_entry_id = 'printer/' + filename_make + '-' + filename_model |
| 1117 |
xmlfile_name = foodir + '/' + xml_entry_id + '.xml' |
| 1118 |
temp = sys.stdout |
| 1119 |
sys.stdout = open(xmlfile_name, 'w') |
| 1120 |
|
| 1121 |
print "<printer id=\"%s\">" %xml_entry_id |
| 1122 |
print " <make>%s</make>" %make_text |
| 1123 |
print " <model>%s</model>" %model_text |
| 1124 |
print " <mechanism>" |
| 1125 |
if p_color.get_active(): |
| 1126 |
print " <color />" |
| 1127 |
else: |
| 1128 |
print " <!--not \"color\"-->" |
| 1129 |
if mechanism_text is not '': |
| 1130 |
print " <%s>" %mechanism_text |
| 1131 |
print " <resolution>" |
| 1132 |
print " <dpi>" |
| 1133 |
|
| 1134 |
if x_dpi_text is not "": |
| 1135 |
print " <x>%s</x>" %x_dpi_text |
| 1136 |
else: |
| 1137 |
print " <!--x unknown-->" |
| 1138 |
|
| 1139 |
if y_dpi_text is not "": |
| 1140 |
print " <y>%s</y>" %y_dpi_text |
| 1141 |
else: |
| 1142 |
print " <!--y unknown-->" |
| 1143 |
|
| 1144 |
print " </dpi>" |
| 1145 |
print " </resolution>" |
| 1146 |
print " </mechanism>" |
| 1147 |
print " <url>%s</url>" %url_text |
| 1148 |
|
| 1149 |
#LANGUAGES |
| 1150 |
print " <lang>" |
| 1151 |
|
| 1152 |
if p_is_postscript.get_active(): |
| 1153 |
if postscript_level_text is not "": |
| 1154 |
print " <postscript level=\"%s\" />" %postscript_level_text |
| 1155 |
|
| 1156 |
if p_is_pcl.get_active(): |
| 1157 |
print " <pcl level=\"%s\" />" %pcl_level_text |
| 1158 |
|
| 1159 |
if p_tiff.get_active(): |
| 1160 |
print " <tiff />" |
| 1161 |
|
| 1162 |
if p_escp.get_active(): |
| 1163 |
print " <escp />" |
| 1164 |
|
| 1165 |
if p_hpgl2.get_active(): |
| 1166 |
print " <hpgl2 />" |
| 1167 |
|
| 1168 |
if p_proprietary.get_active(): |
| 1169 |
print " <proprietary />" |
| 1170 |
|
| 1171 |
if p_pjl.get_active(): |
| 1172 |
print " <pjl />" |
| 1173 |
else: |
| 1174 |
print " <!--no pjl-->" |
| 1175 |
|
| 1176 |
if p_charset.get_active(): |
| 1177 |
print " <text>" |
| 1178 |
print " <charset>us-ascii</charset>" |
| 1179 |
print " </text>" |
| 1180 |
else: |
| 1181 |
print " <!--no \"text\"-->" |
| 1182 |
|
| 1183 |
print " </lang>" |
| 1184 |
|
| 1185 |
#AUTODETECT PARAMETERS |
| 1186 |
if (p_autodetect_usb.get_active() or p_autodetect_parallel.get_active() or snmp_text is not ""): |
| 1187 |
print " <autodetect>" |
| 1188 |
if p_autodetect_parallel.get_active(): |
| 1189 |
print " <parallel>" |
| 1190 |
if parallel_ieee1284_text is not '': |
| 1191 |
print " <ieee1284>%s<ieee1284>" %parallel_ieee1284_text |
| 1192 |
if parallel_manufacturer_text is not '': |
| 1193 |
print " <manufacturer>%s</manufacturer>" %parallel_manufacturer_text |
| 1194 |
if parallel_model_text is not '': |
| 1195 |
print " <model>%s</model>" %parallel_model_text |
| 1196 |
if parallel_commandset_text is not '': |
| 1197 |
print " <commandset>%s</commandset>" %parallel_commandset_text |
| 1198 |
print " </parallel>" |
| 1199 |
if p_autodetect_usb.get_active(): |
| 1200 |
print " <usb>" |
| 1201 |
if usb_ieee1284_text is not '': |
| 1202 |
print " <ieee1284>%s</ieee1284>" %usb_ieee1284_text |
| 1203 |
if usb_manufacturer_text is not '': |
| 1204 |
print " <manufacturer>%s</manufacturer>" %usb_manufacturer_text |
| 1205 |
if usb_model_text is not '': |
| 1206 |
print " <model>%s</model>" %usb_model_text |
| 1207 |
if usb_description_text is not '': |
| 1208 |
print " <description>%s</description>" %usb_description_text |
| 1209 |
if usb_commandset_text is not '': |
| 1210 |
print " <commandset>%s</commandset>" %usb_commandset_text |
| 1211 |
print " </usb>" |
| 1212 |
if snmp_text is not '': |
| 1213 |
print " <snmp>" |
| 1214 |
print " <description>%s</description>" %snmp_text |
| 1215 |
print " </snmp>" |
| 1216 |
print " </autodetect>" |
| 1217 |
|
| 1218 |
print " <functionality>%s</functionality>" %functionality_text |
| 1219 |
|
| 1220 |
if recommended_driver_text is not "": |
| 1221 |
print " <driver>%s</driver>" %recommended_driver_text |
| 1222 |
print " <drivers>" |
| 1223 |
print " <driver>" |
| 1224 |
print " <id>%s</id>" %recommended_driver_text |
| 1225 |
if recommended_driver_text.find('Postscript') != -1: |
| 1226 |
if postscript_url_text is not "": |
| 1227 |
print " <ppd>%s</ppd>" %postscript_url_text |
| 1228 |
print " </driver>" |
| 1229 |
if extra_driver_text_1 is not "": |
| 1230 |
print " <driver>" |
| 1231 |
print " <id>%s</id>" %extra_driver_text_1 |
| 1232 |
if extra_driver_text_1.find('Postscript') != -1: |
| 1233 |
if postscript_url_text is not "": |
| 1234 |
print " <ppd>%s</ppd>" %postscript_url_text |
| 1235 |
print " </driver>" |
| 1236 |
if extra_driver_text_2 is not "": |
| 1237 |
print " <driver>" |
| 1238 |
print " <id>%s</id>" %extra_driver_text_2 |
| 1239 |
if extra_driver_text_2.find('Postscript') != -1: |
| 1240 |
if postscript_url_text is not "": |
| 1241 |
print " <ppd>%s</ppd>" %postscript_url_text |
| 1242 |
print " </driver>" |
| 1243 |
if extra_driver_text_3 is not "": |
| 1244 |
print " <driver>" |
| 1245 |
print " <id>%s</id>" %extra_driver_text_3 |
| 1246 |
if extra_driver_text_3.find('Postscript') != -1: |
| 1247 |
if postscript_url_text is not "": |
| 1248 |
print " <ppd>%s</ppd>" %postscript_url_text |
| 1249 |
print " </driver>" |
| 1250 |
if extra_driver_text_4 is not "": |
| 1251 |
print " <driver>" |
| 1252 |
print " <id>%s</id>" %extra_driver_text_4 |
| 1253 |
if extra_driver_text_4.find('Postscript') != -1: |
| 1254 |
if postscript_url_text is not "": |
| 1255 |
print " <ppd>%s</ppd>" %postscript_url_text |
| 1256 |
print " </driver>" |
| 1257 |
print " </drivers>" |
| 1258 |
|
| 1259 |
print " <comments>" |
| 1260 |
print " <en>" |
| 1261 |
if comments_text is not "": |
| 1262 |
print " %s" %comments_text |
| 1263 |
print " " |
| 1264 |
if throughput_text is not "": |
| 1265 |
print " Throughput = %s" %throughput_text |
| 1266 |
print " " |
| 1267 |
print " Foomatic entry made by PPDtoXML T/G %s on %s" % (version, todaysdate) |
| 1268 |
print " </en>" |
| 1269 |
print " </comments>" |
| 1270 |
print "</printer>" |
| 1271 |
|
| 1272 |
sys.stdout.close() |
| 1273 |
sys.stdout = temp |
| 1274 |
|
| 1275 |
printer_xmlmade_dialog = gtk.MessageDialog(None, |
| 1276 |
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, |
| 1277 |
gtk.MESSAGE_INFO, gtk.BUTTONS_OK, |
| 1278 |
"Printer XML file created at %s." %xmlfile_name) |
| 1279 |
printer_xmlmade_dialog.run() |
| 1280 |
printer_xmlmade_dialog.destroy() |
| 1281 |
|
| 1282 |
if add_to_driver_check.get_active(): |
| 1283 |
#Now the part where we enter the printer information into the driver XML file |
| 1284 |
driver_xml_location = foodir + '/driver/' + recommended_driver_text + '.xml' |
| 1285 |
if os.path.exists(driver_xml_location): |
| 1286 |
parsed_driver = minidom.parse(driver_xml_location) |
| 1287 |
for node in parsed_driver.getElementsByTagName('printers'): |
| 1288 |
printertag = parsed_driver.createElement('printer') |
| 1289 |
node.appendChild(printertag) |
| 1290 |
printeridtag = parsed_driver.createElement('id') |
| 1291 |
printertag.appendChild(printeridtag) |
| 1292 |
txt = parsed_driver.createTextNode(xml_entry_id) |
| 1293 |
printeridtag.appendChild(txt) |
| 1294 |
|
| 1295 |
#This rewrites the driver XML file |
| 1296 |
temp = sys.stdout |
| 1297 |
sys.stdout = open(driver_xml_location, 'w') |
| 1298 |
print parsed_driver.toxml() |
| 1299 |
sys.stdout.close() |
| 1300 |
sys.stdout = temp |
| 1301 |
|
| 1302 |
driver_xml_dialog = gtk.MessageDialog(None, |
| 1303 |
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, |
| 1304 |
gtk.MESSAGE_INFO, gtk.BUTTONS_OK, |
| 1305 |
"printer ID entered into %s - please correct formatting flaws in the driver XML file until this matter has been fixed" %driver_xml_location) |
| 1306 |
driver_xml_dialog.run() |
| 1307 |
driver_xml_dialog.destroy() |
| 1308 |
|
| 1309 |
else: |
| 1310 |
driver_xml_dialog = gtk.MessageDialog(None, |
| 1311 |
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, |
| 1312 |
gtk.MESSAGE_INFO, gtk.BUTTONS_OK, |
| 1313 |
"driver XML file doesn't exist at %s - can't write information" %driver_xml_location) |
| 1314 |
driver_xml_dialog.run() |
| 1315 |
driver_xml_dialog.destroy() |
| 1316 |
|
| 1317 |
def main(): |
| 1318 |
gtk.main() |
| 1319 |
return |
| 1320 |
|
| 1321 |
if __name__ == "__main__": |
| 1322 |
PPDtoXML() |
| 1323 |
main() |