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 |
|
|
557 |
|
|
558 |
if not root.IsOk(): |
if not root.IsOk(): |
559 |
self.image_list = wxImageList(BMP_SIZE_W, BMP_SIZE_H, False, 0) |
self.image_list = wxImageList(BMP_SIZE_W, BMP_SIZE_H, False, 0) |
560 |
|
|
561 |
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
562 |
dc = wxMemoryDC() |
dc = wxMemoryDC() |
563 |
dc.SelectObject(bmp) |
dc.SelectObject(bmp) |
564 |
dc.SetBrush(wxBLACK_BRUSH) |
dc.SetBrush(wxBLACK_BRUSH) |
565 |
dc.Clear() |
dc.Clear() |
566 |
dc.SelectObject(wxNullBitmap) |
dc.SelectObject(wxNullBitmap) |
567 |
|
|
568 |
self.emptyImageIndex = \ |
self.emptyImageIndex = \ |
569 |
self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0)) |
self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0)) |
570 |
|
|
571 |
bmp = resource.GetBitmapResource("legend_icon_layer", |
bmp = resource.GetBitmapResource("legend_icon_layer", |
572 |
wxBITMAP_TYPE_XPM) |
wxBITMAP_TYPE_XPM) |
573 |
self.mapImageIndex = \ |
self.mapImageIndex = \ |
574 |
self.image_list.Add(bmp) |
self.image_list.Add(bmp) |
575 |
|
|
576 |
self.AssignImageList(self.image_list) |
self.AssignImageList(self.image_list) |
577 |
|
self.availImgListIndices = [] |
578 |
|
|
579 |
root = self.AddRoot("") |
root = self.AddRoot("") |
580 |
|
|