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

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

项目:Projects    作者:it2school    | 项目源码 | 文件源码
def load_image(file, transparent):
    "loads an image, prepares it for play"
    file = os.path.join(main_dir, 'data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit('Could not load image "%s" %s' %
                         (file, pygame.get_error()))
    if transparent:
        corner = surface.get_at((0, 0))
        surface.set_colorkey(corner, RLEACCEL)
    return surface.convert()



# The logic for all the different sprite types
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_get_error(self):

        # __doc__ (as of 2008-08-02) for pygame.base.get_error:

          # pygame.get_error(): return errorstr
          # get the current error message
          #
          # SDL maintains an internal error message. This message will usually
          # be given to you when pygame.error is raised. You will rarely need to
          # call this function.
          #

        e = pygame.get_error()
        self.assertTrue(e == "" or
                        # This may be returned by SDL_mixer built with
                        # FluidSynth support. Setting environment variable
                        # SDL_SOUNDFONTS to the path of a valid sound font
                        # file removes the error message.
                        e == "No SoundFonts have been requested",
                        e)
        pygame.set_error("hi")
        self.assertEqual(pygame.get_error(), "hi")
        pygame.set_error("")
        self.assertEqual(pygame.get_error(), "")
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def load_image(file, transparent):
    "loads an image, prepares it for play"
    file = os.path.join(main_dir, 'data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit('Could not load image "%s" %s' %
                         (file, pygame.get_error()))
    if transparent:
        corner = surface.get_at((0, 0))
        surface.set_colorkey(corner, RLEACCEL)
    return surface.convert()



