Beispiel #1
0
def g(path):
    lexer = HqlLexer.HqlLexer(FileStream(path))
    token_stream = CommonTokenStream(lexer)
    parser = HqlParser.HqlParser(token_stream)
    tree = parser.sql()

    visitor = VisitorImpl.VisitorImpl()
    result = visitor.visit(tree)

    pp = pprint.PrettyPrinter(indent=4)
    # pp.pprint(result)
    # test.plotSubTree(result, None, 1, 0, 12)
    test.draw(result)
Beispiel #2
0
def hello(op=None):
    poem = request.form.get('poem',None)
    print "poem is",poem
    if poem:
        poem = poem.encode('utf-8')
        border_img = choose_border()
        font = choose_font()
        color = choose_color()
        draw(border_img,font,color, poem)
        #return render_template('index.html', op='images/output.png')
        #time.sleep(3)
        #return redirect(url_for('.hello', op="static/images/output.png"))
        return render_template('index.html', op="static/images/output.png")
    else:
        return render_template('index.html', op=None)
    def graphvizdraw(self, instance):
        d = draw()
        d.drawGraph(instance.edges, instance.tokens)

        label = self.ui.label_picture

        path = os.path.abspath('test-output/round-table.gv.pdf')
        pdf2png.gs_pdf_to_png(path, 70)
        path2 = os.path.abspath('test-output/round-table.gv.png')

        #pixmap = QtGui.QPixmap(path2)
        #label.setPixmap(pixmap)
        myPixmap = QtGui.QPixmap(path2)
       # myScaledPixmap = myPixmap.scaled(label.size())
        label.setPixmap(myPixmap)

        label.show()
