demo.py
author Radek Brich <radek.brich@devl.cz>
Sun, 22 Feb 2015 09:53:13 +0100
changeset 119 dd91747504dd
parent 117 8680c2333546
permissions -rwxr-xr-x
Redraw widgets on request. Add scrollbar demo.

#!/usr/bin/env python3

from demos.base import setup
import sys
import os
import re


def list_demos():
    return sorted(fname for fname in os.listdir('demos')
                  if re.match(r'[0-9]+_.*\.py', fname))


def print_usage(names):
    print("Usage: %s <name>\n" % sys.argv[0])
    print("Where <name> is one of (or part of):")
    print('\n'.join(['    '+name for name in names]))


if __name__ == '__main__':
    setup()
    names = list_demos()

    if len(sys.argv) != 2:
        print_usage(names)
        sys.exit(0)

    arg = sys.argv[1]
    name = None
    for name in names:
        if arg in name:
            break
    else:
        print("Demo '%s' not found." % arg)
        sys.exit(1)

    print("Executing %s..." % name)
    with open('demos/' + name, 'r') as f:
        exec(f.read())