9 |
|
|
10 |
from Thuban import _ |
from Thuban import _ |
11 |
|
|
12 |
|
import resource |
13 |
|
|
14 |
from wxPython.wx import * |
from wxPython.wx import * |
15 |
|
|
16 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
24 |
|
|
25 |
from Thuban.Lib.connector import ConnectorError |
from Thuban.Lib.connector import ConnectorError |
26 |
|
|
27 |
ID_LEGEND_MOVEUP = 4001 |
ID_LEGEND_RAISE = 4001 |
28 |
ID_LEGEND_MOVEDOWN = 4002 |
ID_LEGEND_LOWER = 4002 |
29 |
ID_LEGEND_TREE = 4003 |
ID_LEGEND_TREE = 4003 |
30 |
ID_LEGEND_PROPS = 4004 |
ID_LEGEND_PROPS = 4004 |
31 |
ID_LEGEND_SHOWLAYER = 4005 |
ID_LEGEND_SHOWLAYER = 4005 |
34 |
BMP_SIZE_W = 30 |
BMP_SIZE_W = 30 |
35 |
BMP_SIZE_H = 15 |
BMP_SIZE_H = 15 |
36 |
|
|
37 |
|
RAISE_BMP = "raise_layer" |
38 |
|
LOWER_BMP = "lower_layer" |
39 |
|
SHOW_BMP = "show_layer" |
40 |
|
HIDE_BMP = "hide_layer" |
41 |
|
PROPS_BMP = "layer_properties" |
42 |
|
|
43 |
|
|
44 |
class LegendPanel(DockPanel): |
class LegendPanel(DockPanel): |
45 |
|
|
46 |
def __init__(self, parent, map, mainWindow): |
def __init__(self, parent, map, mainWindow): |
49 |
self.mainWindow = mainWindow |
self.mainWindow = mainWindow |
50 |
self.parent = parent |
self.parent = parent |
51 |
|
|
|
panelBox = wxBoxSizer(wxVERTICAL) |
|
|
|
|
|
buttonBox = wxGridSizer(2, 3, 0, 0) |
|
|
|
|
52 |
self.buttons = [] |
self.buttons = [] |
53 |
|
|
54 |
button = wxButton(self, ID_LEGEND_MOVEUP, _("Move Up")) |
panelBox = wxBoxSizer(wxVERTICAL) |
55 |
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
|
56 |
self.buttons.append(button) |
self.toolBar = wxToolBar(self, -1) |
|
|
|
|
button = wxButton(self, ID_LEGEND_SHOWLAYER, _("Show Layer")) |
|
|
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
|
|
self.buttons.append(button) |
|
|
|
|
|
button = wxButton(self, ID_LEGEND_PROPS, _("Properties")) |
|
|
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
|
|
self.buttons.append(button) |
|
|
|
|
|
button = wxButton(self, ID_LEGEND_MOVEDOWN, _("Move Down")) |
|
|
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
|
|
self.buttons.append(button) |
|
|
|
|
|
button = wxButton(self, ID_LEGEND_HIDELAYER, _("Hide Layer")) |
|
|
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
|
|
self.buttons.append(button) |
|
|
|
|
|
EVT_BUTTON(self, ID_LEGEND_MOVEUP, self._OnMoveUp) |
|
|
EVT_BUTTON(self, ID_LEGEND_MOVEDOWN, self._OnMoveDown) |
|
|
EVT_BUTTON(self, ID_LEGEND_PROPS, self._OnProperties) |
|
|
EVT_BUTTON(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
|
|
EVT_BUTTON(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
|
57 |
|
|
58 |
panelBox.Add(buttonBox, 0, 0, 4) |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
59 |
|
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
60 |
|
shortHelpString=_("Raise Layer")) |
61 |
|
|
62 |
|
bmp = resource.GetBitmapResource(LOWER_BMP, wxBITMAP_TYPE_XPM) |
63 |
|
self.toolBar.AddTool(ID_LEGEND_LOWER, bmp, |
64 |
|
shortHelpString=_("Lower Layer")) |
65 |
|
|
66 |
|
bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM) |
67 |
|
self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp, |
68 |
|
shortHelpString=_("Show Layer")) |
69 |
|
|
70 |
|
bmp = resource.GetBitmapResource(HIDE_BMP, wxBITMAP_TYPE_XPM) |
71 |
|
self.toolBar.AddTool(ID_LEGEND_HIDELAYER, bmp, |
72 |
|
shortHelpString=_("Hide Layer")) |
73 |
|
|
74 |
|
bmp = resource.GetBitmapResource(PROPS_BMP, wxBITMAP_TYPE_XPM) |
75 |
|
self.toolBar.AddTool(ID_LEGEND_PROPS, bmp, |
76 |
|
shortHelpString=_("Edit Layer Properties")) |
77 |
|
|
78 |
|
self.toolBar.Realize() |
79 |
|
panelBox.Add(self.toolBar, 0, wxALL, 0) |
80 |
|
|
81 |
|
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
82 |
|
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
83 |
|
EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties) |
84 |
|
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
85 |
|
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
86 |
|
|
87 |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
88 |
|
|
94 |
self.SetSizer(panelBox) |
self.SetSizer(panelBox) |
95 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
96 |
|
|
|
#panelBox.SetSizeHints(self.parent) |
|
|
|
|
97 |
self.panelBox = panelBox |
self.panelBox = panelBox |
98 |
|
|
99 |
|
self.__EnableButtons(False) |
100 |
|
|
101 |
EVT_CLOSE(self, self._OnClose) |
EVT_CLOSE(self, self._OnClose) |
102 |
|
|
103 |
|
|
112 |
ok = isinstance(layer, Layer) |
ok = isinstance(layer, Layer) |
113 |
self.__EnableButtons(ok) |
self.__EnableButtons(ok) |
114 |
|
|
115 |
if ok: |
self.mainWindow.SelectLayer(layer) |
|
self.mainWindow.SelectLayer(layer) |
|
116 |
|
|
117 |
def DoOnProperties(self): |
def DoOnProperties(self): |
118 |
list = self.tree.GetSelectedHierarchy() |
list = self.tree.GetSelectedHierarchy() |
148 |
pass |
pass |
149 |
|
|
150 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
151 |
for b in self.buttons: |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
152 |
b.Enable(on) |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
153 |
|
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
154 |
|
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
155 |
|
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
156 |
|
|
157 |
def __Close(self): |
def __Close(self): |
158 |
self.tree.Close() |
self.tree.Close() |
276 |
def Sort(self): |
def Sort(self): |
277 |
self.SortChildren(self.GetRootItem()) |
self.SortChildren(self.GetRootItem()) |
278 |
|
|
279 |
|
def GetSelectedHierarchy(self): |
280 |
|
id = self.GetSelection() |
281 |
|
|
282 |
|
if not id.IsOk(): |
283 |
|
return (None, None) |
284 |
|
|
285 |
|
layer = self.GetPyData(id) |
286 |
|
group = None |
287 |
|
|
288 |
|
if isinstance(layer, ClassGroup): |
289 |
|
id = self.GetItemParent(id) |
290 |
|
assert id.IsOk() |
291 |
|
group = layer |
292 |
|
layer = self.GetPyData(id) |
293 |
|
|
294 |
|
return (layer, group) |
295 |
|
|
296 |
def _OnMsgMapsChanged(self): |
def _OnMsgMapsChanged(self): |
297 |
#print self.map is self.mainWindow.Map() |
#print self.map is self.mainWindow.Map() |
298 |
self.SetMap(self.mainWindow.Map()) |
self.SetMap(self.mainWindow.Map()) |
299 |
|
|
300 |
def _OnSelChanged(self, event): |
def _OnSelChanged(self, event): |
301 |
|
self.__UpdateSelection() |
|
layer, group = self.GetSelectedHierarchy() |
|
|
self.parent.DoOnSelChanged(layer, group) |
|
302 |
|
|
303 |
def _OnItemActivated(self, event): |
def _OnItemActivated(self, event): |
304 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
314 |
# track of the images in the image list when we replace |
# track of the images in the image list when we replace |
315 |
# a layer. it ends up causing a seg fault. |
# a layer. it ends up causing a seg fault. |
316 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
317 |
|
self.__UpdateSelection() |
318 |
#self.__FillTreeLayer(id) |
#self.__FillTreeLayer(id) |
319 |
|
|
320 |
def _OnMsgMapStackingChanged(self, *args): |
def _OnMsgMapStackingChanged(self, *args): |
323 |
|
|
324 |
if id.IsOk(): |
if id.IsOk(): |
325 |
self.EnsureVisible(id) |
self.EnsureVisible(id) |
326 |
|
self.__UpdateSelection() |
327 |
|
|
328 |
def _OnMsgMapLayersAddedRemoved(self, map): |
def _OnMsgMapLayersAddedRemoved(self, map): |
329 |
assert map is self.map |
assert map is self.map |
330 |
|
|
331 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
332 |
|
self.__UpdateSelection() |
333 |
|
|
334 |
def _OnMsgLayerVisibilityChanged(self, layer): |
def _OnMsgLayerVisibilityChanged(self, layer): |
335 |
assert isinstance(layer, Layer) |
assert isinstance(layer, Layer) |
336 |
|
|
337 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
338 |
|
self.__UpdateSelection() |
339 |
|
|
340 |
def GetSelectedHierarchy(self): |
def _OnMsgLayerTitleChanged(self, layer): |
|
id = self.GetSelection() |
|
|
assert id.IsOk() |
|
|
|
|
|
layer = self.GetPyData(id) |
|
|
group = None |
|
341 |
|
|
342 |
if isinstance(layer, ClassGroup): |
id = self.layer2id[layer] |
343 |
id = self.GetItemParent(id) |
if id.IsOk(): |
344 |
assert id.IsOk() |
self.SetItemText(id, layer.Title()) |
345 |
group = layer |
self.__UpdateSelection() |
|
layer = self.GetPyData(id) |
|
|
|
|
|
return (layer, group) |
|
346 |
|
|
347 |
|
def __UpdateSelection(self): |
348 |
|
layer, group = self.GetSelectedHierarchy() |
349 |
|
self.parent.DoOnSelChanged(layer, group) |
350 |
|
|
351 |
def __FillTree(self, map): |
def __FillTree(self, map): |
352 |
|
|
353 |
assert isinstance(map, Map) |
assert isinstance(map, Map) |
379 |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
380 |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
381 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
382 |
|
l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
383 |
self.SetPyData(id, l) |
self.SetPyData(id, l) |
384 |
self.__SetVisibilityStyle(l.Visible(), id) |
self.__SetVisibilityStyle(l.Visible(), id) |
385 |
|
|
439 |
self._OnMsgLayerChanged) |
self._OnMsgLayerChanged) |
440 |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
441 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
442 |
|
layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
443 |
|
|
444 |
self.DeleteAllItems() |
self.DeleteAllItems() |
445 |
|
|