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) |
57 |
|
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
|
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) |
|
58 |
|
|
59 |
panelBox.Add(buttonBox, 0, 0, 4) |
bmp = resource.GetBitmapResource(RAISE_BMP, wxBITMAP_TYPE_XPM) |
60 |
|
self.toolBar.AddTool(ID_LEGEND_RAISE, bmp, |
61 |
|
shortHelpString=_("Raise Layer")) |
62 |
|
|
63 |
|
bmp = resource.GetBitmapResource(LOWER_BMP, wxBITMAP_TYPE_XPM) |
64 |
|
self.toolBar.AddTool(ID_LEGEND_LOWER, bmp, |
65 |
|
shortHelpString=_("Lower Layer")) |
66 |
|
|
67 |
|
bmp = resource.GetBitmapResource(SHOW_BMP, wxBITMAP_TYPE_XPM) |
68 |
|
self.toolBar.AddTool(ID_LEGEND_SHOWLAYER, bmp, |
69 |
|
shortHelpString=_("Show Layer")) |
70 |
|
|
71 |
|
bmp = resource.GetBitmapResource(HIDE_BMP, wxBITMAP_TYPE_XPM) |
72 |
|
self.toolBar.AddTool(ID_LEGEND_HIDELAYER, bmp, |
73 |
|
shortHelpString=_("Hide Layer")) |
74 |
|
|
75 |
|
bmp = resource.GetBitmapResource(PROPS_BMP, wxBITMAP_TYPE_XPM) |
76 |
|
self.toolBar.AddTool(ID_LEGEND_PROPS, bmp, |
77 |
|
shortHelpString=_("Edit Layer Properties")) |
78 |
|
|
79 |
|
self.toolBar.Realize() |
80 |
|
panelBox.Add(self.toolBar, 0, wxALL, 0) |
81 |
|
|
82 |
|
EVT_TOOL(self, ID_LEGEND_RAISE, self._OnMoveUp) |
83 |
|
EVT_TOOL(self, ID_LEGEND_LOWER, self._OnMoveDown) |
84 |
|
EVT_TOOL(self, ID_LEGEND_PROPS, self._OnProperties) |
85 |
|
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
86 |
|
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
87 |
|
|
88 |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
89 |
|
|
90 |
panelBox.Add(self.tree, 1, wxGROW, 4) |
panelBox.Add(self.tree, 1, wxGROW, 0) |
91 |
|
|
92 |
panelBox.Fit(self) |
#panelBox.Fit(self) |
93 |
|
|
94 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
95 |
self.SetSizer(panelBox) |
self.SetSizer(panelBox) |
96 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
97 |
|
|
|
#panelBox.SetSizeHints(self.parent) |
|
98 |
|
|
99 |
self.panelBox = panelBox |
self.panelBox = panelBox |
100 |
|
|
101 |
|
self.__EnableButtons(False) |
102 |
|
|
103 |
|
self.Create() |
104 |
|
|
105 |
EVT_CLOSE(self, self._OnClose) |
EVT_CLOSE(self, self._OnClose) |
106 |
|
|
107 |
|
|
116 |
ok = isinstance(layer, Layer) |
ok = isinstance(layer, Layer) |
117 |
self.__EnableButtons(ok) |
self.__EnableButtons(ok) |
118 |
|
|
119 |
if ok: |
self.mainWindow.SelectLayer(layer) |
|
self.mainWindow.SelectLayer(layer) |
|
120 |
|
|
121 |
def DoOnProperties(self): |
def DoOnProperties(self): |
122 |
list = self.tree.GetSelectedHierarchy() |
list = self.tree.GetSelectedHierarchy() |
152 |
pass |
pass |
153 |
|
|
154 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
155 |
for b in self.buttons: |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
156 |
b.Enable(on) |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
157 |
|
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
158 |
|
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
159 |
|
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
160 |
|
|
161 |
def __Close(self): |
def __Close(self): |
162 |
self.tree.Close() |
self.tree.Close() |
280 |
def Sort(self): |
def Sort(self): |
281 |
self.SortChildren(self.GetRootItem()) |
self.SortChildren(self.GetRootItem()) |
282 |
|
|
283 |
|
def GetSelectedHierarchy(self): |
284 |
|
id = self.GetSelection() |
285 |
|
|
286 |
|
if not id.IsOk(): |
287 |
|
return (None, None) |
288 |
|
|
289 |
|
layer = self.GetPyData(id) |
290 |
|
group = None |
291 |
|
|
292 |
|
if isinstance(layer, ClassGroup): |
293 |
|
id = self.GetItemParent(id) |
294 |
|
assert id.IsOk() |
295 |
|
group = layer |
296 |
|
layer = self.GetPyData(id) |
297 |
|
|
298 |
|
return (layer, group) |
299 |
|
|
300 |
def _OnMsgMapsChanged(self): |
def _OnMsgMapsChanged(self): |
301 |
#print self.map is self.mainWindow.Map() |
#print self.map is self.mainWindow.Map() |
302 |
self.SetMap(self.mainWindow.Map()) |
self.SetMap(self.mainWindow.Map()) |
303 |
|
|
304 |
def _OnSelChanged(self, event): |
def _OnSelChanged(self, event): |
305 |
|
self.__UpdateSelection() |
|
layer, group = self.GetSelectedHierarchy() |
|
|
self.parent.DoOnSelChanged(layer, group) |
|
306 |
|
|
307 |
def _OnItemActivated(self, event): |
def _OnItemActivated(self, event): |
308 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
318 |
# track of the images in the image list when we replace |
# track of the images in the image list when we replace |
319 |
# a layer. it ends up causing a seg fault. |
# a layer. it ends up causing a seg fault. |
320 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
321 |
|
self.__UpdateSelection() |
322 |
#self.__FillTreeLayer(id) |
#self.__FillTreeLayer(id) |
323 |
|
|
324 |
def _OnMsgMapStackingChanged(self, *args): |
def _OnMsgMapStackingChanged(self, *args): |
327 |
|
|
328 |
if id.IsOk(): |
if id.IsOk(): |
329 |
self.EnsureVisible(id) |
self.EnsureVisible(id) |
330 |
|
self.__UpdateSelection() |
331 |
|
|
332 |
def _OnMsgMapLayersAddedRemoved(self, map): |
def _OnMsgMapLayersAddedRemoved(self, map): |
333 |
assert map is self.map |
assert map is self.map |
334 |
|
|
335 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
336 |
|
self.__UpdateSelection() |
337 |
|
|
338 |
def _OnMsgLayerVisibilityChanged(self, layer): |
def _OnMsgLayerVisibilityChanged(self, layer): |
339 |
assert isinstance(layer, Layer) |
assert isinstance(layer, Layer) |
340 |
|
|
341 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
342 |
|
self.__UpdateSelection() |
343 |
|
|
344 |
def GetSelectedHierarchy(self): |
def _OnMsgLayerTitleChanged(self, layer): |
|
id = self.GetSelection() |
|
|
assert id.IsOk() |
|
|
|
|
|
layer = self.GetPyData(id) |
|
|
group = None |
|
345 |
|
|
346 |
if isinstance(layer, ClassGroup): |
id = self.layer2id[layer] |
347 |
id = self.GetItemParent(id) |
if id.IsOk(): |
348 |
assert id.IsOk() |
self.SetItemText(id, layer.Title()) |
349 |
group = layer |
self.__UpdateSelection() |
|
layer = self.GetPyData(id) |
|
|
|
|
|
return (layer, group) |
|
350 |
|
|
351 |
|
def __UpdateSelection(self): |
352 |
|
layer, group = self.GetSelectedHierarchy() |
353 |
|
self.parent.DoOnSelChanged(layer, group) |
354 |
|
|
355 |
def __FillTree(self, map): |
def __FillTree(self, map): |
356 |
|
|
357 |
assert isinstance(map, Map) |
assert isinstance(map, Map) |
383 |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
384 |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
385 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
386 |
|
l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
387 |
self.SetPyData(id, l) |
self.SetPyData(id, l) |
388 |
self.__SetVisibilityStyle(l.Visible(), id) |
self.__SetVisibilityStyle(l.Visible(), id) |
389 |
|
|
443 |
self._OnMsgLayerChanged) |
self._OnMsgLayerChanged) |
444 |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
445 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
446 |
|
layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
447 |
|
|
448 |
self.DeleteAllItems() |
self.DeleteAllItems() |
449 |
|
|