Add demo functions

This commit is contained in:
Davis Goglin 2016-03-15 16:01:07 -07:00 committed by Davis Goglin
parent cdf8f6be09
commit 7d74dcac00
1 changed files with 300 additions and 220 deletions

View File

@ -9,6 +9,45 @@ import six
import os import os
from . import printer, config from . import printer, config
demo_functions = {
'text': [
{'txt': 'Hello, World!',}
],
'qr': [
{'text': 'This tests a QR code'},
{'text': 'https://en.wikipedia.org/'}
],
'barcodes_a': [
{'bc': 'UPC-A', 'code': '13243546576'},
{'bc': 'UPC-E', 'code': '132435'},
{'bc': 'EAN13', 'code': '1324354657687'},
{'bc': 'EAN8', 'code': '13243546'},
{'bc': 'CODE39', 'code': '*TEST*'},
{'bc': 'ITF', 'code': '55867492279103'},
{'bc': 'NW7', 'code': 'A00000000A'},
],
'barcodes_b': [
{'bc': 'UPC-A', 'code': '13243546576', 'function_type': 'B'},
{'bc': 'UPC-E', 'code': '132435', 'function_type': 'B'},
{'bc': 'EAN13', 'code': '1324354657687', 'function_type': 'B'},
{'bc': 'EAN8', 'code': '13243546', 'function_type': 'B'},
{'bc': 'CODE39', 'code': '*TEST*', 'function_type': 'B'},
{'bc': 'ITF', 'code': '55867492279103', 'function_type': 'B'},
{'bc': 'NW7', 'code': 'A00000000A', 'function_type': 'B'},
{'bc': 'CODE93', 'code': 'A00000000A', 'function_type': 'B'},
{'bc': 'CODE93', 'code': '1324354657687', 'function_type': 'B'},
{'bc': 'CODE128A', 'code': '*TEST*', 'function_type': 'B'},
{'bc': 'CODE128B', 'code': '*TEST*', 'function_type': 'B'},
{'bc': 'CODE128C', 'code': '*TEST*', 'function_type': 'B'},
{'bc': 'GS1-128', 'code': '00123456780000000001', 'function_type': 'B'},
{'bc': 'GS1 DataBar Omnidirectional', 'code': '0000000000000', 'function_type': 'B'},
{'bc': 'GS1 DataBar Truncated', 'code': '0000000000000', 'function_type': 'B'},
{'bc': 'GS1 DataBar Limited', 'code': '0000000000000', 'function_type': 'B'},
{'bc': 'GS1 DataBar Expanded', 'code': '00AAAAAAA', 'function_type': 'B'},
]
}
def main():
c = config.Config() c = config.Config()
printer = c.printer() printer = c.printer()
@ -238,6 +277,29 @@ parser_command_panel_buttons.add_argument(
required=True required=True
) )
parser_command_demo = command_subparsers.add_parser('demo', help='Demonstrates various functions')
parser_command_demo.set_defaults(func='demo')
demo_group = parser_command_demo.add_mutually_exclusive_group()
demo_group.add_argument(
'--barcodes-a',
help='Print demo barcodes for function type A',
action='store_true',
)
demo_group.add_argument(
'--barcodes-b',
help='Print demo barcodes for function type B',
action='store_true',
)
demo_group.add_argument(
'--qr',
help='Print some demo QR codes',
action='store_true',
)
demo_group.add_argument(
'--text',
help='Print some demo text',
action='store_true',
)
if not printer: if not printer:
raise Exception('No printers loaded from config') raise Exception('No printers loaded from config')
@ -248,5 +310,23 @@ command_arguments = dict([k, v] for k, v in six.iteritems(args_dict) if v)
target_command = command_arguments.pop('func') target_command = command_arguments.pop('func')
if hasattr(printer, target_command):
# print command with args # print command with args
getattr(printer, target_command)(**command_arguments) getattr(printer, target_command)(**command_arguments)
else:
command_arguments['printer'] = printer
globals()[target_command](**command_arguments)
def demo(printer, **kwargs):
for demo_choice in kwargs.keys():
command = getattr(
printer,
demo_choice
.replace('barcodes_a', 'barcode')
.replace('barcodes_b', 'barcode')
)
for params in demo_functions[demo_choice]:
command(**params)
if __name__ == '__main__':
main()