Beispiel #4
0
def main_loop():
    print "\n" * 12 + "* * * * * NEW GAME * * * * *"

    """these things only need to happen once"""
    screen = pygame.display.get_surface()
    screen.fill(graphics.background)
    load_settings()

    messages.screen = screen

    clock = pygame.time.Clock()
    dt = 0

    world, t, r = 0, 0, 0

    loadedSavedGame = 0

    if getChoiceUnbounded("Load saved game?", ["yes", "no"]) == "yes":
        r = game_progress.load_game()

    if r:
        messages.say("Loading saved game", down=4)
        pygame.display.flip()
        world = pygame.Surface((graphics.world_w, graphics.world_h))
        t = r.topbar
        loadedSavedGame = 1
    else:
        """these are level-specific"""
        level = enteredlevel(allowcancel=0)
        if level == "quit":
            return
        world, t, r = preparelevel(screen, level)
    pygame.display.get_surface().fill((50, 50, 50))

    p = player.Player(r)

    # h = zoo.Beehive()
    h = zoo.Beehive("the fact that any argument is passed here means that I'll load saved bees")

    c = camera.Camera(p, world, screen, r)
    c.jump_to_player()

    # myfamilytree = familytree.FamilyTree()
    myspeciesplot = species_visualization.SpeciesPlot()

    # Generating new bees
    # r.bees = h.preserved_bees(r, p)
    if loadedSavedGame:
        for b in r.bees:
            b.player = p
    else:
        r.generate_bees(settings[MAXIMUM_BEES])
    r.h = h
    # for b in r.bees:
    #   b.randomize_position()

    framecount = 0

    previous_key_states = []
    key_ups = []

    global time_to_quit

    info_panel = StackingPanel()
    left = 0
    top = 0
    for family_name in game_settings.families:
        family_panel = ShrinkingPanel(min_width=250)
        top = 0
        title = MessagePanel(family_name)
        family_panel.children.append(title)

        title.onclick.append(get_toggler(family_panel))
        top += 30

        for entry in game_settings.families[family_name]:
            new_button = SettingButton(entry, y=top, typeface="DejaVu Sans", bold=True, italic=True, visible=False)
            top += 20
            family_panel.children.append(new_button)
        left += family_panel.rect.w
        info_panel.children.append(family_panel)

    # we should never see reassignment of gameobjects!
    gameobjects = {
        "room": r,
        "player": p,
        "hive": h,
        "camera": c,
        "world": world,
        "screen": screen,
        "info_panel": info_panel,
    }

    info_panel.children.append(StatisticsPanel(gameobjects))

    while not close(r):  # Main game loop # Don't need cancel and quit works
        if time_to_quit:
            try:
                print "Quitting indirectly at main loop. Saving room..."
                game_progress.save_game(r)
                break
            except Exception:
                print "Failed to save"
        framecount += 1

        test.begin_timing(test.segs, test.segdescriptors)
        key_presses = pygame.event.get(pygame.KEYDOWN)
        key_states = pygame.key.get_pressed()

        if previous_key_states:
            key_ups = [old and not new for new, old in zip(key_states, previous_key_states)]
        else:
            key_ups = [0 for x in key_states]

        previous_key_states = key_states[:]

        time_gap = handle_player_input(key_presses, key_ups, key_states, gameobjects)

        r = gameobjects["room"]
        c = gameobjects["camera"]
        h = gameobjects["hive"]
        world = gameobjects["world"]
        screen = gameobjects["screen"]
        p = gameobjects["player"]

        if time_gap:
            clock.tick(400)
            dt = 0
        mod = 20
        # each bee updates once every mod frames

        """Update"""
        for i, bee in enumerate(r.bees):
            bee.slow = 1  # (i + framecount) % mod

        test.add_sticky("main:playerupdate")
        p.update(dt, key_states, key_presses)
        test.remove_sticky("main:playerupdate")

        for phys in r.food + r.bullets:
            phys.update(dt, key_states, key_presses)

        test.add_sticky("bee")
        for b in r.bees:
            b.update(dt, key_states, key_presses)
            if b.request_family_tree_update:
                updatefamilytree = 1
                b.request_family_tree_update = 0
        test.remove_sticky("bee")

        screen.fill([0, 0, 0])

        if settings[SHOW_FAMILY_TREE]:
            test.add_sticky("tree")

            # draw every frame, since the tree follows the player around
            if settings[SPECIES_STYLE] == 3:
                if not framecount % settings[TREE_UPDATE_TIME]:
                    myspeciesplot.update(r.bees + r.deadbees)
                    for b in r.deadbees:
                        if b.dead == 2:
                            r.deadbees.remove(b)
                myspeciesplot.draw(
                    world, (int(p.xy[0, 0]) - myspeciesplot.w / 2, int(p.xy[0, 1]) - myspeciesplot.h / 2)
                )

            else:
                # update once every few frames
                if not framecount % settings[TREE_UPDATE_TIME]:
                    myspeciesplot.update(r.bees + r.deadbees)
                    myspeciesplot.draw(screen, (840, 0))

                    for b in r.deadbees:
                        if b.dead == 2:
                            r.deadbees.remove(b)

            updatefamilytree = 0

            if updatefamilytree:
                myfamilytree.update(r.bees)
                myfamilytree.draw(screen, (840, 0))
            test.remove_sticky("tree")

        test.add_sticky("room")
        # Necessarily comes afterwards so that the bees can see the player
        r.update()
        test.remove_sticky("room")

        """
        if r.signal_new_tree:
            r.signal_new_tree = 0
            myfamilytree.depth += 2*settings[TREE_V_SPACING]

        test.remove_sticky('tree') ##########
        """
        test.add_sticky("camera_update")
        c.follow_player(dt)  # Here so that room knows what to draw
        c.updatesight()
        test.remove_sticky("camera_update")

        test.add_sticky("main:drawing")
        test.add_sticky("main:drawing:test")
        test.draw(world, r)
        test.remove_sticky("main:drawing:test")
        test.add_sticky("main:drawing:bee")
        for x in r.bees:
            x.draw(world)
        test.remove_sticky("main:drawing:bee")
        test.add_sticky("main:drawing:other")
        for x in r.food + [p] + r.bullets:
            x.draw(world)
        test.remove_sticky("main:drawing:other")

        # Time
        dt = clock.tick(120)  # used to be 120

        # Make it seem like a slowed down version of 22fps if necessary
        dt = min(dt, 45)
        # print dt, "this is dt"
        test.add_sticky("main:drawing:camera")
        c.draw()
        test.remove_sticky("main:drawing:camera")

        info_panel.draw_to(screen)

        """
        seconds = pygame.time.get_ticks() / 1000

        t0 = ""

        if settings[SPECIES_STYLE] == 1:
            t0 += "Plotted on right: x: horizontal movement, y: generation"
        elif settings[SPECIES_STYLE] == 2:
            t0 += "Plotted on right: x: generation, y: vertical movement"
        elif settings[SPECIES_STYLE] == 3:
            t0 += "angle: direction, radius: generation"

        t.permanent_text = [t0]

        ta = "Time: " + str(seconds)
        tb = " | current bees: " + str(len(r.bees))
        tbb = " | total dead bees " + str(len(r.deadbees))
        tc = " |" + str(int(clock.get_fps()))+"fps"

        t.permanent_text += [
        ta + tb + tbb + tc,]

        if settings[SHOW_HELP]:
            t.permanent_text += [
            "click anywhere for options",
            "plotted on right: Recent lifetimes, max is %s" % (max(t.data) if t.data else "not defined"),
            "[a]: %s birth and deaths" % ("resume" if r.stasis else "pause"),
            "[g]: generate bees",
            "[e]: visualize paths of a random bee",
            "[r]: %s eyes" % ("hide" if settings[SHOW_EYES] else "show"),
            "[n]: %s names" % ("hide" if settings[SHOW_NAMES] else "show"),
            "[m]: %s visual madness" % ("decrease" if r.madness == 2 else "increase"),
            "[SPACE]: teleport to a random position",
            "[t]: turn %s random map generation" % ("off" if settings[GENERATE_RANDOM_MAP] else "on"),
            ]

        t.permanent_text.append("[h]: %s help" % ("hide" if settings[SHOW_HELP] else "show"))

        t.draw(screen)"""
        test.add_sticky("main:drawing:displayflip")
        pygame.display.flip()
        test.remove_sticky("main:drawing:displayflip")
        test.remove_sticky("main:drawing")

        for phys in r.bees + r.food + [p]:
            phys.visible = c.can_see(phys)

        test.summarizetimings(test.segs, test.segdescriptors)
        # if framecount % 30 == 0:
        #   print int(clock.get_fps()), "fps"
        pygame.event.pump()