Ejemplo n.º 1
0
def load_sounds():
    """
load_sounds() loads all of the sounds in the data/sounds/ directory,
defined in sounds/sounds.dat.
"""

    if not mixerinit:
        # Sound is not initialized. Warn if user wanted sound
        if not nosound:
            sys.stderr.write(
                "WARNING: Sound is requested, but mixer is not initialized!\n")
        return

    sound_class_list = generic_load("sounds.dat", load_dirs="sounds")
    for sound_class in sound_class_list:

        # Make sure the sound class has the filename defined.
        check_required_fields(sound_class, ("filename", ), "Sound")

        # Load each sound in the list, inserting it into the sounds dictionary.
        if type(sound_class["filename"]) != list:
            filenames = [sound_class["filename"]]
        else:
            filenames = sound_class["filename"]

        for filename in filenames:
            all_paths = []
            real_file = dirs.get_readable_file_in_dirs(filename,
                                                       "sounds",
                                                       outer_paths=all_paths)

            # Check to make sure it's a real file; bail if not.
            if real_file is None:
                sys.stderr.write(
                    "ERROR: Cannot load nonexistent soundfile: %s!\n" %
                    "\n".join(paths))
                sys.exit(1)
            else:

                # Load it via the mixer ...
                sound = pygame.mixer.Sound(real_file)

                # And shove it into the sounds dictionary.
                if not sounds.has_key(sound_class["id"]):
                    sounds[sound_class["id"]] = []
                sounds[sound_class["id"]].append({
                    "filename": real_file,
                    "sound": sound
                })
                if debug:
                    sys.stderr.write("DEBUG: Loaded soundfile: %s\n" %
                                     real_file)
Ejemplo n.º 2
0
def load_significant_numbers():
    significant_numbers = g.significant_numbers = []

    numbers_file = dirs.get_readable_file_in_dirs("numbers.dat", "data")

    if numbers_file is None:
        sys.stderr.write("WARNING: Cannot read file: numbers.dat\n")
        return

    with open(numbers_file, 'r') as file:
        for index, line in enumerate(file):
            value = line.split("#")[0].strip()

            if len(value) == 0: continue

            try:
                number = int(value)
                significant_numbers.append(number)
            except ValueError:
                sys.stderr.write("WARNING: Invalid number in 'numbers.dat' line: %d\n" % index)
Ejemplo n.º 3
0
def load_significant_numbers():
    global significant_numbers
    significant_numbers = []

    numbers_file = dirs.get_readable_file_in_dirs("numbers.dat", "data")

    if numbers_file is None:
        sys.stderr.write("WARNING: Cannot read file: numbers.dat\n")
        return

    with open(numbers_file, 'r') as file:
        for index, line in enumerate(file):
            value = line.split("#")[0].strip()

            if len(value) == 0: continue

            try:
                number = int(value)
                significant_numbers.append(number)
            except ValueError:
                sys.stderr.write("WARNING: Invalid number in 'numbers.dat' line: %d\n" % index)
Ejemplo n.º 4
0
        logging.getLogger().addHandler(logging.FileHandler(logfile,
                                                           delay=True))
    except TypeError:  # Python < 2.6, delay not supported yet.
        try:
            logging.getLogger().addHandler(logging.FileHandler(logfile))
        except IOError:  # Probably access denied with --singledir. That's ok
            pass

# keep g's defaults intact so we can compare after parsing options and prefs
import mixer
desired_soundbuf = mixer.soundbuf

desired_set_grab = None

#load prefs from file:
save_loc = dirs.get_readable_file_in_dirs("prefs.dat", "pref")

if save_loc is not None:

    prefs = ConfigParser.SafeConfigParser()
    try:
        savefile = open(save_loc, "r")
        prefs.readfp(savefile)
    except Exception, reason:
        sys.stderr.write("Cannot load preferences file %s! (%s)\n" %
                         (save_loc, reason))
        sys.exit(1)

    if prefs.has_section("Preferences"):
        try:
            desired_language = prefs.get("Preferences", "lang")
Ejemplo n.º 5
0
    try:
        logging.getLogger().addHandler(logging.FileHandler(logfile, delay=True))
    except TypeError: # Python < 2.6, delay not supported yet.
        try:
            logging.getLogger().addHandler(logging.FileHandler(logfile))
        except IOError: # Probably access denied with --singledir. That's ok
            pass

# keep g's defaults intact so we can compare after parsing options and prefs
import mixer
desired_soundbuf = mixer.soundbuf

desired_set_grab = None

#load prefs from file:
save_loc = dirs.get_readable_file_in_dirs("prefs.dat", "pref")

if save_loc is not None:

    prefs = ConfigParser.SafeConfigParser()
    try:
        savefile = open(save_loc, "r")
        prefs.readfp(savefile)
    except Exception, reason:
        sys.stderr.write("Cannot load preferences file %s! (%s)\n" % (save_loc, reason))
        sys.exit(1)

    if prefs.has_section("Preferences"):
        try:
            desired_language = prefs.get("Preferences", "lang")
            if desired_language in i18n.available_languages():