# HG changeset patch # User Ben Croston # Date 1313366449 -3600 # Node ID 6a1963ee4afffe6daeaea855c97014b4e6513bec # Parent 19a28a953f393aecffe01d5176293115bc497edb Added docstrings Minor tidying up diff -r 19a28a953f39 -r 6a1963ee4aff README --- a/README Mon Aug 15 00:21:04 2011 +0100 +++ b/README Mon Aug 15 01:00:49 2011 +0100 @@ -10,6 +10,8 @@ :: + from zebra import zebra + z = zebra( [printerqueue] ) - Constructor with optional printerqueue diff -r 19a28a953f39 -r 6a1963ee4aff zebra.py --- a/zebra.py Mon Aug 15 00:21:04 2011 +0100 +++ b/zebra.py Mon Aug 15 01:00:49 2011 +0100 @@ -1,15 +1,20 @@ #!/usr/bin/env python -# NOTE: this package is Linux specific at the moment import subprocess import os.path import sys + if sys.platform.lower().startswith('win'): + IS_WINDOWS = True import win32print +else: + IS_WINDOWS = False class zebra(object): + """A class to communicate with (Zebra) label printers using EPL2""" + def __init__(self, queue=None): - """queue - name of the printer queue""" + """queue - name of the printer queue (optional)""" self.queue = queue def _output_unix(self, commands): @@ -42,8 +47,12 @@ win32print.ClosePrinter(hPrinter) def output(self, commands): + """Output EPL2 commands to the label printer + + commands - EPL2 commands to send to the printer + """ assert self.queue is not None - if sys.platform.lower().startswith('win'): + if IS_WINDOWS: self._output_win(commands) else: self._output_unix(commmands) @@ -63,15 +72,23 @@ return printers def getqueues(self): - if sys.platform.lower().startswith('win'): + """Returns a list of printer queues on local machine""" + if IS_WINDOWS: return self._getqueues_win() else: return self._getqueues_unix() def setqueue(self, queue): + """Set the printer queue""" self.queue = queue def setup(self, direct_thermal=None, label_height=None, label_width=None): + """Set up the label printer. Parameters are not set if they are None. + + direct_thermal - True if using direct thermal labels + label_height - tuple (label height, label gap) in dots + label_width - in dots + """ commands = '\n' if direct_thermal: commands += ('OD\n') @@ -82,7 +99,12 @@ self.output(commands) def store_graphic(self, name, filename): - assert filename.endswith('.pcx') + """Store a .PCX file on the label printer + + name - name to be used on printer + filename - local filename + """ + assert filename.lower().endswith('.pcx') commands = '\nGK"%s"\n'%name commands += 'GK"%s"\n'%name size = os.path.getsize(filename)