2023-08-14 23:03:36 +00:00
|
|
|
"""Prints code page tables."""
|
2016-08-26 09:49:42 +00:00
|
|
|
|
2017-01-30 02:00:23 +00:00
|
|
|
|
2016-08-26 09:49:42 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from escpos import printer
|
2021-10-30 16:15:22 +00:00
|
|
|
from escpos.constants import (
|
|
|
|
CODEPAGE_CHANGE,
|
|
|
|
CTL_CR,
|
2023-08-14 23:03:36 +00:00
|
|
|
CTL_FF,
|
2021-10-30 16:15:22 +00:00
|
|
|
CTL_HT,
|
2023-08-14 23:03:36 +00:00
|
|
|
CTL_LF,
|
2021-10-30 16:15:22 +00:00
|
|
|
CTL_VT,
|
2023-08-14 23:03:36 +00:00
|
|
|
ESC,
|
2021-10-30 16:15:22 +00:00
|
|
|
)
|
2016-08-26 09:49:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Init printer and print codepage tables."""
|
2016-08-26 09:49:42 +00:00
|
|
|
dummy = printer.Dummy()
|
|
|
|
|
2021-10-30 16:15:22 +00:00
|
|
|
dummy.hw("init")
|
2016-08-26 09:49:42 +00:00
|
|
|
|
2021-10-30 16:15:22 +00:00
|
|
|
for codepage in sys.argv[1:] or ["USA"]:
|
2016-08-26 09:49:42 +00:00
|
|
|
dummy.set(height=2, width=2)
|
2017-01-29 22:39:26 +00:00
|
|
|
dummy._raw(codepage + "\n\n\n")
|
2016-08-26 09:49:42 +00:00
|
|
|
print_codepage(dummy, codepage)
|
|
|
|
dummy._raw("\n\n")
|
|
|
|
|
|
|
|
dummy.cut()
|
|
|
|
|
2017-01-30 02:00:23 +00:00
|
|
|
print(dummy.output)
|
2016-08-26 09:49:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def print_codepage(printer, codepage):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Print a codepage."""
|
2016-08-26 09:49:42 +00:00
|
|
|
if codepage.isdigit():
|
|
|
|
codepage = int(codepage)
|
2023-12-16 21:02:24 +00:00
|
|
|
printer._raw(CODEPAGE_CHANGE + bytes((codepage,)))
|
2016-08-26 09:49:42 +00:00
|
|
|
printer._raw("after")
|
|
|
|
else:
|
|
|
|
printer.charcode(codepage)
|
|
|
|
|
|
|
|
sep = ""
|
|
|
|
|
|
|
|
# Table header
|
2021-10-30 16:15:22 +00:00
|
|
|
printer.set(font="b")
|
2023-12-10 23:34:29 +00:00
|
|
|
printer._raw(f" {sep.join(map(lambda s: hex(s)[2:], range(0, 16)))}\n")
|
2016-08-26 09:49:42 +00:00
|
|
|
printer.set()
|
|
|
|
|
|
|
|
# The table
|
2017-01-29 22:39:26 +00:00
|
|
|
for x in range(0, 16):
|
2016-08-26 09:49:42 +00:00
|
|
|
# First column
|
2021-10-30 16:15:22 +00:00
|
|
|
printer.set(font="b")
|
2023-12-10 23:34:29 +00:00
|
|
|
printer._raw(f"{hex(x)[2:]} ")
|
2016-08-26 09:49:42 +00:00
|
|
|
printer.set()
|
|
|
|
|
2017-01-29 23:10:14 +00:00
|
|
|
for y in range(0, 16):
|
2023-12-16 21:02:24 +00:00
|
|
|
byte = bytes(
|
|
|
|
(x * 16 + y),
|
|
|
|
)
|
2016-08-26 09:49:42 +00:00
|
|
|
|
|
|
|
if byte in (ESC, CTL_LF, CTL_FF, CTL_CR, CTL_HT, CTL_VT):
|
2021-10-30 16:15:22 +00:00
|
|
|
byte = " "
|
2016-08-26 09:49:42 +00:00
|
|
|
|
|
|
|
printer._raw(byte)
|
|
|
|
printer._raw(sep)
|
2021-10-30 16:15:22 +00:00
|
|
|
printer._raw("\n")
|
2016-08-26 09:49:42 +00:00
|
|
|
|
2017-01-29 23:10:14 +00:00
|
|
|
|
2021-10-30 16:15:22 +00:00
|
|
|
if __name__ == "__main__":
|
2017-01-29 23:10:14 +00:00
|
|
|
main()
|