brother_ql_info: modified CLI, highly improved list-label-sizes output
This commit is contained in:
@@ -68,10 +68,10 @@ giving:
|
||||
-h, --help show this help message and exit
|
||||
--model MODEL, -m MODEL
|
||||
The printer model to use. Check available ones with
|
||||
`brother_ql_info --list-models`.
|
||||
`brother_ql_info list-models`.
|
||||
--label-size LABEL_SIZE, -s LABEL_SIZE
|
||||
The label size (and kind) to use. Check available ones
|
||||
with `brother_ql_info --list-label-sizes`.
|
||||
with `brother_ql_info list-label-sizes`.
|
||||
--threshold THRESHOLD, -t THRESHOLD
|
||||
The threshold value (in percent) to discriminate
|
||||
between black and white pixels.
|
||||
|
||||
@@ -27,8 +27,8 @@ def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('image', help='The image file to create a label from.')
|
||||
parser.add_argument('outfile', nargs='?', type=argparse.FileType('wb'), default=stdout, help='The file to write the instructions to. Defaults to stdout.')
|
||||
parser.add_argument('--model', '-m', default='QL-500', help='The printer model to use. Check available ones with `brother_ql_info --list-models`.')
|
||||
parser.add_argument('--label-size', '-s', default='62', help='The label size (and kind) to use. Check available ones with `brother_ql_info --list-label-sizes`.')
|
||||
parser.add_argument('--model', '-m', default='QL-500', help='The printer model to use. Check available ones with `brother_ql_info list-models`.')
|
||||
parser.add_argument('--label-size', '-s', default='62', help='The label size (and kind) to use. Check available ones with `brother_ql_info list-label-sizes`.')
|
||||
parser.add_argument('--threshold', '-t', type=float, default=70.0, help='The threshold value (in percent) to discriminate between black and white pixels.')
|
||||
parser.add_argument('--no-cut', dest='cut', action='store_false', help="Don't cut the tape after printing the label.")
|
||||
parser.add_argument('--loglevel', type=lambda x: getattr(logging, x), default=logging.WARNING, help='Set to DEBUG for verbose debugging output to stderr.')
|
||||
@@ -42,12 +42,12 @@ def main():
|
||||
try:
|
||||
qlr = BrotherQLRaster(args.model)
|
||||
except BrotherQLUnknownModel:
|
||||
sys.exit("Unknown model. Use the command brother_ql_info --list-models to show available models.")
|
||||
sys.exit("Unknown model. Use the command brother_ql_info list-models to show available models.")
|
||||
|
||||
try:
|
||||
label_type_specs[args.label_size]
|
||||
except ValueError:
|
||||
sys.exit("Unknown label_size. Check available sizes with the command brother_ql_info --list-label-sizes")
|
||||
sys.exit("Unknown label_size. Check available sizes with the command brother_ql_info list-label-sizes")
|
||||
|
||||
qlr.exception_on_warning = True
|
||||
|
||||
|
||||
@@ -6,23 +6,33 @@ from brother_ql.devicedependent import models, label_sizes, label_type_specs, DI
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--list-label-sizes', action='store_true', help='List available label sizes')
|
||||
parser.add_argument('--list-models', action='store_true', help='List available models')
|
||||
subparser = parser.add_subparsers(dest='action')
|
||||
subparser.add_parser('list-label-sizes', help='List available label sizes')
|
||||
subparser.add_parser('list-models', help='List available models')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.list_models:
|
||||
if not args.action:
|
||||
parser.error('Please choose an action')
|
||||
|
||||
elif args.action == 'list-models':
|
||||
print('Supported models:')
|
||||
for model in models: print(" " + model)
|
||||
|
||||
if args.list_label_sizes:
|
||||
elif args.action == 'list-label-sizes':
|
||||
print('Supported label sizes:')
|
||||
fmt = " {label_size:9s} {dots_printable:14s} {label_descr:26s}"
|
||||
print(fmt.format(label_size="Name", label_descr="Description", dots_printable="Printable px"))
|
||||
for label_size in label_sizes:
|
||||
s = label_type_specs[label_size]
|
||||
descr = " %-10s " % label_size
|
||||
if s['kind'] == DIE_CUT_LABEL: descr += "(%d x %d mm^2)" % s['tape_size']
|
||||
if s['kind'] == ENDLESS_LABEL: descr += "(%d mm endless)" % s['tape_size'][0]
|
||||
if s['kind'] == ROUND_DIE_CUT_LABEL: descr += "(%d mm diameter, round)" % s['tape_size'][0]
|
||||
print(descr)
|
||||
|
||||
if s['kind'] == DIE_CUT_LABEL:
|
||||
label_descr = "(%d x %d mm^2)" % s['tape_size']
|
||||
dots_printable = "{0:4d} x {1:4d}".format(*s['dots_printable'])
|
||||
if s['kind'] == ENDLESS_LABEL:
|
||||
label_descr = "(%d mm endless)" % s['tape_size'][0]
|
||||
dots_printable = "{0:4d}".format(*s['dots_printable'])
|
||||
if s['kind'] == ROUND_DIE_CUT_LABEL:
|
||||
label_descr = "(%d mm diameter, round)" % s['tape_size'][0]
|
||||
dots_printable = "{0:4d} x {1:4d}".format(*s['dots_printable'])
|
||||
print(fmt.format(label_size=label_size, label_descr=label_descr, dots_printable=dots_printable))
|
||||
|
||||
if __name__ == "__main__": main()
|
||||
|
||||
Reference in New Issue
Block a user