Mercurial > fife-parpg
comparison clients/editor/run.py @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | d5658e6c34f5 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 #!/usr/bin/env python | |
2 # coding: utf-8 | |
3 # This is the editor client for FIFE. | |
4 | |
5 import sys, os, re | |
6 | |
7 def _jp(path): | |
8 return os.path.sep.join(path.split('/')) | |
9 | |
10 _paths = ('.', '../../engine/swigwrappers/python', '../../engine/extensions') | |
11 for p in _paths: | |
12 if p not in sys.path: | |
13 sys.path.append(_jp(p)) | |
14 | |
15 import fife | |
16 import fifelog | |
17 import basicapplication | |
18 import pychan | |
19 import pychan.widgets as widgets | |
20 import sys | |
21 | |
22 from listener import EditorListener | |
23 | |
24 from plugins.plugin import Plugin | |
25 from plugins.maploader import MapLoader | |
26 from plugins.maploader import MapSaver | |
27 from plugins.importer import Importer | |
28 from plugins.mapeditor import MapEditor | |
29 from plugins.mapwizard import MapWizard | |
30 from fifedit import Fifedit | |
31 | |
32 # Help display | |
33 class Help(Plugin): | |
34 def __init__(self): | |
35 self._helpWidget = None | |
36 self.menu_items = { 'Help' : self.showHelp } | |
37 | |
38 def showHelp(self): | |
39 if self._helpWidget: | |
40 self._helpWidget.show() | |
41 return | |
42 self._helpWidget = pychan.loadXML('content/gui/help.xml') | |
43 self._helpWidget.mapEvents({ 'closeButton' : self._helpWidget.hide }) | |
44 self._helpWidget.distributeData({ 'helpText' : open("content/infotext.txt").read() }) | |
45 self._helpWidget.show() | |
46 | |
47 class Editor(basicapplication.ApplicationBase): | |
48 def __init__(self, params): | |
49 super(Editor,self).__init__() | |
50 | |
51 # embed Fifedit tools | |
52 self.fifedit = Fifedit(self.engine) | |
53 | |
54 # Create this client's modules | |
55 self.mapedit = MapEditor(self.engine) | |
56 self.maploader = MapLoader(self.engine) | |
57 self.mapsaver = MapSaver(self.engine) | |
58 self.mapwizard = MapWizard(self.engine) | |
59 self.importer = Importer(self.engine) | |
60 | |
61 # Register plugins with Fifedit. | |
62 self.fifedit.registerPlugin(Help()) | |
63 self.fifedit.registerPlugin(self.maploader) | |
64 self.fifedit.registerPlugin(self.mapsaver) | |
65 self.fifedit.registerPlugin(self.mapedit) | |
66 self.fifedit.registerPlugin(self.mapwizard) | |
67 self.fifedit.registerPlugin(self.importer) | |
68 | |
69 self.params = params | |
70 | |
71 def createListener(self): | |
72 # override default event listener | |
73 return EditorListener(self) | |
74 | |
75 def _pump(self): | |
76 if self.maploader.newMap: | |
77 self.mapedit.editMap(self.maploader.newMap.getId()) | |
78 self.importer.addDirs(self.maploader.newMap.importDirs) | |
79 self.maploader.newMap = None | |
80 if self.mapwizard.newMap: | |
81 self.mapedit.editMap(self.mapwizard.map.getId()) | |
82 self.mapwizard.newMap = False | |
83 if self.mapsaver.saveRequested: | |
84 if self.mapedit._map: | |
85 self.mapsaver.saveMap(self.mapedit._map,self.importer.importList) | |
86 else: | |
87 print "Cannot save, map doesn't exist" | |
88 self.mapsaver.saveRequested = False | |
89 if not self.fifedit.active: | |
90 self.quitRequested = True | |
91 if self.params: | |
92 s = os.path.sep | |
93 parts = self.params.split(s) | |
94 self.maploader.loadFile(s.join(parts[0:-1]), parts[-1]) | |
95 self.params = None | |
96 | |
97 if __name__ == '__main__': | |
98 print sys.argv | |
99 params = None | |
100 if len(sys.argv) > 1: | |
101 params = sys.argv[1] | |
102 app = Editor(params) | |
103 app.run() |