Update barcode printing to allow for barcode function type B
This commit is contained in:
parent
60bc6b7d5c
commit
5c49e0103c
|
@ -314,12 +314,13 @@ class Escpos(object):
|
||||||
else:
|
else:
|
||||||
raise CharCodeError()
|
raise CharCodeError()
|
||||||
|
|
||||||
def barcode(self, code, bc, height=64, width=3, pos="BELOW", font="A", align_ct=True):
|
def barcode(self, code, bc, height=64, width=3, pos="BELOW", font="A", align_ct=True, function_type="A"):
|
||||||
""" Print Barcode
|
""" Print Barcode
|
||||||
|
|
||||||
This method allows to print barcodes. The rendering of the barcode is done by the printer and therefore has to
|
This method allows to print barcodes. The rendering of the barcode is done by the printer and therefore has to
|
||||||
be supported by the unit. Currently you have to check manually whether your barcode text is correct. Uncorrect
|
be supported by the unit. Currently you have to check manually whether your barcode text is correct. Uncorrect
|
||||||
barcodes may lead to unexpected printer behaviour.
|
barcodes may lead to unexpected printer behaviour. There are two forms of the barcode function. Type A is
|
||||||
|
default but has fewer barcodes, while type B has some more to choose from.
|
||||||
|
|
||||||
.. todo:: Add a method to check barcode codes. Alternatively or as an addition write explanations about each
|
.. todo:: Add a method to check barcode codes. Alternatively or as an addition write explanations about each
|
||||||
barcode-type. Research whether the check digits can be computed autmatically.
|
barcode-type. Research whether the check digits can be computed autmatically.
|
||||||
|
@ -340,7 +341,7 @@ class Escpos(object):
|
||||||
be of help if the printer does not support types that others do.)
|
be of help if the printer does not support types that others do.)
|
||||||
|
|
||||||
:param code: alphanumeric data to be printed as bar code
|
:param code: alphanumeric data to be printed as bar code
|
||||||
:param bc: barcode format, possible values are:
|
:param bc: barcode format, possible values are for type A are:
|
||||||
|
|
||||||
* UPC-A
|
* UPC-A
|
||||||
* UPC-E
|
* UPC-E
|
||||||
|
@ -350,6 +351,17 @@ class Escpos(object):
|
||||||
* ITF
|
* ITF
|
||||||
* NW7
|
* NW7
|
||||||
|
|
||||||
|
Possible values for type B:
|
||||||
|
|
||||||
|
* All types from function type A
|
||||||
|
* CODE93
|
||||||
|
* CODE128
|
||||||
|
* GS1-128
|
||||||
|
* GS1 DataBar Omnidirectional
|
||||||
|
* GS1 DataBar Truncated
|
||||||
|
* GS1 DataBar Limited
|
||||||
|
* GS1 DataBar Expanded
|
||||||
|
|
||||||
If none is specified, the method raises :py:exc:`~escpos.exceptions.BarcodeTypeError`.
|
If none is specified, the method raises :py:exc:`~escpos.exceptions.BarcodeTypeError`.
|
||||||
:param height: barcode height, has to be between 1 and 255
|
:param height: barcode height, has to be between 1 and 255
|
||||||
*default*: 64
|
*default*: 64
|
||||||
|
@ -373,6 +385,10 @@ class Escpos(object):
|
||||||
issued.
|
issued.
|
||||||
:type align_ct: bool
|
:type align_ct: bool
|
||||||
|
|
||||||
|
:param function_type: Choose between ESCPOS function type A or B, depending on printer support and desired
|
||||||
|
barcode.
|
||||||
|
*default*: A
|
||||||
|
|
||||||
:raises: :py:exc:`~escpos.exceptions.BarcodeSizeError`,
|
:raises: :py:exc:`~escpos.exceptions.BarcodeSizeError`,
|
||||||
:py:exc:`~escpos.exceptions.BarcodeTypeError`,
|
:py:exc:`~escpos.exceptions.BarcodeTypeError`,
|
||||||
:py:exc:`~escpos.exceptions.BarcodeCodeError`
|
:py:exc:`~escpos.exceptions.BarcodeCodeError`
|
||||||
|
@ -404,23 +420,20 @@ class Escpos(object):
|
||||||
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
|
|
||||||
if bc.upper() == "UPC-A":
|
bc_types = BARCODE_TYPES[function_type]
|
||||||
self._raw(BARCODE_UPC_A)
|
if bc.upper() not in bc_types.keys():
|
||||||
elif bc.upper() == "UPC-E":
|
# TODO: Raise a better error, or fix the message of this error type
|
||||||
self._raw(BARCODE_UPC_E)
|
raise BarcodeTypeError("Barcode type {bc} not valid for barcode function type {function_type}".format(
|
||||||
elif bc.upper() == "EAN13":
|
bc=bc,
|
||||||
self._raw(BARCODE_EAN13)
|
function_type=function_type,
|
||||||
elif bc.upper() == "EAN8":
|
))
|
||||||
self._raw(BARCODE_EAN8)
|
|
||||||
elif bc.upper() == "CODE39":
|
self._raw(bc_types[bc.upper()])
|
||||||
self._raw(BARCODE_CODE39)
|
|
||||||
elif bc.upper() == "ITF":
|
if function_type.upper() == "B":
|
||||||
self._raw(BARCODE_ITF)
|
self._raw(chr(len(code)))
|
||||||
elif bc.upper() in ("NW7", "CODABAR"):
|
|
||||||
self._raw(BARCODE_NW7)
|
|
||||||
else:
|
|
||||||
raise BarcodeTypeError(bc)
|
|
||||||
# Print Code
|
# Print Code
|
||||||
if code:
|
if code:
|
||||||
self._raw(code)
|
self._raw(code)
|
||||||
|
|
Loading…
Reference in New Issue