Exemple #1
0
def main():
    # Setup the root UI
    root = tkinter.Tk()
    root.title("JSON editor")
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)

    fname = None
    if len(sys.argv) > 1:
        fname = sys.argv[1]
    Data = treewalk.loadfile(sys.argv[1])


    # Setup the Frames
    TreeFrame = ttk.Frame(root, padding="3")
    TreeFrame.grid(row=0, column=0, sticky=tkinter.NSEW)
    # Setup the Tree
    tree = ttk.Treeview(TreeFrame, columns=('Values'))
    tree.column('Values', width=100, anchor='w')
    tree.heading('Values', text='Values')
    tree.bind('<Double-1>', edit_cell)
    tree.bind('<Return>', edit_cell)
    JSONTree(tree, '', Data)
    tree.pack(fill=tkinter.BOTH, expand=1)
    # Limit windows minimum dimensions
    root.update_idletasks()
    root.minsize(root.winfo_reqwidth(), root.winfo_reqheight())
    root.mainloop()
Exemple #2
0
def main():
    initialize()

    fname = None
    if len(sys.argv) > 1:
        fname = sys.argv[1]
    tree = tw.loadfile(fname)

    tree = populate_stats(tree)
    print_tree(tree)
Exemple #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input', '-i', help="Input file, default: stdin.",
                        default=None, type=str, dest='fname')

    args = parser.parse_args()
    fname = args.fname

    tw = TreeWalker(action, Ctx)

    tree = loadfile(fname)
    tw.walktree(tree)
Exemple #4
0
def main():
    initialize()

    p = parser()
    args = p.parse_args()

    fname = args.fname

    global ROOT_ID
    ROOT_ID = args.name

    tree = treewalk.loadfile(fname)

    tree = populate_stats(tree)
    print_tree(tree)
Exemple #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input', '-i', help="Input file, default: stdin.",
                        default=None, type=str, dest='fname')

    args = parser.parse_args()
    if args.fname:
        args.title = 'Tree analysis for ' + args.fname
    else:
        args.title = 'Tree analysis process ' + str(os.getpid())

    legend = '(\\$: problem size <= possible scores, \\+: optimal split, \\*: root code not a solution.)'
    title = args.title

    fname = args.fname

    global PFXGEN
    PFXGEN = PrefixGen()
    PFXGEN.skip_non_reducing = True

    tw = TreeWalker(action, Ctx)

    tree = loadfile(fname)
    tw.walktree(tree)
    summary = Summary(tree)

    global PRINTED_PFX_LEN
    PRINTED_PFX_LEN = (len(str(CODETABLE.CODES[0]))+2) * MAX_PFX_LEN + 2

    columns = (
        ('prefix', PRINTED_PFX_LEN, 'r'),
        ('flags', max(len('flags'), 6), 'l'),
        ('#children', max(len('#children'), 6), 'l'),
        ('problem size', max(len('problem size'), 6), 'l'),
        ('max subproblem', max(len('max subproblem'), 6), 'l'),
        ('#preserving', max(len('#preserving'), 6), 'l'),
        ('#distinct/in', max(len('#distinct/in'), 4), 'l'),
        ('#distinct/all', max(len('#distinct/all'), 4), 'l'))

    separator = ' '.join(map(lambda c: '=' * c[1], columns))

    header = ' '.join(map(lambda c: pad(c[0], c), columns))

    formats = ("%s", "%s", "%5d", "%5d", "%5d", "%6d", "%4d", "%4d")

    locale.setlocale(locale.LC_ALL, 'en_US')

    print title
    print '=' * len(title)
    print "\nAverage game: {:.4f} moves, Longest game: {} moves\n\n".format(
        summary.mean_game(), 
        locale.format("%d", summary.longest_game(), grouping=True))

    print """.. table:: Prefix properties of a game tree %s
  :widths: %s
  :column-wrapping: %s
  :column-alignment: %s
  :column-dividers: %s

""" % (legend,
       ('1 ' * len(columns)),
       ('false' + ' true' * len(columns[1:])),
       ('left' + ' right' * len(columns[1:])),
       'single' + ' single' * len(columns))


    print '  ' + separator
    print '  ' + header
    print '  ' + separator

    for r in sorted(RECORDS, lambda a, b: cmp(len(a[0]), len(b[0])) or cmp(a[0], b[0]) or cmp(b[4], a[4])):
        (pfx, insoln, optimal, nchildren, psize, maxprob, ninv, nd_in, nd_all) = r
        fields = (format_prefix(pfx),
                  ''.join((('\\$' if psize <= CODETABLE.NSCORES else ''), 
                           ('' if insoln else '\\*'), ('\\+' if optimal else ''))),
                  nchildren,
                  psize,
                  maxprob,
                  ninv,
                  nd_in,
                  nd_all)

        printable = map(lambda i: locale.format(i[0], i[1], grouping=True), zip(formats, fields))
        printable = map(lambda i: pad(i[0], i[1]), zip(printable, columns))
        print '  ' + (' '.join(printable))

    print '  ' + separator