Add text wrapping
* The base class supports to give columns, how much it should wrapped. * This is meant for longer text. * The special instances need to initialize the super class with the * columns
This commit is contained in:
parent
7da2e32e3c
commit
dd228c9fda
|
@ -13,6 +13,7 @@ except ImportError:
|
||||||
|
|
||||||
import qrcode
|
import qrcode
|
||||||
import time
|
import time
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from .constants import *
|
from .constants import *
|
||||||
from .exceptions import *
|
from .exceptions import *
|
||||||
|
@ -21,6 +22,8 @@ class Escpos:
|
||||||
""" ESC/POS Printer object """
|
""" ESC/POS Printer object """
|
||||||
device = None
|
device = None
|
||||||
|
|
||||||
|
def __init__(self, columns=32):
|
||||||
|
self.columns = columns
|
||||||
|
|
||||||
def _check_image_size(self, size):
|
def _check_image_size(self, size):
|
||||||
""" Check and fix the size of the image to 32 bits """
|
""" Check and fix the size of the image to 32 bits """
|
||||||
|
@ -229,6 +232,10 @@ class Escpos:
|
||||||
else:
|
else:
|
||||||
raise TextError()
|
raise TextError()
|
||||||
|
|
||||||
|
def block_text(self, txt, columns=None):
|
||||||
|
'''Text is printed wrapped to specified columns'''
|
||||||
|
colCount = self.columns if columns == None else columns
|
||||||
|
self.text(textwrap.fill(txt, colCount))
|
||||||
|
|
||||||
def set(self, align='left', font='a', type='normal', width=1, height=1, density=9):
|
def set(self, align='left', font='a', type='normal', width=1, height=1, density=9):
|
||||||
""" Set text properties """
|
""" Set text properties """
|
||||||
|
|
|
@ -18,7 +18,7 @@ from .exceptions import *
|
||||||
class Usb(Escpos):
|
class Usb(Escpos):
|
||||||
""" Define USB printer """
|
""" Define USB printer """
|
||||||
|
|
||||||
def __init__(self, idVendor, idProduct, interface=0, in_ep=0x82, out_ep=0x01):
|
def __init__(self, idVendor, idProduct, interface=0, in_ep=0x82, out_ep=0x01, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@param idVendor : Vendor ID
|
@param idVendor : Vendor ID
|
||||||
@param idProduct : Product ID
|
@param idProduct : Product ID
|
||||||
|
@ -26,6 +26,7 @@ class Usb(Escpos):
|
||||||
@param in_ep : Input end point
|
@param in_ep : Input end point
|
||||||
@param out_ep : Output end point
|
@param out_ep : Output end point
|
||||||
"""
|
"""
|
||||||
|
Escpos.__init__(self, *args, **kwargs)
|
||||||
self.idVendor = idVendor
|
self.idVendor = idVendor
|
||||||
self.idProduct = idProduct
|
self.idProduct = idProduct
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
|
@ -69,13 +70,14 @@ class Usb(Escpos):
|
||||||
class Serial(Escpos):
|
class Serial(Escpos):
|
||||||
""" Define Serial printer """
|
""" 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, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@param devfile : Device file under dev filesystem
|
@param devfile : Device file under dev filesystem
|
||||||
@param baudrate : Baud rate for serial transmission
|
@param baudrate : Baud rate for serial transmission
|
||||||
@param bytesize : Serial buffer size
|
@param bytesize : Serial buffer size
|
||||||
@param timeout : Read/Write timeout
|
@param timeout : Read/Write timeout
|
||||||
"""
|
"""
|
||||||
|
Escpos.__init__(self, *args, **kwargs)
|
||||||
self.devfile = devfile
|
self.devfile = devfile
|
||||||
self.baudrate = baudrate
|
self.baudrate = baudrate
|
||||||
self.bytesize = bytesize
|
self.bytesize = bytesize
|
||||||
|
@ -108,11 +110,12 @@ class Serial(Escpos):
|
||||||
class Network(Escpos):
|
class Network(Escpos):
|
||||||
""" Define Network printer """
|
""" Define Network printer """
|
||||||
|
|
||||||
def __init__(self,host,port=9100):
|
def __init__(self,host,port=9100, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@param host : Printer's hostname or IP address
|
@param host : Printer's hostname or IP address
|
||||||
@param port : Port to write to
|
@param port : Port to write to
|
||||||
"""
|
"""
|
||||||
|
Escpos.__init__(self, *args, **kwargs)
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.open()
|
self.open()
|
||||||
|
@ -141,10 +144,11 @@ class Network(Escpos):
|
||||||
class File(Escpos):
|
class File(Escpos):
|
||||||
""" Define Generic file printer """
|
""" Define Generic file printer """
|
||||||
|
|
||||||
def __init__(self, devfile="/dev/usb/lp0"):
|
def __init__(self, devfile="/dev/usb/lp0", *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@param devfile : Device file under dev filesystem
|
@param devfile : Device file under dev filesystem
|
||||||
"""
|
"""
|
||||||
|
Escpos.__init__(self, *args, **kwargs)
|
||||||
self.devfile = devfile
|
self.devfile = devfile
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue