commit
9fdb382c99
21
README.md
21
README.md
|
@ -10,7 +10,7 @@ In order to start getting access to your printer, you must ensure
|
||||||
you have previously installed the following python modules:
|
you have previously installed the following python modules:
|
||||||
|
|
||||||
* pyusb (python-usb)
|
* pyusb (python-usb)
|
||||||
* PIL (Python Image Library)
|
* PIL (Python Image Library) or Pillow (recommended)
|
||||||
|
|
||||||
2. Description
|
2. Description
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
|
@ -69,16 +69,15 @@ The following example shows how to initialize the Epson TM-TI88IV
|
||||||
*** NOTE: Always finish the sequence with Epson.cut() otherwise
|
*** NOTE: Always finish the sequence with Epson.cut() otherwise
|
||||||
you will endup with weird chars being printed.
|
you will endup with weird chars being printed.
|
||||||
|
|
||||||
from escpos import *
|
from escpos import printer
|
||||||
|
|
||||||
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """
|
p = printer.Usb(0x04b8, 0x0202)
|
||||||
Epson = escpos.Escpos(0x04b8,0x0202,0)
|
p.text("Hello World")
|
||||||
Epson.text("Hello World")
|
p.image("doge.jpg")
|
||||||
Epson.image("logo.gif")
|
p.fullimage("a.really.large.image.png")
|
||||||
Epson.fullimage("a.really.large.image.png")
|
p.barcode('1324354657687','EAN13',64,2,'','')
|
||||||
Epson.barcode
|
p.qr('this is a piece of code')
|
||||||
Epson.barcode('1324354657687','EAN13',64,2,'','')
|
p.cut()
|
||||||
Epson.cut()
|
|
||||||
|
|
||||||
5. Links
|
5. Links
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
@license: GPL
|
@license: GPL
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import Image
|
|
||||||
import qrcode
|
|
||||||
import time
|
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
import qrcode
|
||||||
import operator
|
import operator
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from constants import *
|
from constants import *
|
||||||
from exceptions import *
|
from exceptions import *
|
||||||
|
@ -37,7 +37,7 @@ class Escpos:
|
||||||
i = 0
|
i = 0
|
||||||
cont = 0
|
cont = 0
|
||||||
buffer = ""
|
buffer = ""
|
||||||
|
|
||||||
self._raw(S_RASTER_N)
|
self._raw(S_RASTER_N)
|
||||||
buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1], 0)
|
buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1], 0)
|
||||||
self._raw(buffer.decode('hex'))
|
self._raw(buffer.decode('hex'))
|
||||||
|
@ -135,21 +135,21 @@ class Escpos:
|
||||||
break
|
break
|
||||||
elif im_color > (255 * 3 / pattern_len * pattern_len) and im_color <= (255 * 3):
|
elif im_color > (255 * 3 / pattern_len * pattern_len) and im_color <= (255 * 3):
|
||||||
pix_line += im_pattern[-1]
|
pix_line += im_pattern[-1]
|
||||||
break
|
break
|
||||||
pix_line += im_right
|
pix_line += im_right
|
||||||
img_size[0] += im_border[1]
|
img_size[0] += im_border[1]
|
||||||
|
|
||||||
self._print_image(pix_line, img_size)
|
self._print_image(pix_line, img_size)
|
||||||
|
|
||||||
def qr(self,text):
|
def qr(self, text):
|
||||||
""" Print QR Code for the provided string """
|
""" Print QR Code for the provided string """
|
||||||
qr_code = qrcode.QRCode(version=4, box_size=4, border=1)
|
qr_code = qrcode.QRCode(version=4, box_size=4, border=1)
|
||||||
qr_code.add_data(text)
|
qr_code.add_data(text)
|
||||||
qr_code.make(fit=True)
|
qr_code.make(fit=True)
|
||||||
qr_img = qr_code.make_image()
|
qr_img = qr_code.make_image()
|
||||||
im = qr_img._img.convert("RGB")
|
|
||||||
# Convert the RGB image in printable image
|
# Convert the RGB image in printable image
|
||||||
self._convert_image(im)
|
im = qr_img._img.convert("RGB")
|
||||||
|
self.image(im)
|
||||||
|
|
||||||
def barcode(self, code, bc, width, height, pos, font):
|
def barcode(self, code, bc, width, height, pos, font):
|
||||||
""" Print Barcode """
|
""" Print Barcode """
|
||||||
|
@ -177,9 +177,9 @@ class Escpos:
|
||||||
self._raw(BARCODE_TXT_BTH)
|
self._raw(BARCODE_TXT_BTH)
|
||||||
elif pos.upper() == "ABOVE":
|
elif pos.upper() == "ABOVE":
|
||||||
self._raw(BARCODE_TXT_ABV)
|
self._raw(BARCODE_TXT_ABV)
|
||||||
else: # DEFAULT POSITION: BELOW
|
else: # DEFAULT POSITION: BELOW
|
||||||
self._raw(BARCODE_TXT_BLW)
|
self._raw(BARCODE_TXT_BLW)
|
||||||
# Type
|
# Type
|
||||||
if bc.upper() == "UPC-A":
|
if bc.upper() == "UPC-A":
|
||||||
self._raw(BARCODE_UPC_A)
|
self._raw(BARCODE_UPC_A)
|
||||||
elif bc.upper() == "UPC-E":
|
elif bc.upper() == "UPC-E":
|
||||||
|
@ -202,11 +202,11 @@ class Escpos:
|
||||||
else:
|
else:
|
||||||
raise exception.BarcodeCodeError()
|
raise exception.BarcodeCodeError()
|
||||||
|
|
||||||
|
|
||||||
def text(self, txt):
|
def text(self, txt):
|
||||||
""" Print alpha-numeric text """
|
""" Print alpha-numeric text """
|
||||||
if txt:
|
if txt:
|
||||||
self._raw(txt)
|
self._raw(txt.encode('cp936'))
|
||||||
else:
|
else:
|
||||||
raise TextError()
|
raise TextError()
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Usb(Escpos):
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
self.in_ep = in_ep
|
self.in_ep = in_ep
|
||||||
self.out_ep = out_ep
|
self.out_ep = out_ep
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -9,7 +9,7 @@ setup(
|
||||||
download_url='http://python-escpos.googlecode.com/files/python-escpos-1.0.zip',
|
download_url='http://python-escpos.googlecode.com/files/python-escpos-1.0.zip',
|
||||||
description='Python library to manipulate ESC/POS Printers',
|
description='Python library to manipulate ESC/POS Printers',
|
||||||
license='GNU GPL v3',
|
license='GNU GPL v3',
|
||||||
long_description=open('README').read(),
|
long_description=open('README.md').read(),
|
||||||
author='Manuel F Martinez',
|
author='Manuel F Martinez',
|
||||||
author_email='manpaz@bashlinux.com',
|
author_email='manpaz@bashlinux.com',
|
||||||
platforms=['linux'],
|
platforms=['linux'],
|
||||||
|
|
Loading…
Reference in New Issue