Mercurial > fife-parpg
changeset 505:ee65aa323457
Updated the ApplicationBase settings to use the new and improved fife_setting extension. I was able to remove all the setting related functions from the demos and editor so that the ApplicationBase now takes care of all the FIFE related settings.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 18 May 2010 19:37:31 +0000 |
parents | 0196c83c7270 |
children | 226e26d1d11e |
files | demos/rio_de_hola/run.py demos/shooter/run.py engine/python/fife/extensions/basicapplication.py engine/python/fife/extensions/fife_settings.py tools/editor/scripts/editor.py |
diffstat | 5 files changed, 61 insertions(+), 153 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/rio_de_hola/run.py Tue May 18 16:01:35 2010 +0000 +++ b/demos/rio_de_hola/run.py Tue May 18 19:37:31 2010 +0000 @@ -117,55 +117,12 @@ class IslandDemo(ApplicationBase): def __init__(self): - super(IslandDemo,self).__init__() + super(IslandDemo,self).__init__(TDS) pychan.init(self.engine, debug=TDS.get("FIFE", "PychanDebug")) self.world = world.World(self.engine) self.listener = ApplicationListener(self.engine, self.world) self.world.load(str(TDS.get("rio", "MapFile"))) - def loadSettings(self): - """ - Load the settings from a python file and load them into the engine. - Called in the ApplicationBase constructor. - """ - - self._setting = TDS - - glyphDft = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\\\"" - engineSetting = self.engine.getSettings() - engineSetting.setDefaultFontGlyphs(self._setting.get("FIFE", "FontGlyphs", glyphDft)) - engineSetting.setDefaultFontPath(self._setting.get("FIFE", "Font", "fonts/FreeSans.ttf")) - engineSetting.setDefaultFontSize(self._setting.get("FIFE", "DefaultFontSize", 12)) - engineSetting.setBitsPerPixel(self._setting.get("FIFE", "BitsPerPixel", 0)) - engineSetting.setInitialVolume(self._setting.get("FIFE", "InitialVolume", 5.0)) - engineSetting.setSDLRemoveFakeAlpha(self._setting.get("FIFE", "SDLRemoveFakeAlpha", 1)) - engineSetting.setScreenWidth(self._setting.get("FIFE", "ScreenWidth", 1024)) - engineSetting.setScreenHeight(self._setting.get("FIFE", "ScreenHeight", 768)) - engineSetting.setRenderBackend(self._setting.get("FIFE", "RenderBackend", "OpenGL")) - engineSetting.setFullScreen(self._setting.get("FIFE", "FullScreen", 0)) - - engineSetting.setWindowTitle(self._setting.get("FIFE", "WindowTitle", "No window title set")) - engineSetting.setWindowIcon(self._setting.get("FIFE", "WindowIcon", "")) - engineSetting.setImageChunkingSize(self._setting.get("FIFE", "ImageChunkSize", 256)) - - def initLogging(self): - """ - Initialize the LogManager. - """ - - engineSetting = self.engine.getSettings() - logmodules = self._setting.get("FIFE", "LogModules", "controller") - - #log to both the console and log file - self._log = fifelog.LogManager(self.engine, - self._setting.get("FIFE", "LogToPrompt", "0"), - self._setting.get("FIFE", "LogToFile", "0")) - - self._log.setLevelFilter(fife.LogManager.LEVEL_DEBUG) - - if logmodules: - self._log.setVisibleModules(*logmodules) - def createListener(self): pass # already created in constructor
--- a/demos/shooter/run.py Tue May 18 16:01:35 2010 +0000 +++ b/demos/shooter/run.py Tue May 18 19:37:31 2010 +0000 @@ -67,13 +67,11 @@ class Shooter(ApplicationBase): def __init__(self): - super(Shooter,self).__init__() + super(Shooter,self).__init__(TDS) pychan.init(self.engine, debug=False) #This is requred if you want to use modal dialog boxes pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop) - - self._setting = TDS self._world = world.World(self, self.engine, self._setting) self._listener = ApplicationListener(self.engine, self._world) @@ -84,50 +82,6 @@ cmd.setCommandType(fife.CMD_QUIT_GAME) self.engine.getEventManager().dispatchCommand(cmd) - def loadSettings(self): - """ - Load the settings from a python file and load them into the engine. - Called in the ApplicationBase constructor. I hard coded all the - settings in here to remove the complexity of loading settings from - an XML file which would be out of scope of this demo. - """ - - self._setting = TDS - - glyphDft = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\\\"" - engineSetting = self.engine.getSettings() - engineSetting.setDefaultFontGlyphs(self._setting.get("FIFE", "FontGlyphs", glyphDft)) - engineSetting.setDefaultFontPath(self._setting.get("FIFE", "Font", "fonts/FreeSans.ttf")) - engineSetting.setDefaultFontSize(self._setting.get("FIFE", "DefaultFontSize", 12)) - engineSetting.setBitsPerPixel(self._setting.get("FIFE", "BitsPerPixel", 0)) - engineSetting.setInitialVolume(self._setting.get("FIFE", "InitialVolume", 5.0)) - engineSetting.setSDLRemoveFakeAlpha(self._setting.get("FIFE", "SDLRemoveFakeAlpha", 1)) - engineSetting.setScreenWidth(self._setting.get("FIFE", "ScreenWidth", 1024)) - engineSetting.setScreenHeight(self._setting.get("FIFE", "ScreenHeight", 768)) - engineSetting.setRenderBackend(self._setting.get("FIFE", "RenderBackend", "OpenGL")) - engineSetting.setFullScreen(self._setting.get("FIFE", "FullScreen", 0)) - - engineSetting.setWindowTitle(self._setting.get("FIFE", "WindowTitle", "No window title set")) - engineSetting.setWindowIcon(self._setting.get("FIFE", "WindowIcon", "")) - engineSetting.setImageChunkingSize(self._setting.get("FIFE", "ImageChunkSize", 256)) - - def initLogging(self): - """ - Initialize the LogManager. - """ - - engineSetting = self.engine.getSettings() - logmodules = self._setting.get("FIFE", "LogModules", "controller") - - #log to both the console and log file - self._log = fifelog.LogManager(self.engine, - self._setting.get("FIFE", "LogToPrompt", "0"), - self._setting.get("FIFE", "LogToFile", "0")) - - self._log.setLevelFilter(fife.LogManager.LEVEL_DEBUG) - - if logmodules: - self._log.setVisibleModules(*logmodules) def createListener(self): pass # already created in constructor
--- a/engine/python/fife/extensions/basicapplication.py Tue May 18 16:01:35 2010 +0000 +++ b/engine/python/fife/extensions/basicapplication.py Tue May 18 19:37:31 2010 +0000 @@ -30,6 +30,7 @@ from fife import fife from fife.extensions import fifelog from fife.extensions.serializers.xmlanimation import XMLAnimationLoader +from fife.extensions.fife_settings import Setting class ExitEventListener(fife.IKeyListener): """ @@ -68,7 +69,12 @@ to define runtime behavior of the application. """ - def __init__(self): + def __init__(self, setting=None): + if setting: + self._setting = setting + else: + self._setting = Setting(app_name="", settings_file="./settings.xml", settings_gui_xml="") + self.engine = fife.Engine() self.loadSettings() @@ -88,38 +94,39 @@ Load the settings from a python file and load them into the engine. Called in the ApplicationBase constructor. """ - import settings - self.settings = settings + glyphDft = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\\\"" engineSetting = self.engine.getSettings() - engineSetting.setDefaultFontGlyphs(settings.FontGlyphs) - engineSetting.setDefaultFontPath(settings.Font) - engineSetting.setDefaultFontSize(12) - engineSetting.setBitsPerPixel(settings.BitsPerPixel) - engineSetting.setFullScreen(settings.FullScreen) - engineSetting.setInitialVolume(settings.InitialVolume) - engineSetting.setRenderBackend(settings.RenderBackend) - engineSetting.setSDLRemoveFakeAlpha(settings.SDLRemoveFakeAlpha) - engineSetting.setScreenWidth(settings.ScreenWidth) - engineSetting.setScreenHeight(settings.ScreenHeight) + engineSetting.setDefaultFontGlyphs(self._setting.get("FIFE", "FontGlyphs", glyphDft)) + engineSetting.setDefaultFontPath(self._setting.get("FIFE", "Font", "fonts/FreeSans.ttf")) + engineSetting.setDefaultFontSize(self._setting.get("FIFE", "DefaultFontSize", 12)) + engineSetting.setBitsPerPixel(self._setting.get("FIFE", "BitsPerPixel", 0)) + engineSetting.setInitialVolume(self._setting.get("FIFE", "InitialVolume", 5.0)) + engineSetting.setSDLRemoveFakeAlpha(self._setting.get("FIFE", "SDLRemoveFakeAlpha", 1)) + engineSetting.setScreenWidth(self._setting.get("FIFE", "ScreenWidth", 1024)) + engineSetting.setScreenHeight(self._setting.get("FIFE", "ScreenHeight", 768)) + engineSetting.setRenderBackend(self._setting.get("FIFE", "RenderBackend", "OpenGL")) + engineSetting.setFullScreen(self._setting.get("FIFE", "FullScreen", 0)) try: - engineSetting.setColorKeyEnabled(settings.ColorKeyEnabled) + engineSetting.setColorKeyEnabled(self._setting.get("FIFE", "ColorKeyEnabled", False)) except: pass try: - engineSetting.setColorKey(*settings.ColorKey) + key = self._setting.get("FIFE", "ColorKey", "255,255,255").split(',') + engineSetting.setColorKey(int(key[0]), int(key[1]), int(key[2])) except: pass try: - engineSetting.setWindowTitle(settings.WindowTitle) - engineSetting.setWindowIcon(settings.WindowIcon) + engineSetting.setWindowTitle(self._setting.get("FIFE", "WindowTitle", "No window title set")) + engineSetting.setWindowIcon(self._setting.get("FIFE", "WindowIcon", "")) except: pass + try: - engineSetting.setImageChunkingSize(settings.ImageChunkSize) + engineSetting.setImageChunkingSize(self._setting.get("FIFE", "ImageChunkSize", 256)) except: pass @@ -127,10 +134,20 @@ """ Initialize the LogManager. """ - self.log = fifelog.LogManager(self.engine, self.settings.LogToPrompt, self.settings.LogToFile) - if self.settings.LogModules: - self.log.setVisibleModules(*self.settings.LogModules) + + engineSetting = self.engine.getSettings() + logmodules = self._setting.get("FIFE", "LogModules", ["controller"]) + #log to both the console and log file + self._log = fifelog.LogManager(self.engine, + self._setting.get("FIFE", "LogToPrompt", "0"), + self._setting.get("FIFE", "LogToFile", "0")) + + self._log.setLevelFilter(self._setting.get("FIFE", "LogLevelFilter", fife.LogManager.LEVEL_DEBUG)) + + if logmodules: + self._log.setVisibleModules(*logmodules) + def createListener(self): """ This creates a default event listener, which will just close the program
--- a/engine/python/fife/extensions/fife_settings.py Tue May 18 16:01:35 2010 +0000 +++ b/engine/python/fife/extensions/fife_settings.py Tue May 18 19:37:31 2010 +0000 @@ -78,6 +78,16 @@ </Window> """ +EMPTY_SETTINGS="""\ +<?xml version='1.0' encoding='UTF-8'?> +<Settings> + <Module name="FIFE"> + + </Module> + +</Settings> +""" + class Setting(object): """ This class manages loading and saving of game settings. @@ -98,7 +108,7 @@ @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. + in the working directory. It will NOT look in the users home directory. @type settings_file: C{string} @param settings_gui_xml: If you specify this parameter you can customize the look of the settings dialog box. @@ -123,7 +133,12 @@ if not os.path.exists(os.path.join(self._appdata, self._settings_file)): - shutil.copyfile('settings-dist.xml', os.path.join(self._appdata, self._settings_file)) + if os.path.exists('settings-dist.xml'): + shutil.copyfile('settings-dist.xml', os.path.join(self._appdata, self._settings_file)) + else: + #no settings file found + tree = ET.parse(StringIO(EMPTY_SETTINGS)) + tree.write(os.path.join(self._appdata, self._settings_file), 'UTF-8') self._tree = ET.parse(os.path.join(self._appdata, self._settings_file)) self._root_element = self._tree.getroot()
--- a/tools/editor/scripts/editor.py Tue May 18 16:01:35 2010 +0000 +++ b/tools/editor/scripts/editor.py Tue May 18 19:37:31 2010 +0000 @@ -59,6 +59,8 @@ from mapview import MapView from fife.extensions.fife_settings import Setting +TDS = Setting(app_name="editor") + def getEditor(): """ Returns the Global editor instance """ if Editor.editor is None: @@ -95,51 +97,14 @@ self._change_map = -1 - self._settings = None + self._settings = TDS self._help_dialog = None - ApplicationBase.__init__(self, *args, **kwargs) + ApplicationBase.__init__(self, TDS, *args, **kwargs) MainWindow.__init__(self, *args, **kwargs) pychan.init(self.engine, debug=False) - - def loadSettings(self): - """ - Load the settings from a python file and load them into the engine. - Called in the ApplicationBase constructor. - """ - self._settings = Setting(app_name="editor") - TDS = self._settings - - glyphDft = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\\\"" - engineSetting = self.engine.getSettings() - engineSetting.setDefaultFontGlyphs(TDS.get("FIFE", "FontGlyphs", glyphDft)) - engineSetting.setDefaultFontPath(TDS.get("FIFE", "Font", "fonts/FreeSans.ttf")) - engineSetting.setDefaultFontSize(12) - engineSetting.setBitsPerPixel(TDS.get("FIFE", "BitsPerPixel", 0)) - engineSetting.setInitialVolume(TDS.get("FIFE", "InitialVolume", 5.0)) - engineSetting.setSDLRemoveFakeAlpha(TDS.get("FIFE", "SDLRemoveFakeAlpha", 1)) - engineSetting.setScreenWidth(TDS.get("FIFE", "ScreenWidth", 1024)) - engineSetting.setScreenHeight(TDS.get("FIFE", "ScreenHeight", 768)) - engineSetting.setRenderBackend(TDS.get("FIFE", "RenderBackend", "OpenGL")) - engineSetting.setFullScreen(TDS.get("FIFE", "FullScreen", 0)) - - engineSetting.setWindowTitle(TDS.get("FIFE", "WindowTitle", "No window title set")) - engineSetting.setWindowIcon(TDS.get("FIFE", "WindowIcon", "")) - engineSetting.setImageChunkingSize(TDS.get("FIFE", "ImageChunkSize", 256)) - - def initLogging(self): - """ - Initialize the LogManager. - """ - from fife.extensions import fifelog - - logModules = self._settings.get("FIFE", "LogModules") - self.log = fifelog.LogManager(self.engine, self._settings.get("FIFE", "LogToPrompt"), self._settings.get("FIFE", "LogToFile")) - if logModules: - self.log.setVisibleModules(*logModules) - def _initTools(self): """ Initializes tools """ self._pluginmanager = plugin.PluginManager(self.getSettings())