Python pygame 模块,quit() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.quit()

项目:SmartCar    作者:amarlearning    | 项目源码 | 文件源码
def Kaboom(score):
    init()
    gameDisplay.blit(GameOver,(382,175))
    pygame.draw.rect(gameDisplay, white, (200, 400, 550, 50))
    text = smallfont.render("Press [RETURN] to continue and [Q] to quit", True, darkBlue)
    gameDisplay.blit(text, [370,400])
    text = smallfont.render("Score : " + str(score), True, red)
    gameDisplay.blit(text, [450,420])
    pygame.display.update()
    gameExit = True
    while gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    gameExit = False
                    gameloop()
                if event.key == pygame.K_q:
                    pygame.quit()
项目:Maps    作者:DarkPurple141    | 项目源码 | 文件源码
def pygame_demo_image():

    # this function is for demoing a default output
    size,polygons,poly_sites,rivers,cities,roads,regions = setup()
    pygame.init()
    pygame.font.init()

    screen = pygame.display.set_mode(size,pygame.RESIZABLE)
    pygame.display.set_caption('Map')
    city_font = pygame.font.SysFont('arial', 20)
    region_font = pygame.font.SysFont('arial', 30)

    simple_render(polygons,poly_sites,rivers,cities,roads,regions,city_font,region_font,flag=True)
    pygame.image.save(screen,'test.png')

    pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))
    screen.fill((255, 0, 0))
    s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
    pygame.draw.line(s, (0,0,0), (250, 250), (250+200,250))

    width = 1
    for a_radius in range(width):
        radius = 200
        pygame.gfxdraw.aacircle(s, 250, 250, radius-a_radius, (0, 0, 0))

    screen.blit(s, (0, 0))
    pygame.display.flip()
    try:
        while 1:
            event = pygame.event.wait()
            if event.type == pygame.QUIT:
                break
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.unicode == 'q':
                    break
            pygame.display.flip()
    finally:
        pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def main():
    pygame.init()
    pygame.font.init()
    font = pygame.font.Font(None, 24)
    bg = pygame.display.set_mode((800, 600), 0, 24)
    bg.fill((255,255,255))
    bg.blit(font.render("Click to advance", 1, (0, 0, 0)), (0, 0))
    pygame.display.update()
    for cursor in [no, arrow]:
        TestCursor(cursor)
        going = True
        while going:
            pygame.event.pump()
            for e in pygame.event.get():
                if e.type == pygame.MOUSEBUTTONDOWN:
                    going = False
    pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_quit__and_init(self):
        # __doc__ (as of 2008-06-25) for pygame.base.quit:

          # pygame.quit(): return None
          # uninitialize all pygame modules

        # Make sure everything is not init
        self.not_init_assertions()

        # Initiate it
        pygame.init()

        # Check
        self.init_assertions()

        # Quit
        pygame.quit()

        # All modules have quit
        self.not_init_assertions()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_set_palette_at(self):
        pygame.init()
        try:
            pygame.display.set_mode((100, 50))
            surf = pygame.Surface((2, 2), 0, 8)
            original = surf.get_palette_at(10)
            replacement = Color(1, 1, 1, 255)
            if replacement == original:
                replacement = Color(2, 2, 2, 255)
            surf.set_palette_at(10, replacement)
            self.failUnlessEqual(surf.get_palette_at(10), replacement)
            next = tuple(original)
            surf.set_palette_at(10, next)
            self.failUnlessEqual(surf.get_palette_at(10), next)
            next = tuple(original)[0:3]
            surf.set_palette_at(10, next)
            self.failUnlessEqual(surf.get_palette_at(10), next)
            self.failUnlessRaises(IndexError,
                                  surf.set_palette_at,
                                  256, replacement)
            self.failUnlessRaises(IndexError,
                                  surf.set_palette_at,
                                  -1, replacement)
        finally:
            pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_convert(self):
        """Ensure method convert() preserves the surface's class

        When Surface is subclassed, the inherited convert() method will return
        instances of the subclass. Non Surface fields are omitted, however.
        This includes instance attributes.
        """
        pygame.display.init()
        try:
            ms1 = self.MySurface((32, 32), 0, 24)
            ms2 = ms1.convert(24)
            self.assertTrue(ms2 is not ms1)
            self.assertTrue(isinstance(ms2, self.MySurface))
            self.assertTrue(ms1.an_attribute)
            self.assertRaises(AttributeError, getattr, ms2, "an_attribute")
        finally:
            pygame.display.quit()
