annotate clients/editor/scripts/gui/filemanager.py @ 337:f9aca52c7c45

VFS: * Emit warning for upper case filenames. Fixes #122.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 24 Aug 2009 16:06:30 +0000
parents 54de5aebf732
children 8e71629c4c43
rev   line source
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
1 import os, math, fife, pychan, filebrowser, traceback, sys
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 import loaders, savers
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 import action
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 import scripts.editor
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 import pychan.widgets as widgets
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
6 from pychan.tools import callbackWithArguments as cbwa
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
7 from scripts.gui.error import ErrorDialog
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 from action import Action, ActionGroup
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 from input import InputDialog
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 from selection import SelectionDialog, ClickSelectionDialog
325
54de5aebf732 * ObjectSelector will now select and scroll to selected object automatically
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 282
diff changeset
11 from scripts.events import events
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 class FileManager(object):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 def __init__(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 self.editor = scripts.editor.getEditor()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 self.engine = self.editor.getEngine()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 self._map = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 self._layer = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 self._mapdlg = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 self._layerdlg = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 self._cameradlg = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 self._filebrowser = None
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
24 self._importbrowser = None
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 self._savebrowser = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 newAction = Action(u"New map", "gui/icons/new_map.png")
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 loadAction = Action(u"Open", "gui/icons/load_map.png")
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 saveAction = Action(u"Save", "gui/icons/save_map.png")
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 saveAsAction = Action(u"Save as", "gui/icons/save_mapas.png")
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 saveAllAction = Action(u"Save all", "gui/icons/save_allmaps.png")
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
32 importFileAction = Action(u"Import file", "gui/icons/import_file.png")
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
33 importDirAction = Action(u"Import directory", "gui/icons/import_dir.png")
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 newAction.helptext = u"Create new map"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 loadAction.helptext = u"Open existing map"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 saveAction.helptext = u"Save map"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 saveAsAction.helptext = u"Save map as"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 saveAllAction.helptext = u"Save all opened maps"
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
40 importFileAction.helptext = u"Imports an object file"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
41 importDirAction.helptext = u"Recursively imports all objects from a directory"
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 action.activated.connect(self.showMapWizard, sender=newAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 action.activated.connect(self.showLoadDialog, sender=loadAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 action.activated.connect(self.save, sender=saveAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 action.activated.connect(self.saveAs, sender=saveAsAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 action.activated.connect(self.editor.saveAll, sender=saveAllAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
49 self._importFileCallback = cbwa(self.showImportDialog, self.importFile, False)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
50 self._importDirCallback = cbwa(self.showImportDialog, self.importDir, True)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
51 action.activated.connect(self._importFileCallback, sender=importFileAction)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
52 action.activated.connect(self._importDirCallback, sender=importDirAction)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
53
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 eventlistener = self.editor.getEventListener()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 eventlistener.getKeySequenceSignal(fife.Key.N, ["ctrl"]).connect(self.showMapWizard)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 eventlistener.getKeySequenceSignal(fife.Key.O, ["ctrl"]).connect(self.showLoadDialog)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 eventlistener.getKeySequenceSignal(fife.Key.S, ["ctrl"]).connect(self.save)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 eventlistener.getKeySequenceSignal(fife.Key.S, ["ctrl", "shift"]).connect(self.editor.saveAll)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 fileGroup = ActionGroup()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 fileGroup.addAction(newAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 fileGroup.addAction(loadAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 fileGroup.addAction(saveAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 fileGroup.addAction(saveAsAction)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 fileGroup.addAction(saveAllAction)
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
66 fileGroup.addSeparator()
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
67 fileGroup.addAction(importFileAction)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
68 fileGroup.addAction(importDirAction)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 self.editor.getToolBar().insertAction(fileGroup, 0)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 self.editor.getToolBar().insertSeparator(None, 1)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 self.editor._fileMenu.insertAction(fileGroup, 0)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 self.editor._fileMenu.insertSeparator(None, 1)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 def showLoadDialog(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 if self._filebrowser is None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 self._filebrowser = filebrowser.FileBrowser(self.engine, self.loadFile, extensions = loaders.fileExtensions)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 self._filebrowser.showBrowser()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 def showSaveDialog(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 if self._savebrowser is None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 self._savebrowser = filebrowser.FileBrowser(self.engine, self.saveFile, savefile=True, extensions = loaders.fileExtensions)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 self._savebrowser.showBrowser()
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
84
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
85 def showImportDialog(self, callback, selectdir):
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
86 if self._importbrowser is None:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
87 self._importbrowser = filebrowser.FileBrowser(self.engine, callback, extensions = loaders.fileExtensions)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
88 self._importbrowser.fileSelected = callback
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
89 self._importbrowser.selectdir = selectdir
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
90 self._importbrowser.showBrowser()
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 def saveFile(self, path, filename):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 mapview = self.editor.getActiveMapView()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 if mapview is None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 print "No map is open"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 fname = '/'.join([path, filename])
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 mapview.saveAs(fname)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 def saveAs(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 mapview = self.editor.getActiveMapView()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 if mapview is None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 print "No map is open"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 self.showSaveDialog(self)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 def loadFile(self, path, filename):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 self.editor.openFile('/'.join([path, filename]))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 def showMapWizard(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 if self._cameradlg:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 self._cameradlg._widget.show()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 elif self._layerdlg:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 self._layerdlg._widget.show()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 elif self._mapdlg:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 self._mapdlg._widget.show()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 else:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 self._newMap()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 def _newMap(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 self._mapdlg = InputDialog(u'Enter a map identifier:', self._newLayer, self._clean)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 def _newLayer(self, mapId):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 self._map = self.engine.getModel().createMap(str(mapId))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 self._layerdlg = InputDialog(u'Enter a layer identifier for a default layer:', self._newCamera, self._clean)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 def _newCamera(self, layerId):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 grid = fife.SquareGrid()
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
130 self._layer = self._map.createLayer(str(layerId), grid)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 grid.thisown = 0
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
132
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 self._cameradlg = CameraEditor(self.engine, self._addMap, self._clean, self._map, self._layer)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 def _addMap(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 self.editor.newMapView(self._map)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 self._clean()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 def _clean(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 self._mapdlg = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 self._layerdlg = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 self._cameradlg = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 self._map = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 self._layer = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 def save(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 curname = None
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 mapview = self.editor.getActiveMapView()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 if mapview is None:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 print "No map is open"
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 try:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 curname = mapview.getMap().getResourceLocation().getFilename()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 except RuntimeError:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 self.showSaveDialog()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 mapview.save()
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
160
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
161 def importFile(self, path, filename):
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
162 file = os.path.normpath(os.path.join(path, filename))
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
163 # FIXME: This is necassary for the files to be loaded properly.
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
164 # The loader should be fixed to support native (windows)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
165 # path separators.
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
166 file = file.replace('\\', '/')
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
167
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
168 try:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
169 if os.path.isfile(file):
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
170 loaders.loadImportFile(file, self.engine)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
171 else:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
172 raise file+ " is not a file!"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
173 except:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
174 traceback.print_exc(sys.exc_info()[1])
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
175 errormsg = u"Importing file failed:\n"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
176 errormsg += u"File: "+unicode(file)+u"\n"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
177 errormsg += u"Error: "+unicode(sys.exc_info()[1])
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
178 ErrorDialog(errormsg)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
179 return None
325
54de5aebf732 * ObjectSelector will now select and scroll to selected object automatically
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 282
diff changeset
180
54de5aebf732 * ObjectSelector will now select and scroll to selected object automatically
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 282
diff changeset
181 events.onObjectsImported.send(sender=self)
282
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
182
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
183 def importDir(self, path, filename=""):
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
184 if os.path.isdir(os.path.join(path, filename)):
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
185 path = os.path.join(path, filename)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
186 path = os.path.normpath(path)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
187
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
188 # FIXME: This is necassary for the files to be loaded properly.
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
189 # The loader should be fixed to support native (windows)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
190 # path separators.
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
191 path = path.replace('\\', '/')
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
192
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
193 try:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
194 if os.path.isdir(path):
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
195 loaders.loadImportDirRec(path, self.engine)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
196 else:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
197 raise file+ " is not a directory!"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
198 except:
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
199 traceback.print_exc(sys.exc_info()[1])
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
200 errormsg = u"Importing directory failed:\n"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
201 errormsg += u"File: "+unicode(file)+u"\n"
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
202 errormsg += u"Error: "+unicode(sys.exc_info()[1])
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
203 ErrorDialog(errormsg)
0adf9423062e * Buttons and functions for importing objects in the editor
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 255
diff changeset
204 return None
325
54de5aebf732 * ObjectSelector will now select and scroll to selected object automatically
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 282
diff changeset
205
54de5aebf732 * ObjectSelector will now select and scroll to selected object automatically
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 282
diff changeset
206 events.onObjectsImported.send(sender=self)
255
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 class CameraEditor(object):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210 CameraEditor provides a gui dialog for camera creation. The callback is called when camera creation is complete. A
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 partial specification of the camera parameters may optionally be given.
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 """
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213 def __init__(self, engine, callback=None, onCancel=None, map=None, layer=None):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 self.engine = engine
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215 self.callback = callback
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216 self.onCancel = onCancel
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217 self._widget = pychan.loadXML('gui/cameraedit.xml')
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 if map:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 self._widget.distributeData({
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 'mapBox' : unicode(map.getId()),
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 })
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224 if layer:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225 self._widget.distributeData({
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
226 'layerBox' : unicode(layer.getId()),
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
227 })
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229 self._widget.mapEvents({
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
230 'okButton' : self._finished,
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
231 'cancelButton' : self._cancelled
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
232 })
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 self._widget.show()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
236 def _cancelled(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
237 if self.onCancel:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
238 self.onCancel()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
239 self._widget.hide()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
240
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
241
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
242 def _finished(self):
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
243 id = self._widget.collectData('idBox')
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
244 if id == '':
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
245 print 'Please enter a camera id.'
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
246 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
247
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248 try:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
249 map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
250 except fife.Exception:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 print 'Cannot find the specified map id.'
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
253
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
254 try:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
255 layer = map.getLayer(str(self._widget.collectData('layerBox')))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 except fife.Exception:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
257 print 'Cannot find the specified layer id.'
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
258 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
259
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260 try:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261 vals = self._widget.collectData('viewBox').split(',')
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262 if len(vals) != 4:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263 raise ValueError
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
265 viewport = fife.Rect(*[int(c) for c in vals])
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
266 except ValueError:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267 print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.'
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
268 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270 try:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 refh = int(self._widget.collectData('refhBox'))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
272 refw = int(self._widget.collectData('refwBox'))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273 except ValueError:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
274 print 'Please enter positive integer values for reference width and height.'
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
275 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
277 try:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
278 rot = int(self._widget.collectData('rotBox'))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
279 tilt = int(self._widget.collectData('tiltBox'))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
280 except ValueError:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
281 print 'Please enter positive integer values for rotation and tilt.'
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
282 return
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
283
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
284 cam = self.engine.getView().addCamera(str(id), layer, viewport, fife.ExactModelCoordinate(0,0,0))
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
285 cam.setCellImageDimensions(refw, refh)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
286 cam.setRotation(rot)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287 cam.setTilt(tilt)
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
288
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
289 self._widget.hide()
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
290
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
291 if self.callback:
51cc05d862f2 Merged editor_rewrite branch to trunk.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
292 self.callback()