mirror of
https://github.com/python-escpos/python-escpos
synced 2025-09-13 09:09:58 +00:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
37d7f34241 | ||
![]() |
280000d6ed | ||
![]() |
95082067e4 | ||
![]() |
f0f84e1215 | ||
![]() |
cae02976a3 | ||
![]() |
9550ad1068 | ||
![]() |
e623799fd7 | ||
![]() |
47aa4a96c9 | ||
![]() |
bb329b093b | ||
![]() |
d93e76e904 | ||
![]() |
f3933d5d20 | ||
![]() |
517435efad | ||
![]() |
122ff9a363 | ||
![]() |
708f7e97d1 | ||
![]() |
8a3850ea64 | ||
![]() |
34f562d64a |
15
CHANGELOG
15
CHANGELOG
@@ -18,5 +18,20 @@ CHANGELOG
|
||||
- Added exception for PIL import
|
||||
|
||||
* 2014-05-20 - Version 1.0.4
|
||||
- Issue #20: Added Density support (Sent by thomas.erbacher@ragapack.de)
|
||||
- Added charcode tables
|
||||
- Fixed Horizontal Tab
|
||||
- Fixed code tabulators
|
||||
|
||||
* 2015-04-21 - Version 1.0.5
|
||||
- Merge pull request #45 from Krispy2009/master
|
||||
. Raising the right error when wrong charcode is used
|
||||
. Sent by Krispy2009@gmail.com
|
||||
|
||||
* 2015-07-06 - Version 1.0.6
|
||||
- Merge pull request #53 from ldos/master
|
||||
. Extended params for serial printers
|
||||
. Sent by cafeteria.ldosalzira@gmail.com
|
||||
|
||||
* 2015-08-22 - Version 1.0.7
|
||||
- Issue #57: Fixed transparent images
|
||||
|
6
README
6
README
@@ -72,7 +72,7 @@ The following example shows how to initialize the Epson TM-TI88IV
|
||||
from escpos import *
|
||||
|
||||
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """
|
||||
Epson = escpos.Escpos(0x04b8,0x0202,0)
|
||||
Epson = escpos.Escpos(0x04b8,0x0202)
|
||||
Epson.text("Hello World")
|
||||
Epson.image("logo.gif")
|
||||
Epson.barcode
|
||||
@@ -82,8 +82,8 @@ The following example shows how to initialize the Epson TM-TI88IV
|
||||
------------------------------------------------------------------
|
||||
5. Links
|
||||
|
||||
Please visit project homepage at:
|
||||
http://repo.bashlinux.com/projects/escpos.html
|
||||
Please visit project documentation at:
|
||||
https://github.com/manpaz/python-escpos/wiki
|
||||
|
||||
Manuel F Martinez <manpaz@bashlinux.com>
|
||||
|
||||
|
@@ -21,6 +21,7 @@ PAPER_PART_CUT = '\x1d\x56\x01' # Partial cut paper
|
||||
TXT_NORMAL = '\x1b\x21\x00' # Normal text
|
||||
TXT_2HEIGHT = '\x1b\x21\x10' # Double height text
|
||||
TXT_2WIDTH = '\x1b\x21\x20' # Double width text
|
||||
TXT_4SQUARE = '\x1b\x21\x30' # Quad area text
|
||||
TXT_UNDERL_OFF = '\x1b\x2d\x00' # Underline font OFF
|
||||
TXT_UNDERL_ON = '\x1b\x2d\x01' # Underline font 1-dot ON
|
||||
TXT_UNDERL2_ON = '\x1b\x2d\x02' # Underline font 2-dot ON
|
||||
@@ -73,3 +74,13 @@ S_RASTER_N = '\x1d\x76\x30\x00' # Set raster image normal size
|
||||
S_RASTER_2W = '\x1d\x76\x30\x01' # Set raster image double width
|
||||
S_RASTER_2H = '\x1d\x76\x30\x02' # Set raster image double height
|
||||
S_RASTER_Q = '\x1d\x76\x30\x03' # Set raster image quadruple
|
||||
# Printing Density
|
||||
PD_N50 = '\x1d\x7c\x00' # Printing Density -50%
|
||||
PD_N37 = '\x1d\x7c\x01' # Printing Density -37.5%
|
||||
PD_N25 = '\x1d\x7c\x02' # Printing Density -25%
|
||||
PD_N12 = '\x1d\x7c\x03' # Printing Density -12.5%
|
||||
PD_0 = '\x1d\x7c\x04' # Printing Density 0%
|
||||
PD_P50 = '\x1d\x7c\x08' # Printing Density +50%
|
||||
PD_P37 = '\x1d\x7c\x07' # Printing Density +37.5%
|
||||
PD_P25 = '\x1d\x7c\x06' # Printing Density +25%
|
||||
PD_P12 = '\x1d\x7c\x05' # Printing Density +12.5%
|
||||
|
@@ -3,7 +3,7 @@
|
||||
@author: Manuel F Martinez <manpaz@bashlinux.com>
|
||||
@organization: Bashlinux
|
||||
@copyright: Copyright (c) 2012 Bashlinux
|
||||
@license: GPL
|
||||
@license: GNU GPL v3
|
||||
"""
|
||||
|
||||
try:
|
||||
@@ -107,7 +107,15 @@ class Escpos:
|
||||
def image(self,path_img):
|
||||
""" Open image file """
|
||||
im_open = Image.open(path_img)
|
||||
|
||||
# Remove the alpha channel on transparent images
|
||||
if im_open.mode == 'RGBA':
|
||||
im_open.load()
|
||||
im = Image.new("RGB", im_open.size, (255, 255, 255))
|
||||
im.paste(im_open, mask=im_open.split()[3])
|
||||
else:
|
||||
im = im_open.convert("RGB")
|
||||
|
||||
# Convert the RGB image in printable image
|
||||
self._convert_image(im)
|
||||
|
||||
@@ -119,6 +127,7 @@ class Escpos:
|
||||
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)
|
||||
|
||||
@@ -168,7 +177,7 @@ class Escpos:
|
||||
elif code.upper() == "THAI18":
|
||||
self._raw(CHARCODE_THAI18)
|
||||
else:
|
||||
raise CharCode_error()
|
||||
raise CharCodeError()
|
||||
|
||||
def barcode(self, code, bc, width, height, pos, font):
|
||||
""" Print Barcode """
|
||||
@@ -230,12 +239,12 @@ class Escpos:
|
||||
raise TextError()
|
||||
|
||||
|
||||
def set(self, align='left', font='a', type='normal', width=1, height=1):
|
||||
def set(self, align='left', font='a', type='normal', width=1, height=1, density=9):
|
||||
""" Set text properties """
|
||||
# Width
|
||||
if height == 2 and width == 2:
|
||||
self._raw(TXT_2WIDTH)
|
||||
self._raw(TXT_2HEIGHT)
|
||||
self._raw(TXT_NORMAL)
|
||||
self._raw(TXT_4SQUARE)
|
||||
elif height == 2 and width != 2:
|
||||
self._raw(TXT_NORMAL)
|
||||
self._raw(TXT_2HEIGHT)
|
||||
@@ -254,7 +263,6 @@ class Escpos:
|
||||
elif type.upper() == "U2":
|
||||
self._raw(TXT_BOLD_OFF)
|
||||
self._raw(TXT_UNDERL2_ON)
|
||||
self._raw(TXT_ITALIC_OFF)
|
||||
elif type.upper() == "BU":
|
||||
self._raw(TXT_BOLD_ON)
|
||||
self._raw(TXT_UNDERL_ON)
|
||||
@@ -276,6 +284,27 @@ class Escpos:
|
||||
self._raw(TXT_ALIGN_RT)
|
||||
elif align.upper() == "LEFT":
|
||||
self._raw(TXT_ALIGN_LT)
|
||||
# Density
|
||||
if density == 0:
|
||||
self._raw(PD_N50)
|
||||
elif density == 1:
|
||||
self._raw(PD_N37)
|
||||
elif density == 2:
|
||||
self._raw(PD_N25)
|
||||
elif density == 3:
|
||||
self._raw(PD_N12)
|
||||
elif density == 4:
|
||||
self._raw(PD_0)
|
||||
elif density == 5:
|
||||
self._raw(PD_P12)
|
||||
elif density == 6:
|
||||
self._raw(PD_P25)
|
||||
elif density == 7:
|
||||
self._raw(PD_P37)
|
||||
elif density == 8:
|
||||
self._raw(PD_P50)
|
||||
else:# DEFAULT: DOES NOTHING
|
||||
pass
|
||||
|
||||
|
||||
def cut(self, mode=''):
|
||||
|
@@ -3,7 +3,7 @@
|
||||
@author: Manuel F Martinez <manpaz@bashlinux.com>
|
||||
@organization: Bashlinux
|
||||
@copyright: Copyright (c) 2012 Bashlinux
|
||||
@license: GPL
|
||||
@license: GNU GPL v3
|
||||
"""
|
||||
|
||||
import usb.core
|
||||
@@ -69,23 +69,39 @@ class Usb(Escpos):
|
||||
class Serial(Escpos):
|
||||
""" Define Serial printer """
|
||||
|
||||
def __init__(self, devfile="/dev/ttyS0", baudrate=9600, bytesize=8, timeout=1):
|
||||
def __init__(self, devfile="/dev/ttyS0", baudrate=9600, bytesize=8, timeout=1,
|
||||
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
|
||||
xonxoff=False , dsrdtr=True):
|
||||
"""
|
||||
@param devfile : Device file under dev filesystem
|
||||
@param baudrate : Baud rate for serial transmission
|
||||
@param bytesize : Serial buffer size
|
||||
@param timeout : Read/Write timeout
|
||||
|
||||
@param parity : Parity checking
|
||||
@param stopbits : Number of stop bits
|
||||
@param xonxoff : Software flow control
|
||||
@param dsrdtr : Hardware flow control (False to enable RTS/CTS)
|
||||
"""
|
||||
self.devfile = devfile
|
||||
self.baudrate = baudrate
|
||||
self.bytesize = bytesize
|
||||
self.timeout = timeout
|
||||
|
||||
self.parity = parity
|
||||
self.stopbits = stopbits
|
||||
self.xonxoff = xonxoff
|
||||
self.dsrdtr = dsrdtr
|
||||
|
||||
self.open()
|
||||
|
||||
|
||||
def open(self):
|
||||
""" Setup serial port and set is as escpos device """
|
||||
self.device = serial.Serial(port=self.devfile, baudrate=self.baudrate, bytesize=self.bytesize, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=self.timeout, dsrdtr=True)
|
||||
self.device = serial.Serial(port=self.devfile, baudrate=self.baudrate,
|
||||
bytesize=self.bytesize, parity=self.parity,
|
||||
stopbits=self.stopbits, timeout=self.timeout,
|
||||
xonxoff=self.xonxoff, dsrdtr=self.dsrdtr)
|
||||
|
||||
if self.device is not None:
|
||||
print "Serial printer enabled"
|
||||
|
6
setup.py
6
setup.py
@@ -4,9 +4,9 @@ from distutils.core import setup
|
||||
|
||||
setup(
|
||||
name='escpos',
|
||||
version='1.0.4',
|
||||
url='http://code.google.com/p/python-escpos',
|
||||
download_url='http://python-escpos.googlecode.com/files/python-escpos-1.0.zip',
|
||||
version='1.0.7',
|
||||
url='https://github.com/manpaz/python-escpos',
|
||||
download_url='https://github.com/manpaz/python-escpos.git',
|
||||
description='Python library to manipulate ESC/POS Printers',
|
||||
license='GNU GPL v3',
|
||||
long_description=open('README').read(),
|
||||
|
Reference in New Issue
Block a user