comparison clients/editor/plugins/mapeditor.py @ 177:3fb17daa1b27

* Added ToggleButton widget * Modified editor to use togglebuttons in toolbox
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 25 Jan 2009 20:17:41 +0000
parents bb9902910067
children 28532ae6f9f6
comparison
equal deleted inserted replaced
176:542213eebe73 177:3fb17daa1b27
83 83
84 def hide(self): 84 def hide(self):
85 self._toolbar.hide() 85 self._toolbar.hide()
86 86
87 def _enableBtn(self, enabled, btn): 87 def _enableBtn(self, enabled, btn):
88 pass 88 btn.toggled = enabled;
89 89
90 def enableSelect(self, enabled):
91 self._enableBtn(enabled, self._toolbar.findChild(name='btnSelect'))
92
93 def enableMove(self, enabled):
94 self._enableBtn(enabled, self._toolbar.findChild(name='btnMove'))
95
90 def enableInsert(self, enabled): 96 def enableInsert(self, enabled):
91 self._enableBtn(enabled, self._toolbar.findChild(name='btnInsert')) 97 self._enableBtn(enabled, self._toolbar.findChild(name='btnInsert'))
92 98
93 def enableDelete(self, enabled): 99 def enableDelete(self, enabled):
94 self._enableBtn(enabled, self._toolbar.findChild(name='btnDelete')) 100 self._enableBtn(enabled, self._toolbar.findChild(name='btnDelete'))
95 101
96 def enableSelect(self, enabled): 102 def disableAll(self):
97 self._enableBtn(enabled, self._toolbar.findChild(name='btnSelect')) 103 self.enableDelete(False)
104 self.enableSelect(False)
105 self.enableInsert(False)
106 self.enableMove(False)
98 107
99 class StatusBar(object): 108 class StatusBar(object):
100 def __init__(self, screenw, screenh): 109 def __init__(self, screenw, screenh):
101 self._statusbar = pychan.loadXML('content/gui/statuspanel.xml') 110 self._statusbar = pychan.loadXML('content/gui/statuspanel.xml')
102 self._statusbar.show() 111 self._statusbar.show()
155 self._mapselector = MapSelection(self._selectLayer, self._selectObject) 164 self._mapselector = MapSelection(self._selectLayer, self._selectObject)
156 self._objectselector = None 165 self._objectselector = None
157 rb = self._engine.getRenderBackend() 166 rb = self._engine.getRenderBackend()
158 self._statusbar = StatusBar(rb.getWidth(), rb.getHeight()) 167 self._statusbar = StatusBar(rb.getWidth(), rb.getHeight())
159 self._toolbar = Toolbar(cbwa(self._setMode, VIEWING), cbwa(self._setMode, MOVING), 168 self._toolbar = Toolbar(cbwa(self._setMode, VIEWING), cbwa(self._setMode, MOVING),
160 cbwa(self._setMode, INSERTING), cbwa(self._setMode, REMOVING), 169 cbwa(self._setMode, INSERTING), cbwa(self._setMode, REMOVING),
161 self._statusbar.showTooltip, self._statusbar.hideTooltip) 170 self._statusbar.showTooltip, self._statusbar.hideTooltip)
162 self._toolbar.show() 171 self._toolbar.show()
163 self._setMode(NOTHING_LOADED) 172 self._setMode(NOTHING_LOADED)
164 173
165 self._undoStack = [] 174 self._undoStack = []
166 self._undo = False # tracks whether current action is an undo 175 self._undo = False # tracks whether current action is an undo
171 raise EditorLogicError(msg) 180 raise EditorLogicError(msg)
172 181
173 def _setMode(self, mode): 182 def _setMode(self, mode):
174 if (mode != NOTHING_LOADED) and (not self._camera): 183 if (mode != NOTHING_LOADED) and (not self._camera):
175 self._statusbar.setStatus('Please load map first') 184 self._statusbar.setStatus('Please load map first')
185 self._toolbar.disableAll()
176 return 186 return
177 if (mode == INSERTING) and (not self._object): 187 if (mode == INSERTING) and (not self._object):
178 self._statusbar.setStatus('Please select object first') 188 self._statusbar.setStatus('Please select object first')
179 return 189 mode = self._mode
190
191 # Update toolbox buttons
192 if (mode == INSERTING):
193 self._toolbar.enableInsert(True)
194 elif mode == VIEWING:
195 self._toolbar.enableSelect(True)
196 elif mode == REMOVING:
197 self._toolbar.enableDelete(True)
198 elif mode == MOVING:
199 self._toolbar.enableMove(True)
200 else:
201 self._toolbar.disableAll()
202
180 self._mode = mode 203 self._mode = mode
181 print "Entered mode " + mode 204 print "Entered mode " + mode
182 self._statusbar.setStatus(mode.replace('_', ' ').capitalize()) 205 self._statusbar.setStatus(mode.replace('_', ' ').capitalize())
183 206
184 # gui for selecting a map 207 # gui for selecting a map