Python pygame.error() Examples
The following are 30
code examples of pygame.error().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: _Player.py From PyDMXControl with GNU General Public License v3.0 | 6 votes |
def __play(self, file, start_millis): # Stop anything previous self.stop() # Set states self.__paused = False self.__done = False # Get the file try: pygame.mixer.music.load(file) except pygame.error: self.__done = True raise AudioException("Error occurred loading '{}': {}".format(file, pygame.get_error())) # Play the file and tick until play completed pygame.mixer.music.play(start=start_millis / 1000) while pygame.mixer.music.get_busy(): sleep(DMXMINWAIT) # Let everyone know play is done self.__done = True
Example #2
Source File: draw.py From rpisurv with GNU General Public License v2.0 | 5 votes |
def check_keypress(): try: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q or event.key == pygame.K_a or event.key == pygame.K_KP_DIVIDE or event.key == pygame.K_BACKSPACE: logger.debug("Keypress 'a' or 'q' or 'backspace' or 'keypad /' detected.") return "end_event" if event.key == pygame.K_n or event.key == pygame.K_SPACE or event.key == pygame.K_KP_PLUS: logger.debug("Keypress 'n' or 'space' or 'keypad +' detected.") return "next_event" if event.key == pygame.K_r or event.key == pygame.K_KP_PERIOD or event.key == pygame.K_COMMA: logger.debug("Keypress 'r' or ',' or 'keypad .' detected") return "resume_rotation" if event.key == pygame.K_p or event.key == pygame.K_KP_MULTIPLY: logger.debug("Keypress 'p' or 'keypad *' detected") return "pause_rotation" for numeric_key_counter, key in enumerate([pygame.K_F1,pygame.K_F2,pygame.K_F3,pygame.K_F4,pygame.K_F5,pygame.K_F6,pygame.K_F7,pygame.K_F8,pygame.K_F9,pygame.K_F10,pygame.K_F11,pygame.K_F12]): if event.key == key: logger.debug("Keypress 'F" + str(numeric_key_counter + 1) + "' detected") return numeric_key_counter for numeric_key_counter, key in enumerate([pygame.K_KP0,pygame.K_KP1,pygame.K_KP2,pygame.K_KP3,pygame.K_KP4,pygame.K_KP5,pygame.K_KP6,pygame.K_KP7,pygame.K_KP8,pygame.K_KP9]): if event.key == key: logger.debug("Keypress 'keypad " + str(numeric_key_counter + 1) + "' detected") return numeric_key_counter else: return None except pygame.error as e: logger.debug("Exception " + repr(e)) exit(0)
Example #3
Source File: cli.py From stuntcat with GNU Lesser General Public License v2.1 | 5 votes |
def __pgbox(title, message): try: import pygame as pg pg.quit() #clean out anything running pg.display.init() pg.font.init() screen = pg.display.set_mode((460, 140)) pg.display.set_caption(title) font = pg.font.Font(None, 18) foreg, backg, liteg = (0, 0, 0), (180, 180, 180), (210, 210, 210) ok = font.render('Ok', 1, foreg, liteg) okbox = ok.get_rect().inflate(200, 10) okbox.centerx = screen.get_rect().centerx okbox.bottom = screen.get_rect().bottom - 10 screen.fill(backg) screen.fill(liteg, okbox) screen.blit(ok, okbox.inflate(-200, -10)) pos = [10, 10] for text in message.split('\n'): if text: msg = font.render(text, 1, foreg, backg) screen.blit(msg, pos) pos[1] += font.get_height() pg.display.flip() stopkeys = pg.K_ESCAPE, pg.K_SPACE, pg.K_RETURN, pg.K_KP_ENTER while 1: e = pg.event.wait() if e.type == pg.QUIT or \ (e.type == pg.KEYDOWN and e.key in stopkeys) or \ (e.type == pg.MOUSEBUTTONDOWN and okbox.collidepoint(e.pos)): break pg.quit() except pg.error: raise ImportError
Example #4
Source File: sound.py From GDMC with ISC License | 5 votes |
def stop_sound(): try: mixer.stop() except pygame.error: pass
Example #5
Source File: ship.py From alien-invasion-game with MIT License | 5 votes |
def __init__(self, ai_settings: Settings, screen: pygame.SurfaceType , size=(0, 0), image_name="images/ship1.png"): """Initialize the ship and set its starting position.""" super().__init__() self.screen = screen self.ai_settings = ai_settings # Load the ship image and get its rect. # fullname = os.path.join(os.getcwd(), image_name try: self.image = pygame.image.load(image_name) except pygame.error as e: print('Cannot load image: ', image_name) print(e) raise SystemExit if size == (0, 0): size = ai_settings.ship_size self.image = pygame.transform.scale(self.image, size) self.rect = self.image.get_rect() self.screen_rect = screen.get_rect() # Start each new ship at the bottom center of the screen. self.rect.centerx = self.screen_rect.centerx self.rect.bottom = self.screen_rect.bottom # Store a float value for the ship's center. self.center = float(self.rect.centerx) # Movement Flags. self.moving_right = False self.moving_left = False
Example #6
Source File: text_pygame.py From Tickeys-linux with MIT License | 5 votes |
def _render_text(self, text, x, y): font = self._get_font() color = [c * 255 for c in self.options['color']] color[0], color[2] = color[2], color[0] try: text = font.render(text, True, color) self._pygame_surface.blit(text, (x, y), None, pygame.BLEND_RGBA_ADD) except pygame.error: pass
Example #7
Source File: img_pygame.py From Tickeys-linux with MIT License | 5 votes |
def extensions(): '''Return accepted extensions for this loader''' # under macosx, i got with "pygame.error: File is not a Windows BMP # file". documentation said: The image module is a required dependency # of Pygame, but it only optionally supports any extended file formats. # By default it can only load uncompressed BMP image if pygame.image.get_extended() == 0: return ('bmp', ) return ('jpg', 'jpeg', 'jpe', 'png', 'bmp', 'pcx', 'tga', 'tiff', 'tif', 'lbm', 'pbm', 'ppm', 'xpm')
Example #8
Source File: text_pygame.py From Tickeys-linux with MIT License | 5 votes |
def _render_text(self, text, x, y): font = self._get_font() color = [c * 255 for c in self.options['color']] color[0], color[2] = color[2], color[0] try: text = font.render(text, True, color) self._pygame_surface.blit(text, (x, y), None, pygame.BLEND_RGBA_ADD) except pygame.error: pass
Example #9
Source File: img_pygame.py From Tickeys-linux with MIT License | 5 votes |
def extensions(): '''Return accepted extensions for this loader''' # under macosx, i got with "pygame.error: File is not a Windows BMP # file". documentation said: The image module is a required dependency # of Pygame, but it only optionally supports any extended file formats. # By default it can only load uncompressed BMP image if pygame.image.get_extended() == 0: return ('bmp', ) return ('jpg', 'jpeg', 'jpe', 'png', 'bmp', 'pcx', 'tga', 'tiff', 'tif', 'lbm', 'pbm', 'ppm', 'xpm')
Example #10
Source File: clock_example.py From DE3-ROB1-CHESS with Creative Commons Attribution 4.0 International | 5 votes |
def load_image(name, color_key=None): fullname = name try: image = pygame.image.load(fullname) except pygame.error: print('Cannot load image:', name) raise SystemExit image = image.convert() if color_key is not None: if color_key is -1: color_key = image.get_at((0, 0)) image.set_colorkey(color_key, RLEACCEL) return image, image.get_rect()
Example #11
Source File: clock.py From DE3-ROB1-CHESS with Creative Commons Attribution 4.0 International | 5 votes |
def load_image(name, color_key=None): fullname = name try: image = pygame.image.load(fullname) except pygame.error: print('Cannot load image:', name) raise SystemExit image = image.convert() if color_key is not None: if color_key is -1: color_key = image.get_at((0, 0)) image.set_colorkey(color_key, RLEACCEL) return image, image.get_rect()
Example #12
Source File: GameResources.py From artificial-intelligence with MIT License | 5 votes |
def load_image(name): """A better load of images.""" fullname = os.path.join("images", name) try: image = pygame.image.load(fullname) if image.get_alpha() == None: image = image.convert() else: image = image.convert_alpha() except pygame.error: print("Oops! Could not load image:", fullname) return image, image.get_rect()
Example #13
Source File: alien.py From alien-invasion-game with MIT License | 5 votes |
def __init__(self, ai_settings: Settings, screen: pygame.SurfaceType, image_name='images/alien1.png'): """Initialize the alien and set its starting position.""" super().__init__() self.screen = screen self.ai_settings = ai_settings self.screen_rect = screen.get_rect() # Load the alien image and set its rect attribute. fullname = os.path.join('.', image_name) try: self.image = pygame.image.load(fullname) except pygame.error: print('Cannot load image:', image_name) raise SystemExit self.image = pygame.transform.scale(self.image, ai_settings.alien_size) self.rect = self.image.get_rect() # Start each new alien near the top left of the screen. self.rect.x = self.rect.width self.rect.y = self.rect.height self.x = float(self.rect.x) self.y = float(self.rect.y) self.drop_dist = self.y + self.ai_settings.alien_drop_dist
Example #14
Source File: resource.py From GDMC with ISC License | 5 votes |
def get_sound(*names, **kwds): if sound_cache is None: return dummy_sound path = _resource_path("sounds", names, **kwds) sound = sound_cache.get(path) if not sound: try: from pygame.mixer import Sound except ImportError, e: no_sound(e) return dummy_sound try: sound = Sound(path) except pygame.error, e: missing_sound(e, path) return dummy_sound
Example #15
Source File: GameResources.py From AIND-Sudoku with MIT License | 5 votes |
def load_image(name): """A better load of images.""" fullname = os.path.join("images", name) try: image = pygame.image.load(fullname) if image.get_alpha() == None: image = image.convert() else: image = image.convert_alpha() except pygame.error: print("Oops! Could not load image:", fullname) return image, image.get_rect()
Example #16
Source File: renderer_human.py From pysc2 with Apache License 2.0 | 5 votes |
def _get_desktop_size(): """Get the desktop size.""" if platform.system() == "Linux": try: xrandr_query = subprocess.check_output(["xrandr", "--query"]) sizes = re.findall(r"\bconnected primary (\d+)x(\d+)", str(xrandr_query)) if sizes[0]: return point.Point(int(sizes[0][0]), int(sizes[0][1])) except: # pylint: disable=bare-except logging.error("Failed to get the resolution from xrandr.") # Most general, but doesn't understand multiple monitors. display_info = pygame.display.Info() return point.Point(display_info.current_w, display_info.current_h)
Example #17
Source File: sound.py From GDMC with ISC License | 5 votes |
def resume_sound(): try: mixer.unpause() except pygame.error: pass
Example #18
Source File: breakout05.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #19
Source File: breakout04.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #20
Source File: breakout03.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #21
Source File: breakout06.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #22
Source File: breakout01.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #23
Source File: jump.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #24
Source File: double_jump.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #25
Source File: load_map.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #26
Source File: move.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #27
Source File: map_scroll.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #28
Source File: resources.py From QPong with Apache License 2.0 | 5 votes |
def load_image(name, colorkey=None, scale=WIDTH_UNIT/13): fullname = os.path.join(data_dir, 'images', name) try: image = pygame.image.load(fullname) except pygame.error: print('Cannot load image:', fullname) raise SystemExit(str(geterror())) image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0, 0)) image.set_colorkey(colorkey, RLEACCEL) image = pygame.transform.scale(image, tuple(round(scale*x) for x in image.get_rect().size)) return image, image.get_rect()
Example #29
Source File: block.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): """画像をロードして画像と矩形を返す""" filename = os.path.join("data", filename) try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message
Example #30
Source File: fireball.py From pygame with MIT License | 5 votes |
def load_image(filename, colorkey=None): try: image = pygame.image.load(filename) except pygame.error, message: print "Cannot load image:", filename raise SystemExit, message