本文整理汇总了Python中fife.extensions.serializers.simplexml.SimpleXMLSerializer.load方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLSerializer.load方法的具体用法?Python SimpleXMLSerializer.load怎么用?Python SimpleXMLSerializer.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fife.extensions.serializers.simplexml.SimpleXMLSerializer
的用法示例。
在下文中一共展示了SimpleXMLSerializer.load方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_project
# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import load [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
示例2: load_project
# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import load [as 别名]
def load_project(self, filepath):
"""Tries to load a project
Args:
filepath: The path to the project file.
Returns: True of the project was loaded. False if not."""
try:
self.clear()
except Exception as error: # pylint: disable=broad-except
print(error)
settings = SimpleXMLSerializer()
try:
settings.load(filepath)
except (InvalidFormat, ET.ParseError):
return False
if "fife-rpg" in settings.getModuleNameList():
self.project = settings
project_dir = str(os.path.normpath(os.path.split(filepath)[0]))
self.engine.getVFS().addNewSource(project_dir)
self.project_source = project_dir
self.project_dir = project_dir
self.load_project_settings()
self.changed_maps = []
self.project_changed = False
self.entity_changed = False
try:
old_dir = os.getcwd()
os.chdir(self.project_dir)
self.load_maps()
os.chdir(old_dir)
except: # pylint: disable=bare-except
pass
return True
return False
示例3: __init__
# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import load [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)
示例4: Setting
# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import load [as 别名]
class Setting(object):
"""
This class manages loading and saving of game settings.
Usage::
from fife.extensions.fife_settings import Setting
settings = Setting(app_name="myapp")
screen_width = settings.get("FIFE", "ScreenWidth", 1024)
screen_height = settings.get("FIFE", "ScreenHeight", 768)
"""
def __init__(self, app_name="", settings_file="", default_settings_file= "settings-dist.xml", copy_dist=True, serializer=None):
"""
Initializes the Setting object.
@param app_name: The applications name. If this parameter is provided
alone it will try to read the settings file from the users home directory.
In windows this will be something like: C:\Documents and Settings\user\Application Data\fife
@type app_name: C{string}
@param settings_file: The name of the settings file. If this parameter is
provided it will look for the setting file as you specify it, first looking
in the working directory. It will NOT look in the users home directory.
@type settings_file: C{string}
@param default_settings_file: The name of the default settings file. If the settings_file
does not exist this file will be copied into the place of the settings_file. This file
must exist in the root directory of your project!
@type default_settings_file: C{string}
@param settings_gui_xml: If you specify this parameter you can customize the look
of the settings dialog box.
@param copy_dist: Copies the default settings file to the settings_file location. If
this is False it will create a new empty setting file.
@param serializer: Overrides the default XML serializer
@type serializer: C{SimpleSerializer}
"""
self._app_name = app_name
self._settings_file = settings_file
self._default_settings_file = default_settings_file
# Holds SettingEntries
self._entries = {}
if self._settings_file == "":
self._settings_file = "settings.xml"
self._appdata = getUserDataDirectory("fife", self._app_name)
else:
self._appdata = os.path.dirname(self._settings_file)
self._settings_file = os.path.basename(self._settings_file)
if not os.path.exists(os.path.join(self._appdata, self._settings_file)):
if os.path.exists(self._default_settings_file) and copy_dist:
shutil.copyfile(self._default_settings_file, os.path.join(self._appdata, self._settings_file))
# valid values possible for the engineSettings
self._validSetting = {}
self._validSetting['FIFE'] = {
'FullScreen':[True,False], 'PychanDebug':[True,False]
, 'ProfilingOn':[True,False], 'SDLRemoveFakeAlpha':[True,False], 'GLCompressImages':[False,True], 'GLUseFramebuffer':[False,True], 'GLUseNPOT':[False,True],
'GLUseMipmapping':[False,True], 'GLTextureFiltering':['None', 'Bilinear', 'Trilinear', 'Anisotropic'], 'GLUseMonochrome':[False,True],
'GLUseDepthBuffer':[False,True], 'GLAlphaTestValue':[0.0,1.0],
'RenderBackend':['OpenGL', 'SDL'],
'ScreenResolution':['640x480', '800x600', '1024x600', '1024x768', '1280x768',
'1280x800', '1280x960', '1280x1024', '1366x768', '1440x900',
'1600x900', '1600x1200', '1680x1050', '1920x1080', '1920x1200'],
'BitsPerPixel':[0,16,24,32],
'InitialVolume':[0.0,10.0], 'WindowTitle':"", 'WindowIcon':"", 'Font':"",
'FontGlyphs':"", 'DefaultFontSize':"", 'Lighting':[0,1],
'ColorKeyEnabled':[True,False], 'ColorKey':['a','b','c'], 'VideoDriver':"",
'PlaySounds':[True,False], 'LogToFile':[True,False],
'LogToPrompt':[True,False],'UsePsyco':[True,False], 'LogLevelFilter':[0,1,2,3],
'LogModules':['all', 'controller','script','video','audio','loaders','vfs','pool','view','model','metamodel','event_channel','xml'],
'FrameLimitEnabled':[True,False], 'FrameLimit':[0], 'MouseSensitivity':[0.0], 'MouseAcceleration':[True,False]
}
glyphDft = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\\\""
# we at this point assume default values are final values for engineSettings
self._defaultSetting = {}
self._defaultSetting['FIFE'] = {
'FullScreen':False, 'PychanDebug':False
, 'ProfilingOn':False, 'SDLRemoveFakeAlpha':False, 'GLCompressImages':False, 'GLUseFramebuffer':True, 'GLUseNPOT':True,
'GLUseMipmapping':False, 'GLTextureFiltering':'None', 'GLUseMonochrome':False, 'GLUseDepthBuffer':False, 'GLAlphaTestValue':0.3,
'RenderBackend':'OpenGL', 'ScreenResolution':"1024x768", 'BitsPerPixel':0,
'InitialVolume':5.0, 'WindowTitle':"", 'WindowIcon':"", 'Font':"",
'FontGlyphs':glyphDft, 'DefaultFontSize':12, 'Lighting':0,
'ColorKeyEnabled':False, 'ColorKey':[255,0,255], 'VideoDriver':"",
'PlaySounds':True, 'LogToFile':False,
'LogToPrompt':False,'UsePsyco':False,'LogLevelFilter':[0],
'LogModules':['controller','script'],
'FrameLimitEnabled':False, 'FrameLimit':60,
'MouseSensitivity':0.0,
'MouseAcceleration':False
}
# has the settings file been read
self._readSettingsCompleted = {}
# the global dictionary from which we will read after self._readSettingsCompleted is True
self._settingsFromFile = {}
#.........这里部分代码省略.........
示例5: Setting
# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import load [as 别名]
class Setting(object):
"""
This class manages loading and saving of game settings.
Usage::
from fife.extensions.fife_settings import Setting
settings = Setting(app_name="myapp")
screen_width = settings.get("FIFE", "ScreenWidth", 1024)
screen_height = settings.get("FIFE", "ScreenHeight", 768)
"""
def __init__(self, app_name="", settings_file="", default_settings_file= "settings-dist.xml", settings_gui_xml="", changes_gui_xml="", copy_dist=True, serializer=None):
"""
Initializes the Setting object.
@param app_name: The applications name. If this parameter is provided
alone it will try to read the settings file from the users home directory.
In windows this will be something like: C:\Documents and Settings\user\Application Data\fife
@type app_name: C{string}
@param settings_file: The name of the settings file. If this parameter is
provided it will look for the setting file as you specify it, first looking
in the working directory. It will NOT look in the users home directory.
@type settings_file: C{string}
@param default_settings_file: The name of the default settings file. If the settings_file
does not exist this file will be copied into the place of the settings_file. This file
must exist in the root directory of your project!
@type default_settings_file: C{string}
@param settings_gui_xml: If you specify this parameter you can customize the look
of the settings dialog box.
@param copy_dist: Copies the default settings file to the settings_file location. If
this is False it will create a new empty setting file.
@param serializer: Overrides the default XML serializer
@type serializer: C{SimpleSerializer}
"""
self._app_name = app_name
self._settings_file = settings_file
self._default_settings_file = default_settings_file
self._settings_gui_xml = settings_gui_xml
self._changes_gui_xml = changes_gui_xml
self.OptionsDlg = None
# Holds SettingEntries
self._entries = {}
if self._settings_file == "":
self._settings_file = "settings.xml"
self._appdata = getUserDataDirectory("fife", self._app_name)
else:
self._appdata = os.path.dirname(self._settings_file)
self._settings_file = os.path.basename(self._settings_file)
if self._settings_gui_xml == "":
self._settings_gui_xml = SETTINGS_GUI_XML
if self._changes_gui_xml == "":
self._changes_gui_xml = CHANGES_REQUIRE_RESTART
if not os.path.exists(os.path.join(self._appdata, self._settings_file)):
if os.path.exists(self._default_settings_file) and copy_dist:
shutil.copyfile(self._default_settings_file, os.path.join(self._appdata, self._settings_file))
#default settings
self._resolutions = ['640x480', '800x600', '1024x768', '1280x800', '1440x900']
self._renderbackends = ['OpenGL', 'SDL']
self._lightingmodels = [0, 1, 2]
#Used to stylize the options gui
self._gui_style = "default"
#Initialize the serializer
if serializer:
self._serializer = serializer
else:
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):
#.........这里部分代码省略.........
示例6: Settings
# 需要导入模块: from fife.extensions.serializers.simplexml import SimpleXMLSerializer [as 别名]
# 或者: from fife.extensions.serializers.simplexml.SimpleXMLSerializer import load [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)