Package fife :: Package extensions :: Module fife_settings :: Class Setting
[hide private]
[frames] | no frames]

Class Setting

source code

builtins.object --+
                  |
                 Setting

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)
Instance Methods [hide private]
 
__init__(self, app_name="", settings_file="", default_settings_file="settings-dist.xml", copy_dist=True, serializer=None)
Initializes the Setting object.
source code
 
setAllSettings(self, module, settings, validSetting=True) source code
 
setOneSetting(self, module, name, value, validSetting=True) source code
 
getAllSettings(self, module, validSetting=True) source code
 
getOneSetting(self, module, name, validSetting=True) source code
 
setValidResolutions(self, options) source code
 
initSerializer(self) source code
 
_initDefaultSettingEntries(self)
Initializes the default fife setting entries.
source code
 
createAndAddEntry(self, module, name, applyfunction=None, initialdata=None, requiresrestart=False)
"
source code
 
addEntry(self, entry)
Adds a new SettingEntry to the Settting
source code
 
saveSettings(self, filename="")
Writes the settings to the settings file
source code
 
getSettingsFromFile(self, module, logger=None) source code
 
get(self, module, name, defaultValue=None)
Gets the value of a specified setting
source code
 
set(self, module, name, value, extra_attrs={})
Sets a setting to specified value.
source code
 
remove(self, module, name)
Removes a variable
source code
 
setAvailableScreenResolutions(self, reslist)
A list of valid default screen resolutions.
source code
 
setDefaults(self)
Overwrites the setting file with the default settings file.
source code
 
_getEntries(self) source code
 
_setEntries(self, entries) source code
 
_getSerializer(self) source code
 
serializer(self) source code
Class Variables [hide private]
  entries = property(_getEntries, _setEntries)
Method Details [hide private]

__init__(self, app_name="", settings_file="", default_settings_file="settings-dist.xml", copy_dist=True, serializer=None)
(Constructor)

source code 

Initializes the Setting object.

Parameters:
  • app_name (string) - 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
  • settings_file (string) - 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.
  • default_settings_file (string) - 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!
  • copy_dist - Copies the default settings file to the settings_file location. If this is False it will create a new empty setting file.
  • serializer (SimpleSerializer) - Overrides the default XML serializer

_initDefaultSettingEntries(self)

source code 

Initializes the default fife setting entries. Not to be called from outside this class.

createAndAddEntry(self, module, name, applyfunction=None, initialdata=None, requiresrestart=False)

source code 

"

Parameters:
  • module (String) - The Setting module this Entry belongs to
  • name (String) - The Setting's name
  • applyfunction (function) - function that makes the changes when the Setting is saved
  • initialdata (String or Boolean) - If the widget supports the setInitialData() function this can be used to set the initial data
  • requiresrestart (Boolean) - Whether or not the changing of this setting requires a restart

addEntry(self, entry)

source code 

Adds a new SettingEntry to the Settting

Parameters:
  • entry (SettingEntry) - A new SettingEntry that is to be added

saveSettings(self, filename="")

source code 

Writes the settings to the settings file

Parameters:
  • filename (string) - Specifies the file to save the settings to. If it is not specified the original settings file is used.

get(self, module, name, defaultValue=None)

source code 

Gets the value of a specified setting

Parameters:
  • module - Name of the module to get the setting from
  • name - Setting name
  • defaultValue (str or unicode or int or float or bool or list or dict) - Specifies the default value to return if the setting is not found

set(self, module, name, value, extra_attrs={})

source code 

Sets a setting to specified value.

Parameters:
  • module - Module where the setting should be set
  • name - Name of setting
  • value (str or unicode or int or float or bool or list or dict) - Value to assign to setting
  • extra_attrs (dict) - Extra attributes to be stored in the XML-file

remove(self, module, name)

source code 

Removes a variable

Parameters:
  • module - Module where the variable should be set
  • name - Name of the variable

setAvailableScreenResolutions(self, reslist)

source code 

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"])