Mercurial > fife-parpg
view clients/editor/run.py @ 247:040387b7167f
More documentation.
Refactoring.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 25 Mar 2009 21:41:43 +0000 |
parents | bcc93e17f978 |
children | 51cc05d862f2 |
line wrap: on
line source
#!/usr/bin/env python # coding: utf-8 # This is the editor client for FIFE. import sys, os, re def _jp(path): return os.path.sep.join(path.split('/')) _paths = ('.', '../../engine/swigwrappers/python', '../../engine/extensions') for p in _paths: if p not in sys.path: sys.path.append(_jp(p)) import fife import fifelog import basicapplication import pychan import pychan.widgets as widgets import sys from listener import EditorListener from plugins.plugin import Plugin from plugins.maploader import MapLoader from plugins.maploader import MapSaver from plugins.importer import Importer from plugins.mapeditor import MapEditor from plugins.mapwizard import MapWizard from fifedit import Fifedit # zero-projekt plugins from plugins.objectedit import ObjectEdit from plugins.layertool import LayerTool # Help display class Help(Plugin): def __init__(self): self._helpWidget = None self.menu_items = { 'Help' : self.showHelp } def showHelp(self): if self._helpWidget: self._helpWidget.show() return self._helpWidget = pychan.loadXML('gui/help.xml') self._helpWidget.mapEvents({ 'closeButton' : self._helpWidget.hide }) self._helpWidget.distributeData({ 'helpText' : open("misc/infotext.txt").read() }) self._helpWidget.show() class Editor(basicapplication.ApplicationBase): def __init__(self, params): super(Editor,self).__init__() # embed Fifedit tools self.fifedit = Fifedit(self.engine) # Create this client's modules self.mapedit = MapEditor(self.engine) self.maploader = MapLoader(self.engine) self.mapsaver = MapSaver(self.engine) self.mapwizard = MapWizard(self.engine) self.importer = Importer(self.engine) # zero-projekt plugins self.objectedit = ObjectEdit(self.engine, self.mapedit) self.layertool = LayerTool(self.engine, self.mapedit) # Register plugins with Fifedit. self.fifedit.registerPlugin(Help()) self.fifedit.registerPlugin(self.maploader) self.fifedit.registerPlugin(self.mapsaver) self.fifedit.registerPlugin(self.mapedit) self.fifedit.registerPlugin(self.mapwizard) self.fifedit.registerPlugin(self.importer) # zero-projekt plugins self.fifedit.registerPlugin(self.objectedit) self.fifedit.registerPlugin(self.layertool) self.params = params def createListener(self): # override default event listener return EditorListener(self) def _pump(self): self.mapedit.pump() if self.maploader.newMap: self.mapedit.editMap(self.maploader.newMap.getId()) self.importer.addDirs(self.maploader.newMap.importDirs) self.maploader.newMap = None if self.mapwizard.newMap: self.mapedit.editMap(self.mapwizard.map.getId()) self.mapwizard.newMap = False if self.mapsaver.saveRequested: if self.mapedit._map: self.mapsaver.saveMap(self.mapedit._map,self.importer.importList) else: print "Cannot save, map doesn't exist" self.mapsaver.saveRequested = False if not self.fifedit.active: self.quitRequested = True if self.params: s = os.path.sep parts = self.params.split(s) self.maploader.loadFile(s.join(parts[0:-1]), parts[-1]) self.params = None # zero-projekt plugins if self.mapedit._instances is not None: self.objectedit.input() if __name__ == '__main__': print sys.argv params = None if len(sys.argv) > 1: params = sys.argv[1] app = Editor(params) app.run()