# The logic for all the different sprite types
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_get_error(self):

        # __doc__ (as of 2008-08-02) for pygame.base.get_error:

          # pygame.get_error(): return errorstr
          # get the current error message
          # 
          # SDL maintains an internal error message. This message will usually
          # be given to you when pygame.error is raised. You will rarely need to
          # call this function.
          # 

        self.assertEqual(pygame.get_error(), "")
        pygame.set_error("hi")
        self.assertEqual(pygame.get_error(), "hi")
        pygame.set_error("")
        self.assertEqual(pygame.get_error(), "")
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def load_image(file):
    "loads an image, prepares it for play"
    file = os.path.join('data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit('Could not load image "%s" %s'%(file, pygame.get_error()))
    return surface.convert()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def load_image(file):
    "loads an image, prepares it for play"
    file = os.path.join(main_dir, 'data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit('Could not load image "%s" %s'%(file, pygame.get_error()))
    return surface.convert()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def test_set_error(self):

        e = pygame.get_error()
        self.assertTrue(e == "" or
                        # This may be returned by SDL_mixer built with
                        # FluidSynth support. Setting environment variable
                        # SDL_SOUNDFONTS to the path of a valid sf2 file
                        # removes the error message.
                        e == "No SoundFonts have been requested",
                        e)
        pygame.set_error("hi")
        self.assertEqual(pygame.get_error(), "hi")
        pygame.set_error("")
        self.assertEqual(pygame.get_error(), "")
项目:TicTacTio    作者:DevelopForLizardz    | 项目源码 | 文件源码
def test():
            logging.info("Importing pygame")
            import pygame
            result = pygame.init()
            logging.info("Result of initiating pygame: {}".format(result))

            if result[1] != 0:
                if result[1] == 1 and pygame.mixer.get_init() is None:
                    logging.warning("WARNING: pygame mixer module is not initializing properly, however since this is "
                                    "not required the test will still pass.")
                else:
                    logging.error("ERROR: Unable to properly initialize pygame (from pygame: {})".format(
                        pygame.get_error()))
                    raise AssertionError()
            # otherwise the test passes
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def load_image(file):
    "loads an image, prepares it for play"
    file = os.path.join('data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit, 'Could not load image "%s" %s'%(file, pygame.get_error())
    return surface.convert()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def load_image(file):
    "loads an image, prepares it for play"
    file = os.path.join(main_dir, 'data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit('Could not load image "%s" %s'%(file, pygame.get_error()))
    return surface.convert()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def test_set_error(self):

        self.assertEqual(pygame.get_error(), "")
        pygame.set_error("hi")
        self.assertEqual(pygame.get_error(), "hi")
        pygame.set_error("")
        self.assertEqual(pygame.get_error(), "")
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def loadresources(self):
        """painting on the surface (once) and create sprites"""
        # make an interesting background 
        draw_examples(self.background) # background artwork
        try:  # ----------- load sprite images -----------
            PygView.images.append(pygame.image.load(os.path.join("data", "babytux.png"))) # index 0
            # load other resources here
        except:
            print("pygame error:", pygame.get_error())
            print("please make sure there is a subfolder 'data' and in it a file 'babytux.png'")
            pygame.quit()
            sys.exit()
        # -------  create (pygame) Sprites Groups and Sprites -------------
        self.allgroup =  pygame.sprite.LayeredUpdates() # for drawing
        self.ballgroup = pygame.sprite.Group()          # for collision detection etc.
        self.hitpointbargroup = pygame.sprite.Group()
        self.bulletgroup = pygame.sprite.Group()
        self.tuxgroup = pygame.sprite.Group()
        self.enemygroup = pygame.sprite.Group()
        # ----- assign Sprite class to sprite Groups ------- 
        Tux.groups = self.allgroup, self.tuxgroup
        Hitpointbar.groups = self.hitpointbargroup
        Ball.groups = self.allgroup, self.ballgroup
        Evildoge.groups = self.enemygroup, self.allgroup
        Bullet.groups = self.allgroup, self.bulletgroup
        self.ball1 = Ball(x=100, y=100) # creating a Ball Sprite
        self.ball2 = Ball(x=200, y=100) # create another Ball Sprite
        self.tux1 = Tux(x=400, y=200, dx=0, dy=0, layer=5, imagenr = 0) # over balls layer
        #self.evildoge = Evildoge(x=150, y=350)
项目:Space-Shooter    作者:AbelJoshuaa    | 项目源码 | 文件源码
def load_sound(path):
    path = os.path.join(main_dir, "data", path)
    if not pygame.mixer:
        return None
    try:
        data = pygame.mixer.Sound(path)
    except pygame.error:
        print("Sorry, couldn't load image " +(path) + " " + pygame.get_error())
    return data
项目:Space-Shooter    作者:AbelJoshuaa    | 项目源码 | 文件源码
def load_image(path, transparent):
    path = os.path.join(main_dir, "data", path)
    if not pygame.image:
        return None
    try:
        data = pygame.image.load(path)
    except pygame.error:
        print("Couldn't load image file " + path+ " " + pygame.get_error())
    if transparent:
        corner = data.get_at((0,0))
        data.set_colorkey(corner, RLEACCEL)
    return data.convert()
项目:mini_rpg    作者:paolo-perfahl    | 项目源码 | 文件源码
def loadresources(self):
        """painting on the surface (once) and create sprites"""
        # make an interesting background 
        draw_examples(self.background) # background artwork
        try:  # ----------- load sprite images -----------
            tile = pygame.image.load(os.path.join("data", "startile-300px.png"))
            PygView.images.append(pygame.image.load(os.path.join("data", "babytux.png"))) # index 0
            PygView.images.append(pygame.image.load(os.path.join("data", "player_red2.png")))
            PygView.images.append(pygame.image.load(os.path.join("data", "babytux_neg.png")))
            PygView.images.append(pygame.image.load(os.path.join("data", "player_blue2.png"))) # index 3

            # load other resources here
        except:
            print("pygame error:", pygame.get_error())
            print("please make sure there is a subfolder 'data' with the resource files in it")
            pygame.quit()
            sys.exit()
        # fill background with tiles
        self.background = fill_surface_with_tiles(tile, self.width, self.height)
        # write text
        # -------  write text over everything  -----------------
        write(self.background, "Press b to add another ball", x=self.width//2, y=250, center=True)
        write(self.background, "Press c to add another bullet", x=self.width//2, y=275, center=True)
        write(self.background, "Press w,a,s,d and q,e to steer tux", x=self.width//2, y=300, center=True)
        write(self.background, "Press space to fire from tux", x=self.width//2, y=325, center=True)

        self.paintgrid()
        # -------  create (pygame) Sprites Groups and Sprites -------------
        self.allgroup =  pygame.sprite.LayeredUpdates() # for drawing
        self.ballgroup = pygame.sprite.Group()          # for collision detection etc.
        self.bargroup = pygame.sprite.Group()
        self.bulletgroup = pygame.sprite.Group()
        self.fire_at_player_group = pygame.sprite.Group()
        self.tuxgroup = pygame.sprite.Group()
        self.neutralgroup = pygame.sprite.Group()
        self.fleegroup = pygame.sprite.Group()
        self.missilegroup = pygame.sprite.Group()
        # ----- assign Sprite class to sprite Groups ------- 
        Tux.groups = self.allgroup, self.tuxgroup
        Basebar.groups = self.bargroup
        Ball.groups = self.allgroup, self.ballgroup, self.fire_at_player_group # each Ball object belong to those groups
        Bullet.groups = self.allgroup, self.bulletgroup
        Doenertier.groups = self.allgroup, self.neutralgroup, self.fleegroup
        Missile.groups = self.allgroup, self.missilegroup, self.bulletgroup
        self.doenertier1 = Doenertier()
        self.ball1 = Ball(x=100, y=100, radius = 10) # creating a Ball Sprite
        self.ball2 = Ball(x=200, y=100, radius = 20) # create another Ball Sprite
        self.tux1 = Tux(x=400, y=200, dx=0, dy=0, layer=5, imagenr = 0) # over balls layer
        self.tux2 = Tux(x=200, y=400, dx=0, dy=0, layer=5, imagenr = 1)
        print(len(self.joysticks))
        if len(self.joysticks) > 2:
            self.tux3 = Tux(x=300, y=300, dx=0, dy=0, layer=5, imagenr = 2)
        if len(self.joysticks) > 3:
            self.tux4 = Tux(x=100, y=500, dx=0, dy=0, layer=5, imagenr = 3)