Mercurial > fife-parpg
comparison clients/editor/scripts/editor.py @ 367:598547404022
* Initial support for closing maps:
* Lots of cleanup functions has been added
* TODO: Cameras are only removed when all maps are closed
* TODO: Screen leaves traces when the last map is closed
* Replaced pre/postMapRemove events with pre/postMapClosed
* Fixed a bug in the Toolbar where it didn't properly handle removal of actions from an actiongroup
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 29 Oct 2009 22:11:48 +0000 |
parents | f55ddf7fdad5 |
children | 20fa29f376c7 |
comparison
equal
deleted
inserted
replaced
366:dcf6f6091868 | 367:598547404022 |
---|---|
147 | 147 |
148 self._toolbox = ToolBar(title=u"", orientation=1) | 148 self._toolbox = ToolBar(title=u"", orientation=1) |
149 self._toolbox.position_technique = "explicit" | 149 self._toolbox.position_technique = "explicit" |
150 self._toolbox.position = (150, 150) | 150 self._toolbox.position = (150, 150) |
151 | 151 |
152 self._mapbar = ToolBar(panel_size=20) | 152 self._mapbar = ToolBar(name="MapBar", panel_size=20) |
153 self._mapbar.setDocked(True) | 153 self._mapbar.setDocked(True) |
154 | 154 |
155 self._maparea = pychan.widgets.VBox() | 155 self._maparea = pychan.widgets.VBox() |
156 self._maparea.opaque = False | 156 self._maparea.opaque = False |
157 self._maparea.is_focusable = True | 157 self._maparea.is_focusable = True |
215 action.activated.connect(self._actionActivated, sender=test_action1) | 215 action.activated.connect(self._actionActivated, sender=test_action1) |
216 self._view_menu.addAction(test_action1) | 216 self._view_menu.addAction(test_action1) |
217 | 217 |
218 self._mapgroup = ActionGroup(exclusive=True, name="Mapgroup") | 218 self._mapgroup = ActionGroup(exclusive=True, name="Mapgroup") |
219 self._mapbar.addAction(self._mapgroup) | 219 self._mapbar.addAction(self._mapgroup) |
220 self._mapbar.addAction(ActionGroup(exclusive=True, name="Mapgroup2")) | |
221 self._window_menu.addAction(self._mapgroup) | 220 self._window_menu.addAction(self._mapgroup) |
222 | 221 |
223 help_action = Action(u"Help", "gui/icons/help.png") | 222 help_action = Action(u"Help", "gui/icons/help.png") |
224 help_action.helptext = u"Displays a window with some simple instructions" | 223 help_action.helptext = u"Displays a window with some simple instructions" |
225 action.activated.connect(self._showHelpDialog, sender=help_action) | 224 action.activated.connect(self._showHelpDialog, sender=help_action) |
343 action.activated.connect(cbwa(self.showMapView, mapview), sender=map_action, weak=False) | 342 action.activated.connect(cbwa(self.showMapView, mapview), sender=map_action, weak=False) |
344 self._mapgroup.addAction(map_action) | 343 self._mapgroup.addAction(map_action) |
345 | 344 |
346 self.showMapView(mapview) | 345 self.showMapView(mapview) |
347 | 346 |
347 events.preMapClosed.connect(self._mapRemoved) | |
348 events.mapAdded.send(sender=self, map=map) | 348 events.mapAdded.send(sender=self, map=map) |
349 | 349 |
350 return mapview | 350 return mapview |
351 | 351 |
352 def _mapRemoved(self, mapview): | |
353 events.preMapClosed.disconnect(self._mapRemoved) | |
354 | |
355 index = self._mapviewlist.index(mapview)-1 | |
356 self._mapviewlist.remove(mapview) | |
357 | |
358 # Remove tab | |
359 for map_action in self._mapgroup.getActions(): | |
360 if map_action.text == unicode(mapview.getMap().getId()): | |
361 self._mapgroup.removeAction(map_action) | |
362 break | |
363 | |
364 # Change mapview | |
365 if index >= 0: | |
366 self.showMapView(self._mapviewlist[index]) | |
367 else: | |
368 self._mapview = None | |
369 self.getEngine().getView().clearCameras() | |
370 | |
352 def openFile(self, path): | 371 def openFile(self, path): |
353 """ Opens a file """ | 372 """ Opens a file """ |
354 try: | 373 try: |
355 map = loaders.loadMapFile(path, self.engine) | 374 map = loaders.loadMapFile(path, self.engine) |
356 return self.newMapView(map) | 375 return self.newMapView(map) |
359 errormsg = u"Opening map failed:\n" | 378 errormsg = u"Opening map failed:\n" |
360 errormsg += u"File: "+unicode(path, sys.getfilesystemencoding())+u"\n" | 379 errormsg += u"File: "+unicode(path, sys.getfilesystemencoding())+u"\n" |
361 errormsg += u"Error: "+unicode(sys.exc_info()[1]) | 380 errormsg += u"Error: "+unicode(sys.exc_info()[1]) |
362 ErrorDialog(errormsg) | 381 ErrorDialog(errormsg) |
363 return None | 382 return None |
364 | |
365 | 383 |
366 def saveAll(self): | 384 def saveAll(self): |
367 """ Saves all open maps """ | 385 """ Saves all open maps """ |
368 tmpview = self._mapview | 386 tmpview = self._mapview |
369 for mapview in self._mapviewlist: | 387 for mapview in self._mapviewlist: |