1 |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jonathan Coles <[email protected]> |
4 |
|
# Frank Koormann <[email protected]> |
5 |
# |
# |
6 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
14 |
|
|
15 |
from wxPython.wx import * |
from wxPython.wx import * |
16 |
|
|
17 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import BaseLayer |
18 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
|
from Thuban.Model.scalebar import ScaleBar |
|
|
from Thuban.Model.messages import * |
|
19 |
from Thuban.Model.classification import ClassGroup |
from Thuban.Model.classification import ClassGroup |
20 |
|
|
21 |
from Thuban.UI.messages import * |
from Thuban.Model.messages import \ |
22 |
|
MAP_STACKING_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED, LAYER_CHANGED,\ |
23 |
|
LAYER_VISIBILITY_CHANGED, TITLE_CHANGED |
24 |
|
|
25 |
|
from Thuban.UI.messages import SCALE_CHANGED |
26 |
|
|
27 |
from Thuban.UI.classifier import ClassDataPreviewer |
from Thuban.UI.classifier import ClassDataPreviewer |
28 |
from Thuban.UI.dock import DockPanel |
from Thuban.UI.dock import DockPanel |
29 |
|
from Thuban.UI.scalebar import ScaleBar |
30 |
|
|
31 |
from Thuban.Lib.connector import ConnectorError |
from Thuban.Lib.connector import ConnectorError |
32 |
|
|
33 |
ID_LEGEND_RAISE = 4001 |
ID_LEGEND_TOP = 4001 |
34 |
ID_LEGEND_LOWER = 4002 |
ID_LEGEND_RAISE = 4002 |
35 |
ID_LEGEND_TREE = 4003 |
ID_LEGEND_LOWER = 4003 |
36 |
ID_LEGEND_PROPS = 4004 |
ID_LEGEND_BOTTOM = 4004 |
37 |
ID_LEGEND_SHOWLAYER = 4005 |
ID_LEGEND_TREE = 4005 |
38 |
ID_LEGEND_HIDELAYER = 4006 |
ID_LEGEND_PROPS = 4006 |
39 |
|
ID_LEGEND_SHOWLAYER = 4007 |
40 |
|
ID_LEGEND_HIDELAYER = 4008 |
41 |
|
|
42 |
BMP_SIZE_W = 30 |
BMP_SIZE_W = 15 |
43 |
BMP_SIZE_H = 15 |
BMP_SIZE_H = 15 |
44 |
|
|
45 |
|
TOP_BMP = "top_layer" |
46 |
RAISE_BMP = "raise_layer" |
RAISE_BMP = "raise_layer" |
47 |
LOWER_BMP = "lower_layer" |
LOWER_BMP = "lower_layer" |
48 |
|
BOTTOM_BMP = "bottom_layer" |
49 |
SHOW_BMP = "show_layer" |
SHOW_BMP = "show_layer" |
50 |
HIDE_BMP = "hide_layer" |
HIDE_BMP = "hide_layer" |
51 |
PROPS_BMP = "layer_properties" |
PROPS_BMP = "layer_properties" |
66 |
self.toolBar = wxToolBar(self, -1) |
self.toolBar = wxToolBar(self, -1) |
67 |
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
68 |
|
|
69 |
|
bmp = resource.GetBitmapResource(TOP_BMP, wxBITMAP_TYPE_XPM) |
70 |
|
self.toolBar.AddTool(ID_LEGEND_TOP, bmp, |
71 |
|
shortHelpString=_("Top Layer")) |
72 |
|
|
73 |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
74 |
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
75 |
shortHelpString=_("Raise Layer")) |
shortHelpString=_("Raise Layer")) |
78 |
self.toolBar.AddTool(ID_LEGEND_LOWER, bmp, |
self.toolBar.AddTool(ID_LEGEND_LOWER, bmp, |
79 |
shortHelpString=_("Lower Layer")) |
shortHelpString=_("Lower Layer")) |
80 |
|
|
81 |
|
bmp = resource.GetBitmapResource(BOTTOM_BMP, wxBITMAP_TYPE_XPM) |
82 |
|
self.toolBar.AddTool(ID_LEGEND_BOTTOM, bmp, |
83 |
|
shortHelpString=_("Bottom Layer")) |
84 |
|
|
85 |
bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM) |
86 |
self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp, |
self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp, |
87 |
shortHelpString=_("Show Layer")) |
shortHelpString=_("Show Layer")) |
97 |
self.toolBar.Realize() |
self.toolBar.Realize() |
98 |
panelBox.Add(self.toolBar, 0, wxGROW, 0) |
panelBox.Add(self.toolBar, 0, wxGROW, 0) |
99 |
|
|
100 |
|
EVT_TOOL(self, ID_LEGEND_TOP, self._OnMoveTop) |
101 |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
102 |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
103 |
|
EVT_TOOL(self, ID_LEGEND_BOTTOM, self._OnMoveBottom) |
104 |
EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties) |
EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties) |
105 |
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
106 |
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
135 |
|
|
136 |
def DoOnSelChanged(self, layer, group): |
def DoOnSelChanged(self, layer, group): |
137 |
|
|
138 |
ok = isinstance(layer, Layer) |
ok = isinstance(layer, BaseLayer) |
139 |
self.__EnableButtons(ok) |
self.__EnableButtons(ok) |
140 |
|
|
141 |
self.mainWindow.SelectLayer(layer) |
self.mainWindow.SelectLayer(layer) |
143 |
def DoOnProperties(self): |
def DoOnProperties(self): |
144 |
list = self.tree.GetSelectedHierarchy() |
list = self.tree.GetSelectedHierarchy() |
145 |
|
|
146 |
ok = isinstance(list[0], Layer) |
ok = isinstance(list[0], BaseLayer) |
147 |
if ok: |
if ok: |
148 |
self.mainWindow.OpenLayerProperties(list[0], list[1]) |
self.mainWindow.OpenLayerProperties(list[0], list[1]) |
149 |
|
|
153 |
def _OnProperties(self, event): |
def _OnProperties(self, event): |
154 |
self.DoOnProperties() |
self.DoOnProperties() |
155 |
|
|
156 |
|
def _OnMoveTop(self, event): |
157 |
|
self.tree.MoveCurrentItemTop() |
158 |
|
|
159 |
def _OnMoveUp(self, event): |
def _OnMoveUp(self, event): |
160 |
self.tree.MoveCurrentItemUp() |
self.tree.MoveCurrentItemUp() |
161 |
|
|
162 |
def _OnMoveDown(self, event): |
def _OnMoveDown(self, event): |
163 |
self.tree.MoveCurrentItemDown() |
self.tree.MoveCurrentItemDown() |
164 |
|
|
165 |
|
def _OnMoveBottom(self, event): |
166 |
|
self.tree.MoveCurrentItemBottom() |
167 |
|
|
168 |
def _OnShowLayer(self, event): |
def _OnShowLayer(self, event): |
169 |
self.tree.DoOnShowLayer() |
self.tree.DoOnShowLayer() |
170 |
pass |
pass |
180 |
pass |
pass |
181 |
|
|
182 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
183 |
|
self.toolBar.EnableTool(ID_LEGEND_TOP, on) |
184 |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
185 |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
186 |
|
self.toolBar.EnableTool(ID_LEGEND_BOTTOM, on) |
187 |
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
188 |
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
189 |
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
203 |
self.parent = parent |
self.parent = parent |
204 |
self.layer2id = {} |
self.layer2id = {} |
205 |
|
|
206 |
|
# |
207 |
|
# The image list used by the wxTreeCtrl causes problems when |
208 |
|
# we remove layers and/or change a classification because it |
209 |
|
# changes the image indices if you remove images from the list. |
210 |
|
# Rather than removing unused images we use this list to keep |
211 |
|
# track of which indices are available in the image list |
212 |
|
# (because of a previous removal) and then replace those indices |
213 |
|
# with new images rather than appending to the end of the image |
214 |
|
# list (assuming there are any that are available). |
215 |
|
# |
216 |
|
self.availImgListIndices = [] |
217 |
|
|
218 |
self.image_list = None |
self.image_list = None |
219 |
self.emptyImageIndex = 0 |
self.emptyImageIndex = 0 |
220 |
|
|
236 |
def SetMap(self, map): |
def SetMap(self, map): |
237 |
|
|
238 |
sub_list = [(MAP_STACKING_CHANGED, self._OnMsgMapStackingChanged), |
sub_list = [(MAP_STACKING_CHANGED, self._OnMsgMapStackingChanged), |
239 |
(MAP_LAYERS_ADDED, self._OnMsgMapLayersAddedRemoved), |
(MAP_LAYERS_ADDED, self._OnMsgMapLayersAdded), |
240 |
(MAP_LAYERS_REMOVED, self._OnMsgMapLayersAddedRemoved)] |
(MAP_LAYERS_REMOVED, self._OnMsgMapLayersRemoved)] |
241 |
|
|
242 |
if self.map is not None: |
if self.map is not None: |
243 |
for msg, func in sub_list: self.map.Unsubscribe(msg, func) |
for msg, func in sub_list: self.map.Unsubscribe(msg, func) |
248 |
#self._OnMsgMapsChanged) |
#self._OnMsgMapsChanged) |
249 |
#except ConnectorError: |
#except ConnectorError: |
250 |
#pass |
#pass |
251 |
self.__DeleteAllItems() |
self.DeleteAllItems() |
252 |
|
|
253 |
self.map = map |
self.map = map |
254 |
|
|
260 |
#self._OnMsgMapsChanged) |
#self._OnMsgMapsChanged) |
261 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
262 |
|
|
263 |
|
def MoveCurrentItemTop(self): |
264 |
|
layer, group = self.GetSelectedHierarchy() |
265 |
|
|
266 |
|
if layer is not None: |
267 |
|
self.map.MoveLayerToTop(layer) |
268 |
|
else: |
269 |
|
assert False, "Shouldn't be allowed." |
270 |
|
pass |
271 |
|
|
272 |
def MoveCurrentItemUp(self): |
def MoveCurrentItemUp(self): |
273 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
274 |
|
|
287 |
assert False, "Shouldn't be allowed." |
assert False, "Shouldn't be allowed." |
288 |
pass |
pass |
289 |
|
|
290 |
|
def MoveCurrentItemBottom(self): |
291 |
|
layer, group = self.GetSelectedHierarchy() |
292 |
|
|
293 |
|
if layer is not None: |
294 |
|
self.map.MoveLayerToBottom(layer) |
295 |
|
else: |
296 |
|
assert False, "Shouldn't be allowed." |
297 |
|
pass |
298 |
|
|
299 |
def OnCompareItems(self, item1, item2): |
def OnCompareItems(self, item1, item2): |
300 |
|
|
301 |
data1 = self.GetPyData(item1) |
data1 = self.GetPyData(item1) |
302 |
data2 = self.GetPyData(item2) |
data2 = self.GetPyData(item2) |
303 |
|
|
304 |
if isinstance(data1, Layer): |
if isinstance(data1, BaseLayer): |
305 |
layers = self.map.Layers() |
layers = self.map.Layers() |
306 |
return layers.index(data2) - layers.index(data1) |
return layers.index(data2) - layers.index(data1) |
307 |
else: |
else: |
308 |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
return wxTreeCtrl.OnCompareItems(self, item1, item2) |
309 |
|
|
|
|
|
310 |
def DoOnShowLayer(self): |
def DoOnShowLayer(self): |
|
#self.__ShowHideLayer(True) |
|
311 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
312 |
layer.SetVisible(True) |
layer.SetVisible(True) |
313 |
|
|
314 |
def DoOnHideLayer(self): |
def DoOnHideLayer(self): |
|
#self.__ShowHideLayer(False) |
|
315 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
316 |
layer.SetVisible(False) |
layer.SetVisible(False) |
317 |
|
|
346 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
347 |
|
|
348 |
def _OnMsgLayerChanged(self, layer): |
def _OnMsgLayerChanged(self, layer): |
349 |
assert isinstance(layer, Layer) |
assert isinstance(layer, BaseLayer) |
350 |
|
|
351 |
id = self.layer2id[layer] |
id = self.layer2id[layer] |
352 |
assert id.IsOk() |
assert id.IsOk() |
353 |
|
|
354 |
# XXX: yikes! this is so bad, we should be doing what is |
self.__FillTreeLayer(id) |
|
# commented out, but there is a problem with keeping |
|
|
# track of the images in the image list when we replace |
|
|
# a layer. it ends up causing a seg fault. |
|
|
self.__FillTree(self.map) |
|
355 |
self.__UpdateSelection() |
self.__UpdateSelection() |
|
#self.__FillTreeLayer(id) |
|
356 |
|
|
357 |
def _OnMsgMapStackingChanged(self, *args): |
def _OnMsgMapStackingChanged(self, *args): |
358 |
self.Sort() |
self.Sort() |
362 |
self.EnsureVisible(id) |
self.EnsureVisible(id) |
363 |
self.__UpdateSelection() |
self.__UpdateSelection() |
364 |
|
|
365 |
def _OnMsgMapLayersAddedRemoved(self, map): |
def _OnMsgMapLayersAdded(self, map): |
366 |
assert map is self.map |
assert map is self.map |
367 |
|
|
368 |
self.__FillTree(self.map) |
root = self.GetRootItem() |
369 |
|
|
370 |
|
i = 0 |
371 |
|
for l in map.Layers(): |
372 |
|
if not self.layer2id.has_key(l): |
373 |
|
self.__AddLayer(i, l) |
374 |
|
|
375 |
|
self.__UpdateSelection() |
376 |
|
|
377 |
|
def _OnMsgMapLayersRemoved(self, map): |
378 |
|
assert map is self.map |
379 |
|
|
380 |
|
layer, group = self.GetSelectedHierarchy() |
381 |
|
|
382 |
|
if layer is None: |
383 |
|
assert False, "Shouldn't be allowed." |
384 |
|
return |
385 |
|
|
386 |
|
layers = map.Layers() |
387 |
|
|
388 |
|
for layer, id in self.layer2id.items(): |
389 |
|
if layer not in layers: |
390 |
|
if id.IsOk(): |
391 |
|
self.__RemoveLayer(id) |
392 |
|
|
393 |
self.__UpdateSelection() |
self.__UpdateSelection() |
394 |
|
|
395 |
def _OnMsgLayerVisibilityChanged(self, layer): |
def _OnMsgLayerVisibilityChanged(self, layer): |
396 |
assert isinstance(layer, Layer) |
assert isinstance(layer, BaseLayer) |
397 |
|
|
398 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
399 |
self.__UpdateSelection() |
self.__UpdateSelection() |
413 |
|
|
414 |
self.Freeze() |
self.Freeze() |
415 |
|
|
416 |
self.__DeleteAllItems() |
self.DeleteAllItems() |
417 |
|
|
418 |
if map.HasLayers(): |
if map.HasLayers(): |
419 |
|
root = self.GetRootItem() |
|
self.image_list = wxImageList(BMP_SIZE_W, BMP_SIZE_H, False, 0) |
|
|
|
|
|
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
|
|
dc = wxMemoryDC() |
|
|
dc.SelectObject(bmp) |
|
|
dc.SetBrush(wxBLACK_BRUSH) |
|
|
dc.Clear() |
|
|
dc.SelectObject(wxNullBitmap) |
|
|
|
|
|
self.emptyImageIndex = \ |
|
|
self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0)) |
|
|
|
|
|
self.AssignImageList(self.image_list) |
|
|
|
|
|
root = self.AddRoot("") |
|
|
|
|
420 |
for l in map.Layers(): |
for l in map.Layers(): |
421 |
id = self.PrependItem(root, l.Title()) |
self.__AddLayer(0, l) |
|
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
|
|
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
|
|
self._OnMsgLayerVisibilityChanged) |
|
|
l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
|
|
self.SetPyData(id, l) |
|
|
self.__SetVisibilityStyle(l.Visible(), id) |
|
|
|
|
|
self.layer2id[l] = id |
|
|
|
|
|
self.__FillTreeLayer(id) |
|
|
self.Expand(id) |
|
422 |
|
|
423 |
self.Thaw() |
self.Thaw() |
424 |
|
|
429 |
|
|
430 |
self.DeleteChildren(pid) |
self.DeleteChildren(pid) |
431 |
|
|
432 |
clazz = layer.GetClassification() |
if layer.HasClassification(): |
433 |
|
|
434 |
shapeType = layer.ShapeType() |
clazz = layer.GetClassification() |
435 |
|
|
436 |
show = layer.Visible() |
shapeType = layer.ShapeType() |
437 |
for g in clazz: |
|
438 |
if g.IsVisible(): |
show = layer.Visible() |
439 |
id = self.AppendItem(pid, g.GetDisplayText()) |
for g in clazz: |
440 |
self.SetPyData(id, g) |
if g.IsVisible(): |
441 |
self.__SetVisibilityStyle(show, id) |
id = self.AppendItem(pid, g.GetDisplayText()) |
442 |
|
self.SetPyData(id, g) |
443 |
bmp = self.__BuildGroupImage(g, shapeType) |
self.__SetVisibilityStyle(show, id) |
444 |
|
|
445 |
if bmp is None: |
bmp = self.__BuildGroupImage(g, shapeType) |
446 |
self.SetItemImage(id, self.emptyImageIndex) |
|
447 |
else: |
if bmp is None: |
448 |
i = self.image_list.Add(bmp) |
self.SetItemImage(id, -1) |
449 |
self.SetItemImage(id, i) |
self.SetItemSelectedImage(id, -1) |
450 |
|
else: |
451 |
|
if self.availImgListIndices: |
452 |
|
i = self.availImgListIndices.pop(0) |
453 |
|
self.image_list.Replace(i, bmp) |
454 |
|
else: |
455 |
|
i = self.image_list.Add(bmp) |
456 |
|
|
457 |
|
self.SetItemImage(id, i) |
458 |
|
self.SetItemSelectedImage(id, i) |
459 |
|
|
460 |
self.Thaw() |
self.Thaw() |
461 |
|
|
471 |
|
|
472 |
return bmp |
return bmp |
473 |
|
|
474 |
def __DeleteAllItems(self): |
def DeleteAllItems(self): |
475 |
|
|
476 |
while len(self.layer2id) > 0: |
pid = self.GetRootItem() |
|
layer, id = self.layer2id.popitem() |
|
|
layer.Unsubscribe(LAYER_CHANGED, |
|
|
self._OnMsgLayerChanged) |
|
|
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
|
|
self._OnMsgLayerVisibilityChanged) |
|
|
layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
|
477 |
|
|
478 |
self.DeleteAllItems() |
id, cookie = self.GetFirstChild(pid, 123) |
479 |
|
while id.IsOk(): |
480 |
|
self.__RemoveLayer(id) |
481 |
|
id, cookie = self.GetNextChild(pid, cookie) |
482 |
|
|
483 |
|
wxTreeCtrl.DeleteAllItems(self) |
484 |
|
|
485 |
|
def __AddLayer(self, before, l): |
486 |
|
root = self.GetRootItem() |
487 |
|
id = self.InsertItemBefore(root, before, |
488 |
|
l.Title(), |
489 |
|
self.mapImageIndex, |
490 |
|
self.mapImageIndex) |
491 |
|
|
492 |
|
self.SetPyData(id, l) |
493 |
|
self.__SetVisibilityStyle(l.Visible(), id) |
494 |
|
|
495 |
|
self.layer2id[l] = id |
496 |
|
|
497 |
|
self.__FillTreeLayer(id) |
498 |
|
self.Expand(id) |
499 |
|
|
500 |
|
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
501 |
|
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
502 |
|
self._OnMsgLayerVisibilityChanged) |
503 |
|
l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
504 |
|
|
505 |
|
def __RemoveLayer(self, id): |
506 |
|
self.DeleteChildren(id) |
507 |
|
|
508 |
|
layer = self.GetPyData(id) |
509 |
|
layer.Unsubscribe(LAYER_CHANGED, |
510 |
|
self._OnMsgLayerChanged) |
511 |
|
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
512 |
|
self._OnMsgLayerVisibilityChanged) |
513 |
|
layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
514 |
|
|
515 |
|
self.Delete(id) |
516 |
|
del self.layer2id[layer] |
517 |
|
|
518 |
|
def DeleteChildren(self, pid): |
519 |
|
id, cookie = self.GetFirstChild(pid, 123) |
520 |
|
while id.IsOk(): |
521 |
|
self.availImgListIndices.append(self.GetItemImage(id)) |
522 |
|
id, cookie = self.GetNextChild(pid, cookie) |
523 |
|
wxTreeCtrl.DeleteChildren(self, pid) |
524 |
|
|
525 |
|
def GetRootItem(self): |
526 |
|
root = wxTreeCtrl.GetRootItem(self) |
527 |
|
|
528 |
|
if not root.IsOk(): |
529 |
|
self.image_list = wxImageList(BMP_SIZE_W, BMP_SIZE_H, False, 0) |
530 |
|
|
531 |
|
bmp = wxEmptyBitmap(BMP_SIZE_W, BMP_SIZE_H) |
532 |
|
dc = wxMemoryDC() |
533 |
|
dc.SelectObject(bmp) |
534 |
|
dc.SetBrush(wxBLACK_BRUSH) |
535 |
|
dc.Clear() |
536 |
|
dc.SelectObject(wxNullBitmap) |
537 |
|
|
538 |
|
self.emptyImageIndex = \ |
539 |
|
self.image_list.AddWithColourMask(bmp, wxColour(0, 0, 0)) |
540 |
|
|
541 |
|
bmp = resource.GetBitmapResource("legend_icon_layer", |
542 |
|
wxBITMAP_TYPE_XPM) |
543 |
|
self.mapImageIndex = \ |
544 |
|
self.image_list.Add(bmp) |
545 |
|
|
546 |
|
self.AssignImageList(self.image_list) |
547 |
|
|
548 |
|
root = self.AddRoot("") |
549 |
|
|
550 |
|
return root |
551 |
|
|
552 |
def __SetVisibilityStyle(self, visible, id): |
def __SetVisibilityStyle(self, visible, id): |
553 |
font = self.GetItemFont(id) |
font = self.GetItemFont(id) |
556 |
font.SetStyle(wxNORMAL) |
font.SetStyle(wxNORMAL) |
557 |
color = wxBLACK |
color = wxBLACK |
558 |
else: |
else: |
559 |
font.SetStyle(wxITALIC) |
#font.SetStyle(wxITALIC) |
560 |
|
font.SetStyle(wxNORMAL) |
561 |
color = wxLIGHT_GREY |
color = wxLIGHT_GREY |
562 |
|
|
563 |
self.SetItemTextColour(id, color) |
self.SetItemTextColour(id, color) |
583 |
# While the width is fixed, get the height _now_. |
# While the width is fixed, get the height _now_. |
584 |
dc = wxMemoryDC() |
dc = wxMemoryDC() |
585 |
textwidth, textheight = dc.GetTextExtent("%d"%0) |
textwidth, textheight = dc.GetTextExtent("%d"%0) |
586 |
self.width = 200 |
self.width = 210 |
587 |
self.height = textheight + 3*2 + 8 |
self.height = textheight + 3*2 + 8 |
588 |
|
|
589 |
wxBoxSizer.__init__(self, wxVERTICAL) |
wxBoxSizer.__init__(self, wxVERTICAL) |
594 |
self.mainWindow = mainWindow |
self.mainWindow = mainWindow |
595 |
self.parent = parent |
self.parent = parent |
596 |
self.canvas = None |
self.canvas = None |
|
self.scalebar = ScaleBar(map) |
|
597 |
self.SetCanvas(self.mainWindow.canvas) |
self.SetCanvas(self.mainWindow.canvas) |
598 |
|
|
599 |
def SetCanvas(self, canvas): |
def SetCanvas(self, canvas): |
603 |
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
for msg, func in sub_list: self.canvas.Unsubscribe(msg, func) |
604 |
|
|
605 |
self.canvas = canvas |
self.canvas = canvas |
606 |
|
self.scalebar = ScaleBar(canvas.map) |
607 |
|
|
608 |
if self.canvas is not None: |
if self.canvas is not None: |
609 |
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
for msg, func in sub_list: self.canvas.Subscribe(msg, func) |
618 |
dc.SelectObject(bmp) |
dc.SelectObject(bmp) |
619 |
dc.Clear() |
dc.Clear() |
620 |
|
|
621 |
self.scalebar.DrawScalebar(scale, dc) |
self.scalebar.DrawScaleBar(scale, dc, (0,0), dc.GetSizeTuple()) |
622 |
|
|
623 |
self.scalebarBitmap.SetBitmap(bmp) |
self.scalebarBitmap.SetBitmap(bmp) |
624 |
|
|