Use argparse for tweaking stuff

Not tested thoroughly, but I can sort my users, so I'm happy.
master
LEdoian 7 months ago
parent eaef4a72ae
commit 3f24b2cfab

@ -4,6 +4,7 @@ from triditko.renderers import DrawItemNameRenderer
from triditko.utils import align from triditko.utils import align
import json import json
import importlib import importlib
import argparse
def get_base_surface(screen_size, categories) -> (pg.Surface, (int, int)): def get_base_surface(screen_size, categories) -> (pg.Surface, (int, int)):
"""Returns a surface template with legend, suitable as a basis for rendering the rest. """Returns a surface template with legend, suitable as a basis for rendering the rest.
@ -35,16 +36,47 @@ def main():
font = pgft.Font(None) font = pgft.Font(None)
#TODO: use argparse and reasonable stuff #TODO: use argparse and reasonable stuff
categories = ['good', 'bad', 'ugly'] argp = argparse.ArgumentParser()
bindings = { argp.add_argument('-c', '--categories',
pg.K_1: 'good', action='store',
pg.K_2: 'bad', metavar='CATEGORIES',
pg.K_3: 'ugly', default='S, A, B, C, D, F',
} type=str,
help='categories to sort into (defaults to S,A,B,C,D,F)',
)
argp.add_argument('-r', '--renderer',
action='store',
type=str,
default='triditko.renderers:DrawItemNameRenderer',
help='alternative renderer for items',
)
argp.add_argument('-o', '--output',
action='store',
metavar='FILE',
type=str,
default='/dev/stdout',
help='output file (defaults to stdout)',
)
argp.add_argument('-i', '--input',
action='store',
metavar='FILE',
type=str,
required=False,
default='/dev/stdin',
help='file with items (defaults to stdin)',
)
args = argp.parse_args()
categories = [x.strip() for x in args.categories.split(',')]
with open(args.input, 'rt') as inputfile:
items = [line.strip() for line in inputfile if line.strip() != '']
# XXX: We won't need these for a long time…
renderer = args.renderer
outputfile = args.output
# TODO: customizable bindings!
if len(categories) > 10:
raise NotImplementedError('Too many categories, cannot automatically assign keybindings.')
bindings = {pg.key.key_code(str(key)): cat for key, cat in zip(range(1, 10+1), categories)}
escape_char = pg.K_ESCAPE escape_char = pg.K_ESCAPE
items = [f'item_{i}' for i in range(20)]
renderer = 'triditko.renderers:DrawItemNameRenderer'
outputfile = '/dev/stdout'
result = {k: [] for k in categories} result = {k: [] for k in categories}

Loading…
Cancel
Save