Example #1
0
def get_command():
    pie = docpie.docpie(__doc__)

    if pie['--debug']:
        filelogger(pie['--debug'], logger)

    stdoutlogger(logger, INFO)

    logger.debug(pie)
    type_ = []
    if pie['--choose-word']:
        type_.append(Config.CHOOSE_WORD)
    if pie['--choose-meaning']:
        type_.append(Config.CHOOSE_MEANING)
    if not type_:
        type_.append(Config.SPELL)

    assert type_, type_

    if pie['--ascend']:
        order = Config.ASCEND
    elif pie['--descend']:
        order = Config.DESCEND
    else:
        order = Config.SHUFFLE

    config = Config.manual_init(type_=type_,
                                order=order,
                                repeat=not pie['--no-repeat'])

    outfile = pie['--out']
    if outfile:
        config.save_file = outfile
    else:
        config.save_file = StringIO()

    files = pie['<file>']
    start = int(pie['--skip'])
    count = pie['--limit']
    if count.lower() == 'inf':
        end = None
    else:
        count = int(count)
        end = start + count

    words = Words(files, start, end)

    return config, words
Example #2
0
    def get(self):
        return self.select


def main(stdscr):
    # import string
    import sys
    import atexit
    ms = MultiSelect([('中文%s' % x) * 20 for x in range(4)],
                     padding=5,
                     default=[0, 3],
                     lineno=True)
    # ss = SingleSelect('ABCD', [(string.ascii_letters) * 4 for x in range(4)])
    screen = Screen(stdscr)

    atexit.register(lambda: sys.stdout.write(str(ms.select)))
    while True:
        with screen.handle(ms.handler) as s:
            s.clear()
            ms.render(s)


if __name__ == '__main__':
    from wordz.screen import Screen
    from wordz.bashlog import filelogger, stdoutlogger, DEBUG
    from wordz.main import redirect
    redirect()
    stdoutlogger(None, DEBUG)
    # filelogger('/tmp/wordz.log', None, DEBUG)
    curses.wrapper(main)