当前位置: 首页>>代码示例>>Python>>正文


Python SimpleXMLSerializer.save方法代码示例

本文整理汇总了Python中fife.extensions.serializers.simplexml.SimpleXMLSerializer.save方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLSerializer.save方法的具体用法?Python SimpleXMLSerializer.save怎么用?Python SimpleXMLSerializer.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fife.extensions.serializers.simplexml.SimpleXMLSerializer的用法示例。


在下文中一共展示了SimpleXMLSerializer.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_project

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
    def new_project(self, settings_path, values):
        """Create a mew project and load it

        Args:
            settings_path: The path to the new settings file

            values: The starting values of the project.
        """
        import tkinter.messagebox
        settings_file = open(settings_path, "w")
        settings_file.write(BASIC_SETTINGS)
        settings_file.close()
        project = SimpleXMLSerializer(settings_path)
        project.load()
        update_settings(project, values)
        project.save()
        comp_file = project.get("fife-rpg", "ComponentsFile")
        act_file = comp_file or project.get("fife-rpg", "ActionsFile")
        syst_file = act_file or project.get("fife-rpg", "SystemsFile")
        beh_file = syst_file or project.get("fife-rpg", "BehavioursFile")
        comb_file = beh_file or project.get("fife-rpg", "CombinedFile")
        if not comb_file:
            dest = os.path.join(os.path.dirname(settings_path),
                                "combined.yaml")
            shutil.copy("combined.yaml.template", dest)
        self.try_load_project(settings_path)
        tkinter.messagebox.showinfo(_("Project created"),
                              _("Project successfully created"))
        self.editor_gui.enable_menus()
        self.project_changed = False
        self.entity_changed = False
开发者ID:fife-rpg,项目名称:editor,代码行数:33,代码来源:fife_rpg_editor.py

示例2: convert_fife_project

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
    def convert_fife_project(self, project_filepath):
        """Converts a fife settings file to a fife-rpg project

        Args:
            Project_filepath: Path to the fife settings file
        """
        project = SimpleXMLSerializer(project_filepath)

        bak_file = "%s.bak" % project_filepath
        project.save(bak_file)
        settings = {}
        settings["ProjectName"] = project.get("FIFE", "WindowTitle", "")
        update_settings(project, settings)
        if not self.edit_project_settings(project_filepath, project):
            return None
        project.save()
        return bak_file
开发者ID:fife-rpg,项目名称:editor,代码行数:19,代码来源:fife_rpg_editor.py

示例3: serialize

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
	def serialize(self):
		filename = os.path.join("saves", self._mapname + "_save.xml")
		playerfilename = os.path.join("saves", "player_save.xml")
		map_settings = SimpleXMLSerializer(filename)
		player_settings = SimpleXMLSerializer(playerfilename)
		
		objectlist = []
		
		for obj in list(self._objectlist.values()):
			ovals = obj.serialize()
			map_settings.set("objects", obj.id, ovals)
			objectlist.append(obj.id)
			
		map_settings.set("objects", "objectlist", objectlist)
		
		pvals = self._player.serialize()
		player_settings.set("player", "player", pvals)
		
		map_settings.save()
		player_settings.save()
开发者ID:fifengine,项目名称:fifengine-demos,代码行数:22,代码来源:scene.py

