def sign(ui=None, new=False, seed=None): new and rnd.next() if args.low_mem: s = k.select_one(*l[rnd.current]) else: if seed: l[rnd.current] = seed s = l[rnd.current] if ui: ui.display_sign(KDict.extract_dict(s), KDict.extract_priority(s)) ui.set_flips(rnd.flips) return s
def input_handler(ui, key): if rnd.current is None and not ui.is_key(key, 'exit'): reveal_or_next(ui, force=True) # start no matter what key was pressed (except exit) and return # ignore the key if ui.is_key(key, 'exit'): ui.free() elif ui.is_key(key, 'prioritylist'): # set prio if ui.to_priority(key) is KDict.extract_priority(sign()): pass else: p_new = ui.to_priority(key) update_priority(ui, p_new if args.no_scheck or (p_new < 100 and p_new > -100) else KDict.extract_priority(sign())) if args.prio_proceed: reveal_or_next(ui) elif ui.is_key(key, 'inc_priority'): p_old = KDict.extract_priority(sign()) p_scheck = (p_old + 1) if args.no_scheck or (p_old + 1) < 100 else 100 if p_old is not p_scheck: update_priority(ui, p_scheck) if args.prio_proceed: reveal_or_next(ui) elif ui.is_key(key, 'dec_priority'): p_old = KDict.extract_priority(sign()) p_scheck = (p_old - 1) if args.no_scheck or (p_old - 1) > -100 else -100 if p_old is not p_scheck: update_priority(ui, p_scheck) if args.prio_proceed: reveal_or_next(ui) elif ui.is_key(key, 'proceed'): # reveal or next sign reveal_or_next(ui) elif ui.is_key(key, 'hide'): reveal_or_next(ui, go_back=True) elif ui.is_key(key, 'skip'): # next sign reveal_or_next(ui, force=True) if args.keydebug: args.verbosity > 0 and print('[keydebug] ' + str(key)) else: ui.redraw()
def update_priority(ui, p_new): ui.set_priority(p_new) k.update_p(KDict.extract_book(sign()), KDict.extract_id(sign()), p_new) sign(seed=KDict.update_priority(sign(), p_new))
args.p_min = args.p_max args.choice = expand_choice(args.choice) try: UI_Controller = getattr(import_module('ui.' + args.ui_class), 'UI_Controller') except ImportError as e: print('[ui] Error: ' + str(e) + ' (requested ui class: \'' + args.ui_class + '\')') sys.exit(1) ########################## # gather requested kanji # ########################## k = KDict(args.db) l = [] args.verbosity > 1 and print('[args] ' + str(args.choice)) if args.choice is None: l = k.select_all_keyonly(args.p_min, args.p_max) if args.low_mem else k.select_all(args.p_min, args.p_max) else: for d in args.choice: if args.low_mem: l += k.select_keyonly(d['book'], d['from'], d['to'], args.p_min, args.p_max) else: l += k.select(d['book'], d['from'], d['to'], args.p_min, args.p_max) if len(l) < 2 and not args.no_scheck: print('[main] Error: number of selected kanji is too small (' + str(len(l)) + ')')