Esempio n. 1
0
class Settings:
    """
	Handles loading/saving settings from/to a file on disk.
	"""

    # the different settings in each config block
    general = {
        # increment each time there is an incompatible change with the config file
        "version": "1",
        "recentprojects": "value",
        "startupaction": "value",
        "projectfolder": "",
        "windowheight": 550,
        "windowwidth": 900,
        "addinstrumentwindowheight": 350,
        "addinstrumentwindowwidth": 300,
        "instrumenteffectwindowheight": 450,
        "instrumenteffectwindowwidth": 650,
    }

    recording = {
        "fileformat": "flacenc",
        "file_extension": "flac",
        "samplerate":
        "0",  # zero means, autodetect sample rate (ie use any available)
        "audiosrc": "gconfaudiosrc",
        "device": "default"
    }
    # Overwrite with platform specific settings
    recording.update(PlatformUtils.GetRecordingDefaults())

    playback = {
        "devicename": "default",
        "device": "default",
        "audiosink": "autoaudiosink"
    }
    # Overwrite with platform specific settings
    playback.update(PlatformUtils.GetPlaybackDefaults())

    extensions = {"extensions_blacklist": ""}

    sections = {
        "General": general,
        "Recording": recording,
        "Playback": playback,
        "Extensions": extensions
    }

    #_____________________________________________________________________

    def __init__(self):
        self.filename = os.path.join(JOKOSHER_CONFIG_HOME, "config")

        self.config = ConfigParser.ConfigParser()
        self.read()

    #_____________________________________________________________________

    def read(self):
        """
		Reads configuration settings from the config file and loads
		then into the Settings dictionaries.
		"""
        self.config.read(self.filename)

        for section in self.sections:
            if not self.config.has_section(section):
                self.config.add_section(section)

        for section, section_dict in self.sections.iteritems():
            for key, value in self.config.items(section):
                if value == "None":
                    value = None
                section_dict[key] = value

    #_____________________________________________________________________

    def write(self):
        """
		Writes configuration settings to the Settings config file.
		"""

        for section, section_dict in self.sections.iteritems():
            for key, value in section_dict.iteritems():
                self.config.set(section, key, value)

        file = open(self.filename, 'w')
        self.config.write(file)
        file.close()
Esempio n. 2
0
class Settings:
    """
	Handles loading/saving settings from/to a file on disk.
	"""

    # the different settings in each config block
    general = {
        # increment each time there is an incompatible change with the config file
        "version": "1",
        "recentprojects": "",  #deprecated
        "startupaction": "value",
        "projectfolder": "",
        "windowheight": 550,
        "windowwidth": 900,
        "addinstrumentwindowheight": 350,
        "addinstrumentwindowwidth": 300,
        "instrumenteffectwindowheight": 450,
        "instrumenteffectwindowwidth": 650,
    }

    recording = {
        "fileformat": "vorbisenc bitrate=%(bitrate)d ! oggmux",
        "file_extension": "ogg",
        "samplerate":
        "0",  # zero means, autodetect sample rate (ie use any available)
        "bitrate": "131072",
        "audiosrc": "gconfaudiosrc",
        "device": "default"
    }
    # Overwrite with platform specific settings
    recording.update(PlatformUtils.GetRecordingDefaults())

    playback = {
        "devicename": "default",
        "device": "default",
        "audiosink": "autoaudiosink"
    }
    # Overwrite with platform specific settings
    playback.update(PlatformUtils.GetPlaybackDefaults())

    extensions = {"extensions_blacklist": ""}

    recentprojects = {
        #FIXME: replace with some kind of proper database since
        # we now plan to store all the projects created ever
        # (not just the last 8 used)
        "paths": "",
        "names": "",
        "create_times": "",
        "last_used_times": "",
    }

    sections = {
        "General": general,
        "Recording": recording,
        "Playback": playback,
        "Extensions": extensions,
        "RecentProjects": recentprojects,
    }

    #_____________________________________________________________________

    def __init__(self):
        self.filename = os.path.join(JOKOSHER_CONFIG_HOME, "config")
        # Use RawConfigParser so that parameters in pipelines don't get processed
        self.config = ConfigParser.RawConfigParser()
        self.read()

    #_____________________________________________________________________

    def read(self):
        """
		Reads configuration settings from the config file and loads
		then into the Settings dictionaries.
		"""
        self.config.read(self.filename)

        for section in self.sections:
            if not self.config.has_section(section):
                self.config.add_section(section)

        for section, section_dict in self.sections.iteritems():
            for key, value in self.config.items(section):
                if value == "None":
                    value = None
                section_dict[key] = value

    #_____________________________________________________________________

    def write(self):
        """
		Writes configuration settings to the Settings config file.
		"""

        for section, section_dict in self.sections.iteritems():
            for key, value in section_dict.iteritems():
                self.config.set(section, key, value)

        file = open(self.filename, 'w')
        self.config.write(file)
        file.close()