示例4: _setup_settings

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
	def _setup_settings(self, check_file_version=True):
		_user_config_file = os.path.join( os.getcwd(), PATHS.USER_CONFIG_FILE )
		if check_file_version and os.path.exists(_user_config_file):
			# check if user settings file is the current one

			# NOTE: SimpleXMLSerializer can't handle relative paths, it fails silently
			# (although the doc states otherwise) - thus translate paths to absolute ones
			user_config_parser = SimpleXMLSerializer( _user_config_file )
			user_settings_version = user_config_parser.get("meta", "SettingsVersion", -1)
			_template_config_file = os.path.join( os.getcwd(), PATHS.CONFIG_TEMPLATE_FILE )
			template_config_parser = SimpleXMLSerializer( _template_config_file )
			template_settings_version = template_config_parser.get("meta", "SettingsVersion")

			if template_settings_version > user_settings_version: # we have to update the file
				print 'Discovered old settings file, auto-upgrading: %s -> %s' % \
				      (user_settings_version, template_settings_version)
				# create settings so we have a list of all settings
				self._setup_settings(check_file_version=False)

				# save settings here
				entries = []

				# need safe default value
				default_value = object()

				def update_value(modulename, entryname):
					# retrieve values from loaded settings file
					try:
						value = self._setting.get(modulename, entryname, default_value)
					except UnicodeEncodeError: # this can happen when unicode data is saved as str
						value = "default"
					if value is not default_value:
						entries.append( (modulename, entryname, value ) )

				# collect values from known settings and unreferenced settings
				for modulename, module in self._setting.entries.iteritems():
					for entryname in module.iterkeys():
						update_value(modulename, entryname)
				for modulename, entry_list in self.UNREFERENCED_SETTINGS.iteritems():
					for entryname in entry_list:
						update_value(modulename, entryname)

				# patch old values
				if user_settings_version <= 10:
					old_entries = entries
					entries = []
					for i in old_entries:
						if i[0] == UH_MODULE and i[1] == "Language":
							entries.append( (i[0], i[1], LANGUAGENAMES.get_by_value(i[2])) )
						else:
							entries.append(i)

				# write actual new file
				shutil.copy( PATHS.CONFIG_TEMPLATE_FILE, PATHS.USER_CONFIG_FILE )
				user_config_parser = SimpleXMLSerializer( _user_config_file )
				for modulename, entryname, value in entries:
					user_config_parser.set(modulename, entryname, value)
				user_config_parser.save()

		self._setting = SettingsDialog(app_name=UH_MODULE,
				                         settings_file=PATHS.USER_CONFIG_FILE,
				                         settings_gui_xml="settings.xml",
				                         changes_gui_xml="requirerestart.xml",
				                         default_settings_file=PATHS.CONFIG_TEMPLATE_FILE)

		self._setting_handler.add_settings()
开发者ID:DanielStephens,项目名称:unknown-horizons,代码行数:68,代码来源:engine.py

示例5: __init__

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
class Settings:

	# Settings key storing the SettingsVersion used to upgrade settings
	SETTINGS_VERSION = "SettingsVersion"

	def __init__(self, settings_file, settings_template_file):
		self._module_settings = {}
		self._module_settings_template = {}
		self._settings_file = settings_file
		self._settings_template_file = settings_template_file
		self._settings_serializer = SimpleXMLSerializer()
		self._settings_serializer.load(settings_file)
		self._settings_template_serializer = SimpleXMLSerializer()
		self._settings_template_serializer.load(settings_template_file)
		if not hasattr(self._settings_template_serializer, 'getModuleName'):
			# Renamed after 0.3.5: https://github.com/fifengine/fifengine/issues/819.
			new_api = self._settings_template_serializer.getModuleNameList
			self._settings_template_serializer.getModuleName = new_api
		self.upgrade_settings()

	def get(self, module, name, default=None):
		if default is None:
			default = self._settings_template_serializer.get(module, name)

		v = self._settings_serializer.get(module, name, default)
		getter = getattr(self, 'get_' + module + '_' + name, None)
		if getter:
			return getter(v)
		else:
			return v

	def set(self, module, name, value):
		setter = getattr(self, 'set_' + module + '_' + name, None)
		if setter:
			value = setter(value)

		# This is necessary, as empty fields return None, but saving
		# None will result in the String 'None' being stored
		if value is None:
			value = ''

		if module in self._module_settings:
			self._module_settings[module][name] = value

		self._settings_serializer.set(module, name, value, {})

	def get_module_settings(self, module):
		self._module_settings[module] = self._settings_serializer.getAllSettings(module)
		self._module_settings_template[module] = self._settings_template_serializer.getAllSettings(module)
		for name, value in self._module_settings_template[module].items():
			if name not in self._module_settings[module]:
				self._module_settings[module][name] = value
		return self._module_settings[module]

	def get_module_template_settings(self, module):
		return self._settings_template_serializer.getAllSettings(module)

	def save(self):
		self._settings_serializer.save(self._settings_file)

	def apply(self):
		data = self.get(SETTINGS.UH_MODULE, "Language")
		language = LANGUAGENAMES.get_by_value(data)
		change_language(language)

	def set_defaults(self):
		for module in self._settings_template_serializer.getModuleName():
			for setting_name in self._settings_template_serializer.getAllSettings(module):
				value = self._settings_template_serializer.get(module, setting_name)
				self.set(module, setting_name, value)
		self.save()

	def upgrade_settings(self):
		"""Upgrades the settings to a newer version necessary."""
		# if the settings file doesn't exist, force an update with
		# settings version 1 as default value
		current_version = self.get(SETTINGS.META_MODULE, self.SETTINGS_VERSION, 1)
		template_version = self._settings_template_serializer.get(SETTINGS.META_MODULE, self.SETTINGS_VERSION)
		if current_version != template_version:
			print('Discovered old settings file, auto-upgrading: {} -> {}'.format(
		          current_version, template_version))
			for module in self._settings_template_serializer.getModuleName():
				for setting_name in self._settings_template_serializer.getAllSettings(module):
					default_value = self._settings_template_serializer.get(module, setting_name)
					if self.get(module, setting_name, default=default_value) is default_value:
						self.set(module, setting_name, default_value)
			self.set(SETTINGS.META_MODULE, self.SETTINGS_VERSION, template_version)
			self.save()

	# settings

	def get_unknownhorizons_Language(self, value):
		if value is None: # the entry is None for empty strings
			value = ""
		return LANGUAGENAMES[value]

	def set_unknownhorizons_Language(self, value):
		return LANGUAGENAMES.get_by_value(value)
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:100,代码来源:settings.py

