Tools¶
Few helpers, and they are free :)
Constants¶
-
thermalprinter.tools.
ls
(*constants)¶ Parameters: *constants (list) – constants to print. Print a list of constants and their values.
>>> ls() All constants will be printed here.
You can print only constants you want too:
>>> from thermalprinter.constants import Chinese, CodePage >>> ls(Chinese) Chinese values will be prited here. >>> ls(Chinese, CodePage) Chinese and CodePage values will be prited here.
Tests¶
Code pages¶
-
thermalprinter.tools.
test_char
(char)¶ Parameters: char (bytes) – bytes to print. Test one character with all possible code page. Say you are looking for the good code page to print a sequence, you can print it using every code pages:
>>> test_char(b'现')
This function is as simple as:
for codepage in list(CodePage): printer.out('{}: {}'.format(codepage.name, char), codepage=codepage)
Data validation¶
These are special functions to handle data validation. As it could take a lot of lines and logic, we prefered create them outsite the class to keep a light code for every ThermalPrinter
’s methods.
-
thermalprinter.validate.
validate_barcode
(data, barcode_type) → None¶ Parameters: - data (mixed) – data to print.
- barecode_type (BarCode) – bar code type to use.
Raises: - ThermalPrinterValueError – On incorrect
data
’s type or value. - ThermalPrinterConstantError – On bad
barecode_type
’s type.
Validate data against the bar code type.
-
thermalprinter.validate.
validate_barcode_position
(position) → None¶ Parameters: position (BarCodePosition) – the position to use. Raises: ThermalPrinterConstantError – On bad position
’s type.Validate a bar code position.
-
thermalprinter.validate.
validate_charset
(charset) → None¶ Parameters: charset (CharSet) – new charset to use. Raises: ThermalPrinterConstantError – On bad charset
’s type.Validate a charset.
-
thermalprinter.validate.
validate_chinese_format
(fmt) → None¶ Parameters: fmt (Chinese) – new format to use. Raises: ThermalPrinterConstantError – On bad fmt
’s type.Validate a Chinese format.
-
thermalprinter.validate.
validate_codepage
(codepage) → None¶ Parameters: codepage (CodePage) – new code page to use. Raises: ThermalPrinterConstantError – On bad codepage
’s type.Validate a code page.