當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleXMLSerializer.remove方法代碼示例

本文整理匯總了Python中fife.extensions.serializers.simplexml.SimpleXMLSerializer.remove方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleXMLSerializer.remove方法的具體用法?Python SimpleXMLSerializer.remove怎麽用?Python SimpleXMLSerializer.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fife.extensions.serializers.simplexml.SimpleXMLSerializer的用法示例。


在下文中一共展示了SimpleXMLSerializer.remove方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Setting

# 需要導入模塊: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 別名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import remove [as 別名]

#.........這裏部分代碼省略.........
		@param name: Setting name
		@param defaultValue: Specifies the default value to return if the setting is not found
		@type defaultValue: C{str} or C{unicode} or C{int} or C{float} or C{bool} or C{list} or C{dict}
		"""

		if self._serializer:
			if module is "FIFE":
				# check whether getAllSettings has been called already
				if self._readSettingsCompleted[module] is not True:
					value = self._serializer.get(module, name, defaultValue)

					if value is not None:
						return value
					else:
						if name in self._defaultSetting[module]:
							return self._defaultSetting[module][name]
						else:
							raise Exception(str(name) + ' is neither in settings.xml nor it has a default value set')
				else:
					if name in self._settingsFromFile[module]:
						return self._settingsFromFile[module][name]
					else:
						raise Exception(str(name) + ' is neither in settings.xml nor it has a default value set')
			else:
				return self._serializer.get(module, name, defaultValue)
		else:
			"""
			serializer not set, reading from default value
			"""
			if name in self._defaultSetting:
				return self._defaultSetting[module][name]
			else:
				raise Exception(str(name) + ' is neither in settings.xml nor it has a default value set')

	def set(self, module, name, value, extra_attrs={}):
		"""
		Sets a setting to specified value.

		@param module: Module where the setting should be set
		@param name: Name of setting
		@param value: Value to assign to setting
		@type value: C{str} or C{unicode} or C{int} or C{float} or C{bool} or C{list} or C{dict}
		@param extra_attrs: Extra attributes to be stored in the XML-file
		@type extra_attrs: C{dict}
		"""

		#update the setting cache
		if module in self._settingsFromFile:
			self._settingsFromFile[module][name] = value
		else:
			self._settingsFromFile[module] = { name: value }

		if self._serializer:
			self._serializer.set(module, name, value, extra_attrs)

	def remove(self, module, name):
		"""
		Removes a variable

		@param module: Module where the variable should be set
		@param name: Name of the variable
		"""
		#update the setting cache
		if module in self._settingsFromFile:
			del self._settingsFromFile[module][name]

		if self._serializer:
			self._serializer.remove(module, name)

	def setAvailableScreenResolutions(self, reslist):
		"""
		A list of valid default screen resolutions.   This should be called once
		right after you instantiate Settings.

		Valid screen resolutions must be strings in the form of: WIDTHxHEIGHT

		Example:
			settings.setAvailableScreenResolutions(["800x600", "1024x768"])
		"""
		self._resolutions = reslist

	def setDefaults(self):
		"""
		Overwrites the setting file with the default settings file.
		"""
		shutil.copyfile(self._default_settings_file, os.path.join(self._appdata, self._settings_file))
		self.changesRequireRestart = True
		self.initSerializer()

	def _getEntries(self):
		return self._entries

	def _setEntries(self, entries):
		self._entries = entries

	def _getSerializer(self):
		return self._serializer

	entries = property(_getEntries, _setEntries)
	serializer = property(_getSerializer)
開發者ID:jakoch,項目名稱:fifengine,代碼行數:104,代碼來源:fife_settings.py


注:本文中的fife.extensions.serializers.simplexml.SimpleXMLSerializer.remove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。