def errorbox(message): message = str(message) if not message: message = 'Error' import errorbox errorbox.errorbox("Solarwolf Error", message) sys.stderr.write('ERROR: ' + message + '\n') raise SystemExit
def load_song(c, name): fullname = os.path.join(c.MUSC_DIR, name) try: pygame.mixer.music.load(fullname) pygame.mixer.music.set_volume(c.VOLUME[0]) except pygame.error: message = 'COULD NOT LOAD MUSIC: ' + fullname debug(c.DEBUG, message) errorbox("Failed Loading Song", message) raise SystemExit(str(geterror())) return
def save_players(): allplayers = players + winners try: filename = game.make_dataname('players') f = open(filename, 'wb') p = pickle.Pickler(f, 1) p.dump(allplayers) f.close() except (IOError, OSError), msg: import errorbox errorbox.errorbox("Error Saving Player Data", "There was an error saving the player data.\nCurrent player data has been lost.\n\n%s"%msg)
def exception_handler(): import traceback type, info, trace = sys.exc_info() tracetop = traceback.extract_tb(trace)[-1] tracetext = 'File %s, Line %d' % tracetop[:2] if tracetop[2] != '?': tracetext += ', Function %s' % tracetop[2] exception_message = '%s:\n%s\n\n%s\n"%s"' message = exception_message % (str(type), str(info), tracetext, tracetop[3]) if type not in (KeyboardInterrupt, SystemExit): import errorbox errorbox.errorbox("Solarwolf Error", message) sys.stderr.write('ERROR: ' + message + '\n') raise SystemExit
def load_sound(c, name): fullname = os.path.join(c.SND_DIR, name) try: if not (os.path.isfile(fullname)): raise NameError(fullname) sound = pygame.mixer.Sound(fullname) #print c.VOLUME sound.set_volume(c.VOLUME[0]) except NameError: message = 'Cannot load sound: ' + fullname errorbox("Failed Sound Loading", message) debug(c.DEBUG, ('Cannot load sound: ', fullname)) raise SystemExit(str(geterror())) return sound
def save_translations(): global translations #not gonna save for now return try: filename = game.make_dataname('input') f = open(filename, 'wb') p = pickle.Pickler(f, 1) p.dump(translations) f.close() except (IOError, OSError), msg: import errorbox errorbox.errorbox( "Error Saving Control Data", "There was an error saving the control data.\nCurrent player controls have been lost.\n\n%s" % msg)
def load_image(c, name, colorkey=None): fullname = os.path.join(c.GFX_DIR, name) try: image = pygame.image.load(fullname) except pygame.error: message = 'Cannot load image: ' + fullname errorbox("Failed Image Loading", message) debug(c.DEBUG, message) 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) return image perPixelAlphaImage = image.convert_alpha() return perPixelAlphaImage
def load_image_C(gfx_dir, DEBUG, name, colorkey=None): fullname = os.path.join(gfx_dir, name) try: image = pygame.image.load(fullname) #print fullname except pygame.error: message = 'Cannot load image: ' + fullname errorbox("Failed Image Loading", message) debug(DEBUG, ('Cannot load image: ', message)) 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) return image, image.get_rect() return image.convert_alpha(), image.get_rect()
def debugMain(): print "HEY THERE WE'RE DOING SPECIAL DEBUGGING" import logging DATE = datetime.date.timetuple(datetime.date.today())[0] , \ datetime.date.timetuple(datetime.date.today())[1] , \ datetime.date.timetuple(datetime.date.today())[2] MAIN_DIR = os.path.split(os.path.abspath(__file__))[0] MAIN_DIR = os.path.split(MAIN_DIR)[0] DATA_DIR = os.path.join(MAIN_DIR, 'data') saveDir = os.path.join(DATA_DIR, 'logs', 'crash-log-{0}.txt'.format(DATE)) logFile = open(saveDir, 'w') logFile.close() logging.basicConfig(level=logging.DEBUG, filename=saveDir) try: main(1) except Exception as exception: logging.exception("Oops: ") errorbox('Main Error', repr(exception))