dibbler/text_interface/printermenu.py

35 lines
1.1 KiB
Python
Raw Normal View History

2017-04-15 20:47:28 +02:00
import re
2017-03-25 16:59:47 +01:00
from db import Product, User
from printer_helpers import print_bar_code, print_name_label
2017-03-22 18:02:11 +01:00
from text_interface.helpermenus import Menu
import conf
class PrintLabelMenu(Menu):
def __init__(self):
2017-03-25 17:02:29 +01:00
Menu.__init__(self, 'Print a label', uses_db=True)
2017-03-22 18:02:11 +01:00
self.help_text = '''
Prints out a product bar code on the printer
Put it up somewhere in the vicinity.
'''
def _execute(self):
self.print_header()
thing = self.input_thing('Product/User')
2017-03-25 16:59:47 +01:00
if isinstance(thing, Product):
2017-04-15 20:47:28 +02:00
if re.match(r"^[0-9]{13}$", thing.bar_code):
bar_type = "ean13"
2017-04-15 20:47:28 +02:00
elif re.match(r"^[0-9]{8}$", thing.bar_code):
bar_type = "ean8"
else:
bar_type = "code39"
print_bar_code(thing.bar_code, thing.name, barcode_type=bar_type, rotate=conf.label_rotate,
2017-03-25 16:59:47 +01:00
printer_type="QL-700", label_type=conf.label_type)
elif isinstance(thing, User):
print_name_label(text=thing.name, label_type=conf.label_type, rotate=conf.label_rotate,
printer_type="QL-700")