示例6: Setting

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]

#.........这里部分代码省略.........
		if validSetting:
			return self._validSetting[module][name]
		else:
			return self._defaultSetting[module][name]

	# sets valid resolution options in the settings->Resolution
	def setValidResolutions(self, options):
		if options:
			self._resolutions = options
		self.createAndAddEntry(FIFE_MODULE, "ScreenResolution", initialdata = self._resolutions,
		              requiresrestart=True)

	def initSerializer(self):
		self._serializer.load(os.path.join(self._appdata, self._settings_file))

	def _initDefaultSettingEntries(self):
		"""Initializes the default fife setting entries. Not to be called from
		outside this class."""
		self.createAndAddEntry(FIFE_MODULE, "PlaySounds", requiresrestart=True)

		self.createAndAddEntry(FIFE_MODULE, "FullScreen", requiresrestart=True)

		self.createAndAddEntry(FIFE_MODULE, "ScreenResolution", initialdata = self._resolutions, requiresrestart=True)

		self.createAndAddEntry(FIFE_MODULE, "RenderBackend", initialdata = self._renderbackends, requiresrestart=True)

	def createAndAddEntry(self, module, name, applyfunction=None, initialdata=None, requiresrestart=False):
		""""
		@param module: The Setting module this Entry belongs to
		@type module: C{String}
		@param name: The Setting's name
		@type name: C{String}
		@param applyfunction: function that makes the changes when the Setting is
		saved
		@type applyfunction: C{function}
		@param initialdata: If the widget supports the setInitialData() function
		this can be used to set the initial data
		@type initialdata: C{String} or C{Boolean}
		@param requiresrestart: Whether or not the changing of this setting
		requires a restart
		@type requiresrestart: C{Boolean}
		"""
		entry = SettingEntry(module, name, applyfunction, initialdata, requiresrestart)
		self.addEntry(entry)

	def addEntry(self, entry):
		"""Adds a new C{SettingEntry} to the Settting
		@param entry: A new SettingEntry that is to be added
		@type entry: C{SettingEntry}
		"""
		if entry.module not in self._entries:
			self._entries[entry.module] = {}
		self._entries[entry.module][entry.name] = entry

		"""
		# Make sure the new entry is available
		if self.get(entry.module, entry.name) is None:
			print "Updating", self._settings_file, "to the default, it is missing the entry:"\
			      , entry.name ,"for module", entry.module

			#self.setDefaults()
		if self.get(entry.module, entry.name) is None:
			print "WARNING:", entry.module, ":", entry.name, "still not found!"
		"""

	def saveSettings(self, filename=""):
开发者ID:cheif,项目名称:fifengine,代码行数:70,代码来源:fife_settings.py

示例7: Setting

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]

#.........这里部分代码省略.........
			self._serializer = SimpleXMLSerializer()
	
		self.initSerializer()
	
		self._initDefaultSettingEntries()

	def initSerializer(self):
		self._serializer.load(os.path.join(self._appdata, self._settings_file))
		
	def _initDefaultSettingEntries(self):
		"""Initializes the default fife setting entries. Not to be called from
		outside this class."""
		self.createAndAddEntry(FIFE_MODULE, "PlaySounds", "enable_sound",
		              requiresrestart=True)
		self.createAndAddEntry(FIFE_MODULE, "FullScreen", "enable_fullscreen",
		              requiresrestart=True)
		self.createAndAddEntry(FIFE_MODULE, "ScreenResolution", "screen_resolution", initialdata = self._resolutions,
		              requiresrestart=True)
		self.createAndAddEntry(FIFE_MODULE, "RenderBackend", "render_backend", initialdata = self._renderbackends,
		              requiresrestart=True)
		self.createAndAddEntry(FIFE_MODULE, "Lighting", "lighting_model", initialdata = self._lightingmodels,
		              requiresrestart=True)

	def createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False):
		""""
		@param module: The Setting module this Entry belongs to
		@type module: C{String}
		@param name: The Setting's name
		@type name: C{String}
		@param widgetname: The name of the widget that is used to change this
		setting
		@type widgetname: C{String}
		@param applyfunction: function that makes the changes when the Setting is
		saved
		@type applyfunction: C{function}
		@param initialdata: If the widget supports the setInitialData() function
		this can be used to set the initial data
		@type initialdata: C{String} or C{Boolean}
		@param requiresrestart: Whether or not the changing of this setting
		requires a restart
		@type requiresrestart: C{Boolean}
		"""
		entry = SettingEntry(module, name, widgetname, applyfunction, initialdata, requiresrestart)
		self.addEntry(entry)

	def addEntry(self, entry):
		"""Adds a new C{SettingEntry} to the Settting
		@param entry: A new SettingEntry that is to be added
		@type entry: C{SettingEntry}
		"""
		if entry.module not in self._entries:
			self._entries[entry.module] = {}
		self._entries[entry.module][entry.name] = entry

		# Make sure the new entry is available
		if self.get(entry.module, entry.name) is None:
			print "Updating", self._settings_file, "to the default, it is missing the entry:"\
			      , entry.name ,"for module", entry.module
			self.setDefaults()
		if self.get(entry.module, entry.name) is None:
			print "WARNING:", entry.module, ":", entry.name, "still not found!"


	def saveSettings(self, filename=""):
		""" Writes the settings to the settings file 
		
开发者ID:mgeorgehansen,项目名称:FIFE_Technomage,代码行数:69,代码来源:fife_settings.py

示例8: _setup_settings

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
	def _setup_settings(self, check_file_version=True):
		_user_config_file = os.path.join( os.getcwd(), PATHS.USER_CONFIG_FILE )
		if not os.path.exists(_user_config_file):
			check_file_version = False
		if check_file_version:
			# check if user settings file is the current one

			# NOTE: SimpleXMLSerializer can't handle relative paths, it fails silently
			# (although the doc states otherwise) - thus translate paths to absolute ones
			user_config_parser = SimpleXMLSerializer( _user_config_file )
			user_settings_version = user_config_parser.get("meta", "SettingsVersion", -1)
			_template_config_file = os.path.join( os.getcwd(), PATHS.CONFIG_TEMPLATE_FILE )
			template_config_parser = SimpleXMLSerializer( _template_config_file )
			template_settings_version = template_config_parser.get("meta", "SettingsVersion")

			if template_settings_version > user_settings_version: # we have to update the file
				# create settings so we have a list of all settings
				self._setup_settings(check_file_version=False)

				# save settings here
				entries = []
				def update_value(modulename, entryname):
					# retrieve values from loaded settings file
					try:
						value = self._setting.get(modulename, entryname)
					except UnicodeEncodeError: # this can happen when unicode data is saved as str
						value = "default"
					entries.append( (modulename, entryname, value ) )

				# update known settings and unreferenced settings
				for modulename, module in self._setting.entries.iteritems():
					for entryname in module.iterkeys():
						update_value(modulename, entryname)
				for modulename, entry_list in self.UNREFERENCED_SETTINGS.iteritems():
					for entryname in entry_list:
						update_value(modulename, entryname)

				# write actual new file
				shutil.copy( PATHS.CONFIG_TEMPLATE_FILE, PATHS.USER_CONFIG_FILE )
				user_config_parser = SimpleXMLSerializer( _user_config_file )
				for modulename, entryname, value in entries:
					user_config_parser.set(modulename, entryname, value)
				user_config_parser.save()

		self._setting = LocalizedSetting(app_name=UH_MODULE,
		                                 settings_file=PATHS.USER_CONFIG_FILE,
		                                 settings_gui_xml="settings.xml",
		                                 changes_gui_xml="requirerestart.xml",
		                                 default_settings_file=PATHS.CONFIG_TEMPLATE_FILE)

		# TODO: find a way to apply changing to a running game in a clean fashion
		#       possibility: use singaling via changelistener
		def update_minimap(*args):
			try: horizons.main._modules.session.ingame_gui.minimap.draw()
			except AttributeError: pass # session or gui not yet initialised

		def update_autosave_interval(*args):
			try: horizons.main._modules.session.reset_autosave()
			except AttributeError: pass # session or gui not yet initialised


		#self.createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False)
		self._setting.createAndAddEntry(UH_MODULE, "AutosaveInterval", "autosaveinterval",
		                                applyfunction=update_autosave_interval)
		self._setting.createAndAddEntry(UH_MODULE, "AutosaveMaxCount", "autosavemaxcount")
		self._setting.createAndAddEntry(UH_MODULE, "QuicksaveMaxCount", "quicksavemaxcount")
		self._setting.createAndAddEntry(UH_MODULE, "EdgeScrolling", "edgescrolling")
		self._setting.createAndAddEntry(UH_MODULE, "UninterruptedBuilding", "uninterrupted_building")

		self._setting.createAndAddEntry(UH_MODULE, "MinimapRotation", "minimaprotation", \
		                                applyfunction=update_minimap)

		self._setting.createAndAddEntry(FIFE_MODULE, "BitsPerPixel", "screen_bpp",
		                                initialdata=[0, 16, 32], requiresrestart=True)

		languages_map = dict(find_available_languages())
		languages_map[_('System default')] = ''
		# English is not shipped as .mo file.
		languages_map['en'] = ''

		self._setting.createAndAddEntry(UH_MODULE, "Language", "language",
		                                applyfunction=self.update_languages,
		                                initialdata= [LANGUAGENAMES[x] for x in sorted(languages_map.keys())])
		self._setting.createAndAddEntry(UH_MODULE, "VolumeMusic", "volume_music",
		                                applyfunction=self.set_volume_music)
		self._setting.createAndAddEntry(UH_MODULE, "VolumeEffects", "volume_effects",
		                                applyfunction=self.set_volume_effects)

		self._setting.createAndAddEntry(UH_MODULE, "NetworkPort", "network_port",
		                                applyfunction=self.set_network_port)


		self._setting.entries[FIFE_MODULE]['PlaySounds'].applyfunction = lambda x: self.setup_sound()
		self._setting.entries[FIFE_MODULE]['PlaySounds'].requiresrestart = False

		self._setting.entries[FIFE_MODULE]['RenderBackend'].applyfunction = lambda x: self._show_renderbackend_warning()
开发者ID:slbucur,项目名称:unknown-horizons,代码行数:98,代码来源:engine.py

示例9: raw_input

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
if os.path.isdir(fife_path) and fife_path not in sys.path:
	sys.path.insert(0,fife_path)

# Load the XML Serialiser:
from fife.extensions.serializers.simplexml import SimpleXMLSerializer

print """ ____  _  ____  _____  _  ____  _  ____ _____ 
| _) \| |/ (__`|_   _|| || ===|| || ===|| () )
|____/|_|\____)  |_|  |_||__|  |_||____||_|\_\

Python Dict to FIFE XML Serial Format Converter
"""

filename = raw_input("XML Filename: ")
xml = SimpleXMLSerializer(filename)

dict = {}
loop = True

while loop:
    key = raw_input("Key: ")
    dict[key] = raw_input("Value: ")
    print "Add more? Y/n"
    if raw_input() == "n":
        loop = False
        
dictstore = xml._serializeDict(dict)
xml.set(raw_input("Module: "), raw_input("Name: "), dictstore)
xml.save(filename)
print filename + " has been updated with the new dict entry. Press enter to end this python shell"
raw_input()
开发者ID:Drakekin,项目名称:Zero-Sum-Cascade-Old,代码行数:33,代码来源:dictify.py

示例10: Settings

# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import save [as 别名]
class Settings(object):

	# Settings key storing the SettingsVersion used to upgrade settings
	SETTINGS_VERSION = "SettingsVersion"

	def __init__(self, settings_file, settings_template_file):
		self._module_settings = {}
		self._module_settings_template = {}
		self._settings_file = settings_file
		self._settings_template_file = settings_template_file
		self._settings_serializer = SimpleXMLSerializer()
		self._settings_serializer.load(settings_file)
		self._settings_template_serializer = SimpleXMLSerializer()
		self._settings_template_serializer.load(settings_template_file)
		self.upgrade_settings()

	def get(self, module, name, default=None):
		if default is None:
			default = self._settings_template_serializer.get(module, name)

		v = self._settings_serializer.get(module, name, default)
		getter = getattr(self, 'get_' + module + '_' + name, None)
		if getter:
			return getter(v)
		else:
			return v

	def set(self, module, name, value):
		setter = getattr(self, 'set_' + module + '_' + name, None)
		if setter:
			value = setter(value)

		# This is necessary, as empty fields return None, but saving
		# None will result in the String 'None' being stored
		if value is None:
			value = ''

		if module in self._module_settings:
			self._module_settings[module][name] = value

		self._settings_serializer.set(module, name, value, {})

	def get_module_settings(self, module):
		self._module_settings[module] = self._settings_serializer.getAllSettings(module)
		self._module_settings_template[module] = self._settings_template_serializer.getAllSettings(module)
		for name, value in self._module_settings_template[module].iteritems():
			if name not in self._module_settings[module]:
				self._module_settings[module][name] = value
		return self._module_settings[module]

	def get_module_template_settings(self, module):
		return self._settings_template_serializer.getAllSettings(module)

	def save(self):
		self._settings_serializer.save(self._settings_file)

	def apply(self):
		data = self.get(SETTINGS.UH_MODULE, "Language")
		language = LANGUAGENAMES.get_by_value(data)
		change_language(language)

	def set_defaults(self):
		for module in self._settings_template_serializer.getModuleName():
			for setting_name in self._settings_template_serializer.getAllSettings(module):
				value = self._settings_template_serializer.get(module, setting_name)
				self.set(module, setting_name, value)
		self.save()

	def upgrade_settings(self):
		"""Upgrades the settings to a newer version necessary."""
		current_version = self.get(SETTINGS.META_MODULE, self.SETTINGS_VERSION)
		template_version = self._settings_template_serializer.get(SETTINGS.META_MODULE, self.SETTINGS_VERSION)
		if current_version != template_version:
			print 'Discovered old settings file, auto-upgrading: %s -> %s' % \
		          (current_version, template_version)
			for module in self._settings_template_serializer.getModuleName():
				for setting_name in self._settings_template_serializer.getAllSettings(module):
					default_value = self._settings_template_serializer.get(module, setting_name)
					if self.get(module, setting_name, default=default_value) is default_value:
						self.set(module, setting_name, default_value)
			self.set(SETTINGS.META_MODULE, self.SETTINGS_VERSION, template_version)
			self.save()

	# settings

	def get_unknownhorizons_Language(self, value):
		if value is None: # the entry is None for empty strings
			value = ""
		return LANGUAGENAMES[value]

	def set_unknownhorizons_Language(self, value):
		return LANGUAGENAMES.get_by_value(value)
开发者ID:JonathanMeans,项目名称:unknown-horizons,代码行数:94,代码来源:settings.py


注:本文中的fife.extensions.serializers.simplexml.SimpleXMLSerializer.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。