comparison zebra.py @ 8:19fd067db7ca

Added Windows support
author Ben Croston
date Mon, 15 Aug 2011 00:20:31 +0100
parents 0687a6666873
children 6a1963ee4aff
comparison
equal deleted inserted replaced
7:0687a6666873 8:19fd067db7ca
22 else: 22 else:
23 p.communicate(str(commands).encode()) 23 p.communicate(str(commands).encode())
24 p.stdin.close() 24 p.stdin.close()
25 25
26 def _output_win(self, commands): 26 def _output_win(self, commands):
27 raise Exception('Not yet implemented') 27 if self.queue == 'zebra_python_unittest':
28 print commands
29 return
30 if type(commands) != bytes:
31 commands = str(commands).encode()
32 hPrinter = win32print.OpenPrinter(self.queue)
33 try:
34 hJob = win32print.StartDocPrinter(hPrinter, 1, ('Label',None,'RAW'))
35 try:
36 win32print.StartPagePrinter(hPrinter)
37 win32print.WritePrinter(hPrinter, commands)
38 win32print.EndPagePrinter(hPrinter)
39 finally:
40 win32print.EndDocPrinter(hPrinter)
41 finally:
42 win32print.ClosePrinter(hPrinter)
28 43
29 def output(self, commands): 44 def output(self, commands):
30 assert self.queue is not None 45 assert self.queue is not None
31 if sys.platform.lower().startswith('win'): 46 if sys.platform.lower().startswith('win'):
32 self._output_win(commands) 47 self._output_win(commands)
40 if line.startswith('printer'): 55 if line.startswith('printer'):
41 queues.append(line.split(' ')[1]) 56 queues.append(line.split(' ')[1])
42 return queues 57 return queues
43 58
44 def _getqueues_win(self): 59 def _getqueues_win(self):
45 raise Exception('Not yet implemented') 60 printers = []
61 for (a,b,name,d) in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
62 printers.append(name)
63 return printers
46 64
47 def getqueues(self): 65 def getqueues(self):
48 if sys.platform.lower().startswith('win'): 66 if sys.platform.lower().startswith('win'):
49 return self._getqueues_win() 67 return self._getqueues_win()
50 else: 68 else: