本文整理匯總了Python中fife.extensions.serializers.simplexml.SimpleXMLSerializer類的典型用法代碼示例。如果您正苦於以下問題:Python SimpleXMLSerializer類的具體用法?Python SimpleXMLSerializer怎麽用?Python SimpleXMLSerializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SimpleXMLSerializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
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()
示例2: new_project
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
示例3: __init__
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()
示例4: deserialize
def deserialize(self, valueDict):
questFile = "maps/quests.xml"
self._questSettings = SimpleXMLSerializer(questFile)
for identifier in self._questSettings.get("QuestGivers", "list", []):
for quest in self._questSettings.get(identifier, "questList", []):
questDict = self._questSettings.get(identifier, quest, [])
if questDict["type"] == 'RETURN_ITEM':
questObj = ReturnItemQuest(identifier, quest, questDict["name"], questDict["desc"])
for ritem in self._questSettings.get(quest + "_items", "itemlist", []):
itemDict = self._questSettings.get(quest + "_items", ritem, [])
if itemDict["name"] == "GOLD_COINS":
questObj.addRequiredGold(itemDict["value"])
else:
questObj.addRequiredItem(ritem)
else:
questObj = Quest(identifier, quest, questDict["name"], questDict["desc"])
if questDict.has_key("quest_incomplete_dialog"):
questObj._incompleteDialog = questDict["quest_incomplete_dialog"]
if questDict.has_key("quest_complete_dialog"):
questObj._completeDialog = questDict["quest_complete_dialog"]
self._gameplay.questManager.addQuest(questObj)
示例5: deserialize
def deserialize(self, valuedict=None):
questfile = self._gamecontroller.settings.get("RPG", "QuestFile", "maps/quests.xml")
self._questsettings = SimpleXMLSerializer(questfile)
for identifier in self._questsettings.get("QuestGivers", "list", []):
for quest in self._questsettings.get(identifier, "questlist", []):
questdict = self._questsettings.get(identifier, quest, {})
if questdict['type'] == "RETURN_ITEM":
questobj = ReturnItemQuest(identifier, quest, questdict['name'], questdict['desc'])
for ritem in self._questsettings.get(quest+"_items", "itemlist", []):
itemdict = self._questsettings.get(quest+"_items", ritem, {})
if itemdict["name"] == "GOLD_COINS":
questobj.addRequiredGold(int(itemdict['value']))
else:
questobj.addRequiredItem(ritem)
else:
questobj = Quest(identifier, quest, questdict['name'], questdict['desc'])
if questdict.has_key("quest_incomplete_dialog"):
questobj._incomplete_dialog = questdict['quest_incomplete_dialog']
if questdict.has_key("quest_complete_dialog"):
questobj._complete_dialog = questdict['quest_complete_dialog']
self._gamecontroller.questmanager.addQuest(questobj)
示例6: createPlayerObject
def createPlayerObject(self):
"""
@todo: once we have all art assets this should be able to load one of 3 player models
"""
modeldict = self._modelsettings.get("models", "Player", {})
print('loading: %s' % modeldict["file"])
self._loader.loadImportFile(modeldict["file"])
self._player = Player(self._gamecontroller, self.actorlayer, "warrior")
playerfilename = os.path.join("saves", "player_save.xml")
if os.path.isfile(playerfilename):
player_settings = SimpleXMLSerializer(playerfilename)
pvals = player_settings.get("player", "player", {})
self._player.deserialize(pvals)
示例7: load_project
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
示例8: _loadNPC
def _loadNPC(self, name):
self._npcFile = SimpleXMLSerializer(filename="npcs/" + name + ".xml")
actionstr = self._npcFile.get("npc", "actions", None)
actions = self._npcFile._deserializeDict(actionstr)
for action, bool in actions.iteritems():
if bool == "True":
self._availableActions[action] = True
else:
self._availableActions[action] = False
self._actionchance = self._npcFile.get("npc", "actionchance", 0)
self._description = self._npcFile.get("npc", "description", "I can see a mysterious figure,\n but I can't quite make them out.")
self._autowalk = self._npcFile.get("npc", "autowalk", True)
self._hasdialogue = self._npcFile.get("npc", "hasdialogue", False)
self._autowalk = self._npcFile.get("npc", "autowalk", True)
self._loadDialogue()
self._idle()
示例9: __init__
def __init__(self, objectmanager, model, file):
fife.InstanceActionListener.__init__(self)
self._manager = objectmanager
self._model = model
self._objectFile = SimpleXMLSerializer(file)
self._agentName = self._objectFile.get("object", "agentname", "dummy")
self._layer = self._manager._world._map.getLayer(self._objectFile.get("object", "layer", "player"))
self._agent = self._layer.getInstance(self._agentName)
self._agent.addActionListener(self)
self._status = self._objectFile.get("object", "status", 'INACTIVE')
self._actions = { 'use' : self.use,
'destroy' : self.destroy,
'turnon' : self.activate,
'turnoff' : self.deactivate,
'explode' : self.explode,
'describe': self.describe,
'glitch' : self.glitch }
self._availableactions = { 'use' : False,
'destroy' : False,
'turnon' : False,
'turnoff' : False,
'explode' : False,
'describe' : True,
'glitch' : False }
actionstr = self._objectFile.get("object", "actions", None)
actions = self._objectFile._deserializeDict(actionstr)
for action, bool in actions.iteritems():
if bool in ("True"):
self._availableactions[action] = True
else:
self._availableactions[action] = False
self._description = self._objectFile.get("object", "description", "I can see something, but\n I can't tell what it is")
self._talk = self._objectFile.get("object", "talk", False)
self._message = self._objectFile._deserializeList(self._objectFile.get("object", "messages", ""))
self._usesound = self._objectFile.get("object", "sound", False)
if self._usesound:
self._manager._world._sounds._loadclip(self._agentName, self._objectFile.get("object", "soundfile", ""), False, False)
self._sound = self._manager._world._sounds._emitters[self._agentName]
self._loadObject()
self.onInstanceActionFinished(self._agent, "")
示例10: convert_fife_project
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
示例11: __init__
#.........這裏部分代碼省略.........
@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 = {}
# the logger needed to write in log file. It will be initialized in this file when self.getSettings()
# method is called by logger
self._logger = None
#default settings
self._resolutions = self._validSetting['FIFE']['ScreenResolution']
self._renderbackends = self._validSetting['FIFE']['RenderBackend']
self._lightingmodels = self._validSetting['FIFE']['Lighting']
#Used to stylize the options gui
self._gui_style = "default"
#Initialize the serializer
if serializer:
self._serializer = serializer
else:
self._serializer = SimpleXMLSerializer()
self.initSerializer()
# Get all modules and initialize reading of them from xml file as false
self._allModules = self._serializer.getModuleNameList()
# print("All Module Names:",self._allModules)
for module in self._allModules:
self._readSettingsCompleted[module] = False
self._initDefaultSettingEntries()
示例12: Setting
#.........這裏部分代碼省略.........
'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 = {}
# the logger needed to write in log file. It will be initialized in this file when self.getSettings()
# method is called by logger
self._logger = None
#default settings
self._resolutions = self._validSetting['FIFE']['ScreenResolution']
self._renderbackends = self._validSetting['FIFE']['RenderBackend']
self._lightingmodels = self._validSetting['FIFE']['Lighting']
#Used to stylize the options gui
self._gui_style = "default"
#Initialize the serializer
if serializer:
self._serializer = serializer
else:
self._serializer = SimpleXMLSerializer()
self.initSerializer()
# Get all modules and initialize reading of them from xml file as false
self._allModules = self._serializer.getModuleNameList()
# print("All Module Names:",self._allModules)
for module in self._allModules:
self._readSettingsCompleted[module] = False
self._initDefaultSettingEntries()
#self.setOneSetting('FIFE','Font','fonts/FreeSans.ttf',False)
#print self.getSettingsFromFile('unknownhorizons')
# set all Settings in either validSetting or defaultSetting
def setAllSettings(self,module,settings,validSetting = True):
if validSettings:
self._validSetting[module] = settings
else:
self._defaultSetting[module] = settings
# set an entry in the validSetting or defaultSetting dictionary
def setOneSetting(self,module,name,value,validSetting = True):
if validSetting:
self._validSetting[module][name] = value
else:
self._defaultSetting[module][name] = value
# get all the Settings(either validSetting or defaultSetting)
def getAllSettings(self,module,validSetting = True):
if validSetting:
示例13: InteractiveObject
class InteractiveObject(fife.InstanceActionListener):
def __init__(self, objectmanager, model, file):
fife.InstanceActionListener.__init__(self)
self._manager = objectmanager
self._model = model
self._objectFile = SimpleXMLSerializer(file)
self._agentName = self._objectFile.get("object", "agentname", "dummy")
self._layer = self._manager._world._map.getLayer(self._objectFile.get("object", "layer", "player"))
self._agent = self._layer.getInstance(self._agentName)
self._agent.addActionListener(self)
self._status = self._objectFile.get("object", "status", 'INACTIVE')
self._actions = { 'use' : self.use,
'destroy' : self.destroy,
'turnon' : self.activate,
'turnoff' : self.deactivate,
'explode' : self.explode,
'describe': self.describe,
'glitch' : self.glitch }
self._availableactions = { 'use' : False,
'destroy' : False,
'turnon' : False,
'turnoff' : False,
'explode' : False,
'describe' : True,
'glitch' : False }
actionstr = self._objectFile.get("object", "actions", None)
actions = self._objectFile._deserializeDict(actionstr)
for action, bool in actions.iteritems():
if bool in ("True"):
self._availableactions[action] = True
else:
self._availableactions[action] = False
self._description = self._objectFile.get("object", "description", "I can see something, but\n I can't tell what it is")
self._talk = self._objectFile.get("object", "talk", False)
self._message = self._objectFile._deserializeList(self._objectFile.get("object", "messages", ""))
self._usesound = self._objectFile.get("object", "sound", False)
if self._usesound:
self._manager._world._sounds._loadclip(self._agentName, self._objectFile.get("object", "soundfile", ""), False, False)
self._sound = self._manager._world._sounds._emitters[self._agentName]
self._loadObject()
self.onInstanceActionFinished(self._agent, "")
def onInstanceActionFinished(self, instance, action):
if self._status == 'ACTIVE':
self._agent.act('on', self._agent.getFacingLocation())
elif self._status == 'INACTIVE':
self._agent.act('off', self._agent.getFacingLocation())
elif self._status == 'DESTROYED':
self._agent.act('dead', self._agent.getFacingLocation())
elif self._status == 'GLITCHED':
self._agent.act('glitch', self._agent.getFacingLocation())
def use(self):
if self._status == 'ACTIVE':
self._agent.act('use', self._agent.getFacingLocation())
self._manager._world._player._agent.setFacingLocation(self._agent.getLocation())
if self._noactioncallbacks == 0:
self._action()
elif self._noactioncallbacks == 1:
self._action(self._actioncallbacks[0])
elif self._noactioncallbacks == 2:
self._action(self._actioncallbacks[0], self._actioncallbacks[1])
elif self._noactioncallbacks == 3:
self._action(self._actioncallbacks[0], self._actioncallbacks[1], self._actioncallbacks[2])
elif self._noactioncallbacks == 4:
self._action(self._actioncallbacks[0], self._actioncallbacks[1], self._actioncallbacks[2], self._actioncallbacks[3])
elif self._noactioncallbacks == 5:
self._action(self._actioncallbacks[0], self._actioncallbacks[1], self._actioncallbacks[2], self._actioncallbacks[3], self._actioncallbacks[4])
if self._talk:
rand = random.randint(0, len(self._message) - 1)
self._manager._world._player._agent.say(self._message[rand], 3500)
if self._usesound:
self._sound.play()
def destroy(self):
self._agent.act('die', self._agent.getFacingLoaction)
self._status = 'DESTROYED'
def activate(self):
self._agent.act('turnon', self._agent.getFacingLoaction)
self._status = 'ACTIVE'
def deactivate(self):
self._agent.act('turnoff', self._agent.getFacingLoaction)
self._status = 'INACTIVE'
def explode(self):
self._agent.act('explode', self._agent.getFacingLoaction)
self._status = 'DESTROYED'
def describe(self):
self._manager._world._player._agent.say(self._description, 5000)
def glitch(self):
self._agent.act('glitch', self._agent.getFacingLoaction)
self._status = 'GLITCHED'
def noAction(self):
#.........這裏部分代碼省略.........
示例14: __init__
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()
示例15: Setting
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):
#.........這裏部分代碼省略.........