项目:Infinity-Game    作者:ISNSaintLaurent    | 项目源码 | 文件源码
def menu_info():
    rect_pointeur = pygame.Rect(pygame.mouse.get_pos(),(1,1))
    rect_retour = pygame.Rect((50,25), (180,35))
    for event in pygame.event.get():
        if event.type == pygame.QUIT :
            abientot()
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if rect_pointeur.colliderect(rect_retour):
                return 1

    fenetre.fill(blanc)
    fenetre.blit(calibri_font.render("< Retour", True, blue), (50, 30))
    fenetre.blit(InfoMenu, (0,80))

    if rect_pointeur.colliderect(rect_retour):
        fenetre.blit(calibri_font.render("< Retour", True, blue2), (50, 30))
    pygame.display.flip()

#Fonction lancée lorsque le joueur quitte et affichant un remerciement
项目:Physics-2.0    作者:rschwa6308    | 项目源码 | 文件源码
def main():
    screen, dims = init_display()
    bodies, camera, scroll = [], Camera(dims), Scroll()

    settings_window, clock, done, frame_count = create_menu("Settings", bodies, camera, dims,
                                                            [constants.G, constants.COR]), pg.time.Clock(), False, 0

    while not done:
        clock.tick(constants.clock_speed)
        frame_count += 1

        camera.apply_velocity()
        G, COR, misc_settings = update_windows(settings_window)
        done, dims, screen = handle_events(settings_window, camera, scroll, done, dims, screen, bodies, G, COR)
        handle_bodies(G, COR, *misc_settings, scroll, bodies, camera, dims, frame_count, settings_window)
        refresh_display(settings_window, screen, bodies, camera)
        scroll.update_value()

    pg.quit()
    if settings_window.alive: settings_window.destroy()
项目:OSD_game    作者:alchon    | 项目源码 | 文件源码
def pause(self):
        fontObj = pygame.font.Font('assets/Roboto-Bold.ttf', 32)
        textSurfaceObj = fontObj.render('Paused', True, GREEN)
        textRectObj = textSurfaceObj.get_rect()
        textRectObj.center = (175, 185)
        fontObj2 = pygame.font.Font('assets/Roboto-Bold.ttf', 16)
        textSurfaceObj2 = fontObj2.render('Press p to continue', True, GREEN)
        textRectObj2 = textSurfaceObj2.get_rect()
        textRectObj2.center = (175, 235)
        self.screen.blit(textSurfaceObj, textRectObj)
        self.screen.blit(textSurfaceObj2, textRectObj2)
        pygame.display.update()
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == KEYUP and event.key == K_p:
                    running = False
项目:OSD_game    作者:alchon    | 项目源码 | 文件源码
def GameOver(self):
        fontObj = pygame.font.Font('assets/Roboto-Bold.ttf', 32)
        textSurfaceObj = fontObj.render('Game over', True, GREEN)
        textRectObj = textSurfaceObj.get_rect()
        textRectObj.center = (175, 185)
        fontObj2 = pygame.font.Font('assets/Roboto-Bold.ttf', 16)
        textSurfaceObj2 = fontObj2.render('Press a key to continue', True, GREEN)
        textRectObj2 = textSurfaceObj2.get_rect()
        textRectObj2.center = (175, 235)
        self.screen.blit(textSurfaceObj, textRectObj)
        self.screen.blit(textSurfaceObj2, textRectObj2)
        pygame.display.update()
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == KEYDOWN:
                    running = False
