From 5617571f310581793267117019669617851b591c Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 01:46:24 +0800 Subject: [PATCH 1/7] tab -> spaces --- escpos/printer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escpos/printer.py b/escpos/printer.py index 4b2088b..640c3f4 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -31,7 +31,7 @@ class Usb(Escpos): self.interface = interface self.in_ep = in_ep self.out_ep = out_ep - self.open() + self.open() def open(self): From 442e523956f982765854c5dc8118f6872c45b011 Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 01:48:12 +0800 Subject: [PATCH 2/7] fix README path --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4388292..27197d0 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( download_url='http://python-escpos.googlecode.com/files/python-escpos-1.0.zip', description='Python library to manipulate ESC/POS Printers', license='GNU GPL v3', - long_description=open('README').read(), + long_description=open('README.md').read(), author='Manuel F Martinez', author_email='manpaz@bashlinux.com', platforms=['linux'], From b68b3dc6c0768f96de5446d795f6447f19b91f1d Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 01:51:14 +0800 Subject: [PATCH 3/7] import Image from PIL, or Pillow --- escpos/escpos.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index 85be2e3..3389c93 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -6,11 +6,11 @@ @license: GPL ''' -import Image import qrcode import time import os import operator +from PIL import Image from constants import * from exceptions import * @@ -37,7 +37,7 @@ class Escpos: i = 0 cont = 0 buffer = "" - + self._raw(S_RASTER_N) buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1], 0) self._raw(buffer.decode('hex')) @@ -135,7 +135,7 @@ class Escpos: break elif im_color > (255 * 3 / pattern_len * pattern_len) and im_color <= (255 * 3): pix_line += im_pattern[-1] - break + break pix_line += im_right img_size[0] += im_border[1] @@ -177,9 +177,9 @@ class Escpos: self._raw(BARCODE_TXT_BTH) elif pos.upper() == "ABOVE": self._raw(BARCODE_TXT_ABV) - else: # DEFAULT POSITION: BELOW + else: # DEFAULT POSITION: BELOW self._raw(BARCODE_TXT_BLW) - # Type + # Type if bc.upper() == "UPC-A": self._raw(BARCODE_UPC_A) elif bc.upper() == "UPC-E": @@ -202,7 +202,7 @@ class Escpos: else: raise exception.BarcodeCodeError() - + def text(self, txt): """ Print alpha-numeric text """ if txt: From 9f7e5861cd00e85556bae077eebaf8445e239b07 Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 01:58:55 +0800 Subject: [PATCH 4/7] adjust import order and fix `qr` method --- escpos/escpos.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index 3389c93..ed9b3d3 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -6,9 +6,9 @@ @license: GPL ''' -import qrcode -import time import os +import time +import qrcode import operator from PIL import Image @@ -141,15 +141,15 @@ class Escpos: self._print_image(pix_line, img_size) - def qr(self,text): + def qr(self, text): """ Print QR Code for the provided string """ qr_code = qrcode.QRCode(version=4, box_size=4, border=1) qr_code.add_data(text) qr_code.make(fit=True) qr_img = qr_code.make_image() - im = qr_img._img.convert("RGB") # 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): """ Print Barcode """ From 6a4fbc191fea62f07e25a58f077ec74ab3967f7e Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 02:05:41 +0800 Subject: [PATCH 5/7] add Chinese support via cp936 --- escpos/escpos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index ed9b3d3..c5457b9 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -206,7 +206,7 @@ class Escpos: def text(self, txt): """ Print alpha-numeric text """ if txt: - self._raw(txt) + self._raw(txt.encode('cp936')) else: raise TextError() From 0590ec90a28c8072dfd413398da10c9201e4c1fe Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 02:09:10 +0800 Subject: [PATCH 6/7] use my own examples --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c912612..f4367a6 100644 --- a/README.md +++ b/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: * pyusb (python-usb) - * PIL (Python Image Library) + * PIL (Python Image Library) or Pillow (recommended) 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 you will endup with weird chars being printed. - from escpos import * - - """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ - Epson = escpos.Escpos(0x04b8,0x0202,0) - Epson.text("Hello World") - Epson.image("logo.gif") - Epson.fullimage("a.really.large.image.png") - Epson.barcode - Epson.barcode('1324354657687','EAN13',64,2,'','') - Epson.cut() + from escpos import printer + + p = printer.Usb(0x04b8, 0x0202) + p.text("Hello World") + p.image("logo.gif") + p.fullimage("a.really.large.image.png") + p.barcode('1324354657687','EAN13',64,2,'','') + p.qr('this is a piece of code') + p.cut() 5. Links ------------------------------------------------------------------ From 8c115bce27656be6dcbcd8971839878cf4ed2e38 Mon Sep 17 00:00:00 2001 From: freeyoung Date: Fri, 14 Mar 2014 02:20:57 +0800 Subject: [PATCH 7/7] use doge.jpg as the example of p.image --- README.md | 2 +- doge.jpg | Bin 0 -> 8795 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 doge.jpg diff --git a/README.md b/README.md index f4367a6..0dc4f5c 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ The following example shows how to initialize the Epson TM-TI88IV p = printer.Usb(0x04b8, 0x0202) p.text("Hello World") - p.image("logo.gif") + p.image("doge.jpg") p.fullimage("a.really.large.image.png") p.barcode('1324354657687','EAN13',64,2,'','') p.qr('this is a piece of code') diff --git a/doge.jpg b/doge.jpg new file mode 100644 index 0000000000000000000000000000000000000000..555d7d73ec9a7cf5f295be753ca16c77c416a75a GIT binary patch literal 8795 zcmbVxcQ{<%_wE@+7hQBwMs(3j^oTNQh#Ewq1QAAw8ltx`+K3T7I?+NfTJ-2dbffp^ z1`!hB=hMFBd4Bgk_qpfnzvirS_TFpl^{#ilb2WXn1W;(ILDc{d2mnCWH*hrzr~ric z_yqWPgaiZxL_~zdq%=23Nk~W;sHn+lSQu}yvM@3;vq6No**F9^nVET{cm;$-#KpyL zam&a{i^>U!iHlyf0VIUL6>tRtQ36+8z^&_#}^mIA;5 z;o{*oNN5|4^qL>Zr2|0w~78;xjiVh$nay{dLvgRh4WF>Ch_BI28L z^bCw#x4C(E`NSn8rKDx!6O&WZGnnO- z)wT7F&2L-V*rVf<@25Y`&VOEE0Kz}qrU?A_$&(BJzYPAER;*X8Z`t-;@30yt9ewd} zt6Iw;AM5xpH&SZ#5+YLU17;t5m`6O>_R;%{dd)wUW}3A7W5n6KNz!$XM7TepGcq=E z5P7G6pm(1@S(Qfre;K~nojb+m?T@sl8Uyl2&zc@Kp?(|aL(KEd))aXK2xo|Mv=JUn z3CaztBs7OpF)!npXL`VVb~>_;yzCJ2HD$%fCbXVl$4drIAffbe@Lw}nWVNnXLTl9y ze}wJr-I3^07932m3ol35Cm(AbSz^PLhZStXnU9apT=qR+@&{d&6p|%OQJjr6vFsm? zoBMG1yQ9~u$if-Sj?ABDz*H+j+aCQsEiagN{JE-r1rXsUx=wm8(>+OuGq8Ky#Nw** zRGIw)P*MF~zC6AH!ftv~`rrOqZYMS~ry{VT%7a^CULwVbPr%Uruv<-+P@40@l(>^3 z#W(Lp)t|81rs!OMKyx!sNEsB|PQX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