Thursday, 25. May 2006 10:33.
diag.py now shows printer information as returned by win32print.GetPrinter().(I had to upgrade to pywin32 build 208 because the GetPrinter of my version didn't yet know about a level parameter.)
Here is a first snippet which I used to explore the results of GetPrinter():
def diag_printer(out,printerName=None):
try:
import win32print
except ImportError,e:
out.write("No module win32print (%s)\n" % e)
return
if printerName is None:
printerName=win32print.GetDefaultPrinter()
out.write("Printer %s\n" % printerName)
h=win32print.OpenPrinter(printerName)
for lvl in (1,2,3,4,5,7,8,9):
out.write("GetPrinter(%d,%d): %r\n"
% (h,lvl,win32print.GetPrinter(h,lvl)))
win32print.ClosePrinter(h)
import sys
diag_printer(sys.stdout)
And here is the output (manually indented):
Printer Lexmark Optra PS
GetPrinter(1398484,1): {
'pName': 'Lexmark Optra PS',
'pDescription': 'Lexmark Optra PS,Lexmark Optra PS,',
'Flags': 8388608,
'pComment': ''
}
GetPrinter(1398484,2): {
'Status': 0,
'UntilTime': 1380,
'pDriverName': 'Lexmark Optra PS',
'cJobs': 0,
'pSepFile': '',
'AveragePPM': 0,
'pPortName': 'FILE:',
'pParameters': '',
'pPrintProcessor': 'WinPrint',
'Attributes': 576,
'Priority': 1,
'pPrinterName': 'Lexmark Optra PS',
'DefaultPriority': 0,
'StartTime': 1380,
'pDatatype': 'RAW',
'pDevMode': ,
'pLocation': '',
'pShareName': '',
'pServerName': None,
'pSecurityDescriptor': ,
'pComment': ''
}
GetPrinter(1398484,3): {'pSecurityDescriptor': }
GetPrinter(1398484,4): {'pPrinterName': 'Lexmark Optra PS', 'pServerName':
None, 'Attributes': 576}
GetPrinter(1398484,5): {
'TransmissionRetryTimeout': 45000,
'pPrinterName': 'Lexmark Optra PS',
'DeviceNotSelectedTimeout': 15000,
'Attributes': 576,
'pPortName': 'FILE:'
}
GetPrinter(1398484,7): {'Action': 4, 'ObjectGUID': None}
GetPrinter(1398484,8): {'pDevMode': }
GetPrinter(1398484,9): {'pDevMode': None}
What is a PyDEVMODE object? The pywin32 documentation just says «Python object wrapping a DEVMODE structure».
What is a DEVMODE structure? oem.zeno.com/public/SDK/0_SuperPrint%20SDK/4_Reference/Core%20Exports/Structures/devmode.htm support.microsoft.com/default.aspx?scid=kb;EN-US;Q167345.
I changed the lines between OpenPrinter() and ClosePrinter() as follows:
d=win32print.GetPrinter(h,2)
devmode=d['pDevMode']
for n in dir(devmode):
if n != 'DriverData' and n[0]!='_':
out.write("%r\t%r\n" % (n,getattr(devmode,n)))
And again the result:
Printer Lexmark Optra PS 'BitsPerPel' 0L 'Clear''Collate' 1 'Color' 1 'Copies' 1 'DefaultSource' 15 'DeviceName' 'Lexmark Optra PS' 'DisplayFlags' 1L 'DisplayFrequency' 0L 'DitherType' 0L 'DriverExtra' 708 'DriverVersion' 1282 'Duplex' 1 'Fields' 130899L 'FormName' 'A4' 'ICMIntent' 2L 'ICMMethod' 1L 'LogPixels' 0 'MediaType' 1L 'Nup' 1L 'Orientation' 1 'PanningHeight' 0L 'PanningWidth' 0L 'PaperLength' 2970 'PaperSize' 9 'PaperWidth' 2100 'PelsHeight' 0L 'PelsWidth' 0L 'Position_x' 589825 'Position_y' 137628570 'PrintQuality' 600 'Reserved1' 0L 'Reserved2' 0L 'Scale' 100 'Size' 156 'SpecVersion' 1025 'TTOption' 3 'YResolution' 600
(Later I moved this to sysinfo.py)