项目:OSD_game    作者:alchon    | 项目源码 | 文件源码
def newGame(self):
        fontObj = pygame.font.Font('assets/Roboto-Bold.ttf', 32)
        textSurfaceObj = fontObj.render('Tetris', True, GREEN)
        textRectObj = textSurfaceObj.get_rect()
        textRectObj.center = (175, 185)
        fontObj2 = pygame.font.Font('assets/Roboto-Bold.ttf', 16)
        textSurfaceObj2 = fontObj2.render('Press a key to continue', True, GREEN)
        textRectObj2 = textSurfaceObj2.get_rect()
        textRectObj2.center = (175, 235)
        self.screen.fill(BLACK)
        self.screen.blit(textSurfaceObj, textRectObj)
        self.screen.blit(textSurfaceObj2, textRectObj2)
        pygame.display.update()
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == KEYDOWN:
                    running = False
项目:OSD_game    作者:alchon    | 项目源码 | 文件源码
def HS(self, txt="no"):
        if txt != "no":
            fontObj = pygame.font.Font('assets/Roboto-Bold.ttf', 32)
            textSurfaceObj = fontObj.render('HighScore : '+txt, True, GREEN)
            textRectObj = textSurfaceObj.get_rect()
            textRectObj.center = (175, 185)
            fontObj2 = pygame.font.Font('assets/Roboto-Bold.ttf', 16)
            textSurfaceObj2 = fontObj2.render('Press a key to continue', True, GREEN)
            textRectObj2 = textSurfaceObj2.get_rect()
            textRectObj2.center = (175, 235)
            self.screen.fill(BLACK)
            self.screen.blit(textSurfaceObj, textRectObj)
            self.screen.blit(textSurfaceObj2, textRectObj2)
            pygame.display.update()
            running = True
            while running:
                for event in pygame.event.get():
                    if event.type == QUIT:
                        pygame.quit()
                        sys.exit()
                    elif event.type == KEYDOWN:
                        running = False
项目:freddie    作者:kunkkakada    | 项目源码 | 文件源码
def main():
    global DISPLAYSURF, font, menufont


    pygame.init()
    font = pygame.font.Font('etc/INVASION2000.ttf', 25)
    menufont = pygame.font.Font('etc/INVASION2000.ttf', 15)
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    pygame.display.set_caption('Ski Jump Henri 1.0')

    while True: # main game loop
        #header = 

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            #elif event.type == KEYDOWN and event.key == pygame.K_DOWN:



        for h in hills:
            player_jump(h)
项目:rpi_lcars    作者:tobykurien    | 项目源码 | 文件源码
def handleEvents(self):
        for event in pygame.event.get():
            if (event.type == pygame.QUIT) or \
                (event.type == KEYUP and event.key == K_ESCAPE):
                pygame.quit()
                self.running = False
                return

            for sprite in self.all_sprites.sprites():
                if hasattr(event, "pos"):
                    focussed = sprite.rect.collidepoint(event.pos)
                    if (focussed or sprite.focussed) and sprite.handleEvent(event, self.fpsClock):
                        break

            self.screen.handleEvents(event, self.fpsClock)

            newScreen = self.screen.getNextScreen()
            if (newScreen):
                self.all_sprites.empty()
                newScreen.setup(self.all_sprites)
                self.screen = newScreen
                break
项目:pyHonGo    作者:charpy-le    | 项目源码 | 文件源码
def terminate():

   # Quit program nicely
   log('Stopping pygame',1)
   pygame.quit()
   log('OK')
   if WITH_REMOTE:
      log('Stopping remote',1)
      remote.stop()
      log('OK')
   log('Exiting')
   sys.exit()

