Пример #1
0
def main():
    pygame.init()

    # Note : the DisplayWidget does NOT take care of the creation of the
    # display area.  I do not want the GUI to force me to change anything to
    # my code.

    pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

    CreateGui()

    running = True
    clock = pygame.time.Clock()
    while running:
        # I expect the GUI to have to update itself once per frame at max.
        # If `pynguin.update` has nothing to do then it return immediately.
        # In this usecase, the GUI is not modified after the initial creation
        # so `pynguin.update` will do something only the first time.
        pynguin.update()
        pygame.display.flip()
        clock.tick(MAX_FPS)
        for event in pygame.event.get():
            if event.type == EVENT_QUIT:
                running = False
    print "Quitting..."
    pygame.quit()
Пример #2
0
def main():
    pygame.init()

    # Note : the DisplayWidget does NOT take care of the creation of the
    # display area.  I do not want the GUI to force me to change anything to
    # my code.

    pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

    event_manager = EventManager()

    CreateGui(event_manager)

    console_viewer = ConsoleViewer()
    event_manager.register(console_viewer)

    running = True
    clock = pygame.time.Clock()
    while running:
        # I expect the GUI to have to update itself once per frame at max.
        # If `pynguin.update` has nothing to do then it returns immediately.
        pynguin.update()
        pygame.display.flip()
        clock.tick(MAX_FPS)
        for event in pygame.event.get():
            if event.type == EVENT_QUIT:
                running = False
            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    # Left button.
                    event_manager.post(Event("mouse click", event.pos))

    print "Quitting..."
    pygame.quit()
Пример #3
0
def main():
    print "[SPACE]: show animation object."
    print "[RETURN]: start animation."

    pygame.init()
    pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

    label_move, label_fps, label_follow, label_bounce = CreateGui()

    running = True
    clock = pygame.time.Clock()

    label_follow.startAnimation(AnimFollowMouse, -1) # Negative duration: loop.
    label_fps.startAnimation(AnimShowFPS, -1, clock) # Can pass extra params.
    label_bounce.startAnimation(AnimBounce, -500) # 500 ms, loop.

    while running:
        clock.tick(MAX_FPS)
        gui_time = pygame.time.get_ticks() # I can use any time I want.-
        #
        # NOTE:
        #
        # In this usecase I provide a time to the update function.  I didn't
        # do it before.  Looks like the time is necessary.  Question is: should
        # I allow the user to call update without parameter, and if yes what
        # should be the default value, and what should it mean ?  Since without
        # time it is impossible to use animations, it would be natural to just
        # don't animate anything if the time is not provided.
        pynguin.update(gui_time)
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == EVENT_QUIT:
                running = False
            elif event.type == EVENT_KEYDOWN:
                if event.key == ' ':
                    print label_move.animation
                elif event.key == pygame.K_RETURN:
                    if label_move.animation is None:
                        label_move.startAnimation(AnimMoveRight, 2000) # In ms.
                    else:
                        print "Animation already running."
    print "Quitting..."
    pygame.quit()
Пример #4
0
def main():
    pygame.init()

    # Note : the DisplayWidget does NOT take care of the creation of the
    # display area.  I do not want the GUI to force me to change anything to
    # my code.

    pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

    button, text_input = CreateGui()

    running = True
    clock = pygame.time.Clock()
    while running:
        # I expect the GUI to have to update itself once per frame at max.
        # If `pynguin.update` has nothing to do then it return immediately.
        # In this usecase, the GUI is not modified after the initial creation
        # so `pynguin.update` will do something only the first time.
        pynguin.update()
        pygame.display.flip()
        clock.tick(MAX_FPS)
        for event in pygame.event.get():
            if event.type == EVENT_QUIT:
                running = False
        # Modify the appearance of the GUI.
        if random.randrange == 0:
            # Modify the appearance.
            button.mode = random.choice(['normal', 'clicked'])
        if random.randrange == 0:
            # Modify the size.
            # That should also change the size of the window.
            text_input.text = str(random.randrange(9999999)) * random.randrange(10)
        text_input

    print "Quitting..."
    pygame.quit()