From c6ee2f633843368f2470b356b240a057ed7e7faf Mon Sep 17 00:00:00 2001 From: Manuel F Martinez Date: Fri, 12 Apr 2013 14:04:48 -0700 Subject: [PATCH] Added ability to print from a generic file --- escpos/printer.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/escpos/printer.py b/escpos/printer.py index dd5aa93..7cdedf3 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -128,9 +128,40 @@ class Network(Escpos): def _raw(self, msg): + """ Print any command sent in raw format """ self.device.send(msg) def __del__(self): """ Close TCP connection """ self.device.close() + + + +class File(Escpos): + """ Define Generic file printer """ + + def __init__(self, devfile="/dev/usb/lp0"): + """ + @param devfile : Device file under dev filesystem + """ + self.devfile = devfile + self.open() + + + def open(self): + """ Open system file """ + self.device = open(self.devfile, "wb") + + if self.device is None: + print "Could not open the specified file %s" % self.devfile + + + def _raw(self, msg): + """ Print any command sent in raw format """ + self.device.write(msg); + + + def __del__(self): + """ Close system file """ + self.device.close()