#-----------------------------------------------------------------------
# Plotting functions
#-----------------------------------------------------------------------
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def textBoxInput(textbox):
    # starts grabbing key inputs, putting into textbox until enter pressed
    global keydict
    textbox.text = ""
    while True:
        updateDisplay()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    textbox.clear()
                    return textbox.text
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                else:
                    textbox.update(event)
            elif event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def textBoxInput(textbox):
    # starts grabbing key inputs, putting into textbox until enter pressed
    global keydict
    textbox.text = ""
    while True:
        updateDisplay()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    textbox.clear()
                    return textbox.text
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                else:
                    textbox.update(event)
            elif event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
项目:backround-maker    作者:Fooliery887    | 项目源码 | 文件源码
def ask(self,question):
        word=""
        Text(self.game).draw_text2(self.default,question,green,wth//2,50) #example asking name
        pygame.display.flip()
        done = True
        while done:
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_a:
                        word+=str(chr(event.key))
                    if event.key == pygame.K_b:
                        word+=chr(event.key)
                    if event.key == pygame.K_c:
                        word+=chr(event.key)
                    if event.key == pygame.K_d:
                        word+=chr(event.key)
                    if event.key == pygame.K_RETURN:
                        done=False
                    #events...
        return Text(self.game).draw_text2(self.default,word,green,wth//2,100)
项目:catcom    作者:Meepasaurus    | 项目源码 | 文件源码
def update(self):
        """Update called every frame"""
        #add check for colission here
        collideB = self.grid.collisionBottom(self.col, self.y)
        if collideB == False:
            self.y+=1
        elif self.placed != True:
            self.placed = True
            #self.grid.add_block(collideB[1], self.col, self.blocktype_file)
            #print "Placed a " + str(self.type) + " at [" + str(collideB[1]) + "][" + str(self.col) + "]"
            if collideB[1] == 0:
                #print "GAME OVER!!"
                #pygame.quit()
                #sys.exit(0)
                return True
        self.screen.blit(self.block_sample, (self.x,self.y))
项目:deep-rl    作者:xinghai-sun    | 项目源码 | 文件源码
def main():
    pygame.init()
    pygame.display.set_caption('Pong')
    pygame.mouse.set_visible(0)  # make cursor invisible
    surface = pygame.display.set_mode((400, 300))
    fps_clock = pygame.time.Clock()

    game = PongGame(window_size=(400, 300), speed=4)

    while True:  #main game loop
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            # mouse movement commands
            #elif event.type == MOUSEMOTION:
            #game.bats['user'].move(event.pos)

        _, done = game.step(1, -1)
        if done:
            game.reset()
        game.draw(surface)
        pygame.display.update()
        fps_clock.tick(120)
项目:rapidpythonprogramming    作者:thecount12    | 项目源码 | 文件源码
def splash():
    intro=True
    while intro:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            if event.type==pygame.KEYDOWN:
                if event.key == pygame.K_c:
                    intro=False
                if event.key==pygame.K_q:
                    pygame.quit()
                    quit()
        display.fill(white)
        message("Wellcome!!!", black,300,300 )
        message("Press 'c' to continue or 'q' to Quit",black,300,400)
        pygame.display.update()
        clock.tick(15)
项目:gym-minecraft    作者:tambetm    | 项目源码 | 文件源码
def _render(self, mode='human', close=False):
        if mode == 'rgb_array':
            return self.last_image
        elif mode == 'human':
            try:
                import pygame
            except ImportError as e:
                raise error.DependencyNotInstalled("{}. (HINT: install pygame using `pip install pygame`".format(e))

            if close:
                pygame.quit()
            else:
                if self.screen is None:
                    pygame.init()
                    self.screen = pygame.display.set_mode((self.video_width, self.video_height))
                img = pygame.surfarray.make_surface(self.last_image.swapaxes(0, 1))
                self.screen.blit(img, (0, 0))
                pygame.display.update()
        else:
            raise error.UnsupportedMode("Unsupported render mode: " + mode)
项目:PyPong    作者:Starlight42    | 项目源码 | 文件源码
def main():
    print('Press return to start the game')

    pygame.init()
    RUN = True
    screen = pygame.display.set_mode(SCREEN_SIZE)
    background = pygame.image.load(BG_PATH).convert_alpha()
    pygame.display.set_caption('PyPong')
    menu = MainMenu(screen)

    while RUN:
        for event in pygame.event.get():
            if event.type == QUIT or \
                    (event.type == KEYDOWN and event.key == K_ESCAPE):
                RUN = False
            if event.type == KEYDOWN and event.key == K_RETURN:
                menu.start()

        pygame.draw.rect(screen, BLACK, SCREEN_ORI + SCREEN_SIZE)
        screen.blit(background, SCREEN_ORI)
        pygame.display.flip()

    pygame.quit()
项目:Pygames    作者:christat    | 项目源码 | 文件源码
def pause():
    paused = True

    message_to_screen("PAUSED", red, -100, mfont)
    message_to_screen("Continue - [ESC]/C", white, 0, sfont)
    message_to_screen("Exit - Q", white, 50, sfont)
    pygame.display.update()

    while paused:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_c or event.key == pygame.K_ESCAPE:
                    paused = False
                elif event.key == pygame.K_q:
                    pygame.quit()
                    quit()
#        gameDisplay.fill(background)
        clock.tick(5)
项目:zeroids-16.2    作者:ProgrammaBol    | 项目源码 | 文件源码
def handle_events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit(0)
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player_one.speed = 10
            if event.key == pygame.K_RIGHT:
                player_one.angular_speed = 5
            if event.key == pygame.K_LEFT:
                player_one.angular_speed = -5
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                player_one.speed = 0
            if event.key == pygame.K_RIGHT:
                player_one.angular_speed = 0
            if event.key == pygame.K_LEFT:
                player_one.angular_speed = 0
项目:pygame-robotics    作者:ioarun    | 项目源码 | 文件源码
def fireShell(xy, tankx, tanky, turPos, gun_power):
    fire = True

    startingShell = list(xy) # from tuple to list conversion
    # print ("FIRE!", xy)

    while fire:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        # print startingShell[0], startingShell[1]
        pygame.draw.circle(gameDisplay, red, (startingShell[0], startingShell[1]), 5)

        startingShell[0] -= (12 - turPos)*2

        # y = x**2
        startingShell[1] += int((((startingShell[0] - xy[0])*0.015)**2) - (turPos + turPos/(12-turPos)))

        if startingShell[1] > display_height:
            fire = False

        pygame.display.update()
        clock.tick(60)
项目:pygame-robotics    作者:ioarun    | 项目源码 | 文件源码
def button(text, x, y, width, height, inactive_color, active_color, action=None):
    cur = pygame.mouse.get_pos()
    # returns a tuple (is_left?, is_center?, is_right?)
    click = pygame.mouse.get_pressed()

    if x + width > cur[0] > x and y + height > cur[1] > y:
        pygame.draw.rect(gameDisplay, active_color, (x, y, width, height))

        if click[0] == 1 and action != None:
            if action == "quit":
                pygame.quit()
                quit()
            if action == "controls":
                game_controls()
            if action == "play":
                gameLoop()
            if action == "main":
                game_intro()

    else:
        pygame.draw.rect(gameDisplay, inactive_color, (x, y, width, height))

    text_to_button(text, black, x, y, width, height)
项目:TabularSASR    作者:SimsGautam    | 项目源码 | 文件源码
def run(self):
        while not self.done:
            # if user clicks close, then exit
            for event in pygame.event.get():
                if event.type == pygame.QUIT:  
                    self.done = True
            grid = self.grid
            self.screen.fill(EMPTY_COLOR)
            for row in range(len(grid)):
                for col in range(len(grid[0])):
                    color = grid[row][col]
                    pygame.draw.rect(self.screen, color,
                                    [(MARGIN + WIDTH) * col + MARGIN,
                                     (MARGIN + HEIGHT) * row + MARGIN,
                                     WIDTH, HEIGHT])
            # Limit to 30 frames per second
            self.clock.tick(30)
            pygame.display.flip()
        pygame.quit()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))
    screen.fill((255, 0, 0))
    s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
    pygame.gfxdraw.aacircle(s, 250, 250, 200, (0, 0, 0))
    screen.blit(s, (0, 0))
    pygame.display.flip()
    try:
        while 1:
            event = pygame.event.wait()
            if event.type == pygame.QUIT:
                break
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.unicode == 'q':
                    break
            pygame.display.flip()
    finally:
        pygame.quit()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def main():
    pygame.init()
    pygame.font.init()
    font = pygame.font.Font(None, 24)
    bg = pygame.display.set_mode((800, 600), 0, 24)
    bg.fill((255,255,255))
    bg.blit(font.render("Click to advance", 1, (0, 0, 0)), (0, 0))
    pygame.display.update()
    for cursor in [no, arrow]:
        TestCursor(cursor)
        going = True
        while going:
            pygame.event.pump()
            for e in pygame.event.get():
                if e.type == pygame.MOUSEBUTTONDOWN:
                    going = False
    pygame.quit()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_quit__and_init(self):
        # __doc__ (as of 2008-06-25) for pygame.base.quit:

          # pygame.quit(): return None
          # uninitialize all pygame modules

        # Make sure everything is not init
        self.not_init_assertions()

        # Initiate it
        pygame.init()

        # Check
        self.init_assertions()

        # Quit
        pygame.quit()

        # All modules have quit
        self.not_init_assertions()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_get_palette(self):
        pygame.init()
        try:
            palette = [Color(i, i, i) for i in range(256)]
            pygame.display.set_mode((100, 50))
            surf = pygame.Surface((2, 2), 0, 8)
            surf.set_palette(palette)
            palette2 = surf.get_palette()
            r,g,b = palette2[0]

            self.failUnlessEqual(len(palette2), len(palette))
            for c2, c in zip(palette2, palette):
                self.failUnlessEqual(c2, c)
            for c in palette2:
                self.failUnless(isinstance(c, pygame.Color))
        finally:
            pygame.quit()
