202 |
self.map = None |
self.map = None |
203 |
self.parent = parent |
self.parent = parent |
204 |
self.layer2id = {} |
self.layer2id = {} |
205 |
|
self.changing_selection = 0 |
206 |
|
|
207 |
# |
# |
208 |
# The image list used by the wxTreeCtrl causes problems when |
# The image list used by the wxTreeCtrl causes problems when |
341 |
self.SetMap(self.mainWindow.Map()) |
self.SetMap(self.mainWindow.Map()) |
342 |
|
|
343 |
def _OnSelChanged(self, event): |
def _OnSelChanged(self, event): |
344 |
|
# If we change the selection from normalize_selection do nothing. |
345 |
|
if self.changing_selection: |
346 |
|
return |
347 |
|
|
348 |
|
self.normalize_selection() |
349 |
self.__UpdateSelection() |
self.__UpdateSelection() |
350 |
|
|
351 |
|
def normalize_selection(self): |
352 |
|
"""Select the layer containing currently selected item""" |
353 |
|
# This is really a workaround for a bug in wx where deleting a |
354 |
|
# subtree with DeleteChildren does not update the selection |
355 |
|
# properly and can lead to segfaults later because the return |
356 |
|
# value of GetSelection points to invalid data. |
357 |
|
item = self.GetSelection() |
358 |
|
while item.IsOk(): |
359 |
|
object = self.GetPyData(item) |
360 |
|
if isinstance(object, BaseLayer): |
361 |
|
break |
362 |
|
item = self.GetItemParent(item) |
363 |
|
else: |
364 |
|
# No layer was found in the chain of parents, so there's |
365 |
|
# nothing we can do. |
366 |
|
return |
367 |
|
|
368 |
|
self.changing_selection = 1 |
369 |
|
try: |
370 |
|
self.SelectItem(item) |
371 |
|
finally: |
372 |
|
self.changing_selection = 0 |
373 |
|
|
374 |
|
|
375 |
def _OnItemActivated(self, event): |
def _OnItemActivated(self, event): |
376 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
377 |
|
|