项目:sc8pr    作者:dmaccarthy    | 项目源码 | 文件源码
def __init__(self, size=(512,288)):
        super().__init__(size, "white")
        self.quit = False
        self.frameCount = 0
        self.evMgr = EventManager(self)
项目:sc8pr    作者:dmaccarthy    | 项目源码 | 文件源码
def onquit(self, ev): self.quit = True
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def main(fname):
    """play video file fname"""
    pygame.init()
    try:
        pygame.display.set_mode(SR)
        vPlayer(fname)
    finally:
        pygame.quit()

# Test all modules
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def main():
    pygame.init()
    pygame.camera.init()
    VideoCapturePlayer().main()
    pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_autoinit_and_autoquit(self):
        pygame.init()
        self.assertTrue(ft.was_init())
        pygame.quit()
        self.assertFalse(ft.was_init())

        # Ensure autoquit is replaced at init time
        pygame.init()
        self.assertTrue(ft.was_init())
        pygame.quit()
        self.assertFalse(ft.was_init())
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_cache_size(self):
        DEFAULT_CACHE_SIZE = 64
        ft.init()
        self.assertEqual(ft.get_cache_size(), DEFAULT_CACHE_SIZE)
        ft.quit()
        self.assertEqual(ft.get_cache_size(), 0)
        new_cache_size = DEFAULT_CACHE_SIZE * 2
        ft.init(cache_size=new_cache_size)
        self.assertEqual(ft.get_cache_size(), new_cache_size)
        ft.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def testAutoInit(self):
        pygame.init()
        pygame.quit()
        self.assertEqual(init_called, 1)
        self.assertEqual(quit_called, 1)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_register_quit(self):

        # __doc__ (as of 2008-06-25) for pygame.base.register_quit:

          # register_quit(callable): return None
          # register a function to be called when pygame quits

        self.assert_(not quit_hook_ran)

        pygame.init()
        pygame.register_quit(quit_hook)
        pygame.quit()

        self.assert_(quit_hook_ran)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def todo_test_quit(self):

        # __doc__ (as of 2008-08-02) for pygame.display.quit:

          # pygame.display.quit(): return None
          # uninitialize the display module
          # 
          # This will shut down the entire display module. This means any active
          # displays will be closed. This will also be handled automatically
          # when the program exits.
          # 
          # It is harmless to call this more than once, repeated calls have no effect. 

        self.fail()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def tearDown(self):
        pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_get_palette_at(self):
        # See also test_get_palette
        pygame.init()
        try:
            pygame.display.set_mode((100, 50))
            surf = pygame.Surface((2, 2), 0, 8)
            color = pygame.Color(1, 2, 3, 255)
            surf.set_palette_at(0, color)
            color2 = surf.get_palette_at(0)
            self.failUnless(isinstance(color2, pygame.Color))
            self.failUnlessEqual(color2, color)
            self.failUnlessRaises(IndexError, surf.get_palette_at, -1)
            self.failUnlessRaises(IndexError, surf.get_palette_at, 256)
        finally:
            pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_set_palette(self):
        palette = [pygame.Color(i, i, i) for i in range(256)]
        palette[10] = tuple(palette[10])      # 4 element tuple
        palette[11] = tuple(palette[11])[0:3] # 3 element tuple

        surf = pygame.Surface((2, 2), 0, 8)
        pygame.init()
        try:
            pygame.display.set_mode((100, 50))
            surf.set_palette(palette)
            for i in range(256):
                self.failUnlessEqual(surf.map_rgb(palette[i]), i,
                                     "palette color %i" % (i,))
                c = palette[i]
                surf.fill(c)
                self.failUnlessEqual(surf.get_at((0, 0)), c,
                                     "palette color %i" % (i,))
            for i in range(10):
                palette[i] = pygame.Color(255 - i, 0, 0)
            surf.set_palette(palette[0:10])
            for i in range(256):
                self.failUnlessEqual(surf.map_rgb(palette[i]), i,
                                     "palette color %i" % (i,))
                c = palette[i]
                surf.fill(c)
                self.failUnlessEqual(surf.get_at((0, 0)), c,
                                     "palette color %i" % (i,))
            self.failUnlessRaises(ValueError, surf.set_palette,
                                  [Color(1, 2, 3, 254)])
            self.failUnlessRaises(ValueError, surf.set_palette,
                                  (1, 2, 3, 254))
        finally:
            pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_unmap_rgb(self):
        # Special case, 8 bit-per-pixel surface (has a palette).
        surf = pygame.Surface((2, 2), 0, 8)
        c = (1, 1, 1)  # Unlikely to be in a default palette.
        i = 67
        pygame.init()
        try:
            pygame.display.set_mode((100, 50))
            surf.set_palette_at(i, c)
            unmapped_c = surf.unmap_rgb(i)
            self.failUnlessEqual(unmapped_c, c)
            # Confirm it is a Color instance
            self.failUnless(isinstance(unmapped_c, pygame.Color))
        finally:
            pygame.quit()

        # Remaining, non-pallete, cases.
        c = (128, 64, 12, 255)
        formats = [(0, 16), (0, 24), (0, 32),
                   (SRCALPHA, 16), (SRCALPHA, 32)]
        for flags, bitsize in formats:
            surf = pygame.Surface((2, 2), flags, bitsize)
            unmapped_c = surf.unmap_rgb(surf.map_rgb(c))
            surf.fill(c)
            comparison_c = surf.get_at((0, 0))
            self.failUnlessEqual(unmapped_c, comparison_c,
                                 "%s != %s, flags: %i, bitsize: %i" %
                                 (unmapped_c, comparison_c, flags, bitsize))
            # Confirm it is a Color instance
            self.failUnless(isinstance(unmapped_c, pygame.Color))
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def tearDown(self):
        pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def tearDown(self):
        pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def tearDown(self):
        pygame_font.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_get_init(self):
        self.failUnless(pygame_font.get_init())
        pygame_font.quit()
        self.failIf(pygame_font.get_init())