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) |
|
buttonBox.Add(button, 0, wxGROW | wxLEFT | wxRIGHT, 0) |
|
|
self.buttons.append(button) |
|
|
|
|
|
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) |
|
55 |
|
|
56 |
panelBox.Add(buttonBox, 0, 0, 4) |
self.toolBar = wxToolBar(self, -1) |
57 |
|
self.toolBar.SetToolBitmapSize(wxSize(24, 24)) |
58 |
|
|
59 |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
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, wxGROW, 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 |
panelBox.Add(self.tree, 1, wxGROW, 4) |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
89 |
|
|
90 |
panelBox.Fit(self) |
panelBox.Add(self.tree, 1, wxGROW, 0) |
91 |
|
|
92 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
93 |
self.SetSizer(panelBox) |
self.SetSizer(panelBox) |
94 |
panelBox.SetSizeHints(self) |
panelBox.SetSizeHints(self) |
95 |
|
|
|
#panelBox.SetSizeHints(self.parent) |
|
96 |
|
|
97 |
self.panelBox = panelBox |
self.panelBox = panelBox |
98 |
|
|
99 |
|
self.__EnableButtons(False) |
100 |
|
|
101 |
|
self.Create() |
102 |
|
|
103 |
EVT_CLOSE(self, self._OnClose) |
EVT_CLOSE(self, self._OnClose) |
104 |
|
|
105 |
|
|
114 |
ok = isinstance(layer, Layer) |
ok = isinstance(layer, Layer) |
115 |
self.__EnableButtons(ok) |
self.__EnableButtons(ok) |
116 |
|
|
117 |
if ok: |
self.mainWindow.SelectLayer(layer) |
|
self.mainWindow.SelectLayer(layer) |
|
118 |
|
|
119 |
def DoOnProperties(self): |
def DoOnProperties(self): |
120 |
list = self.tree.GetSelectedHierarchy() |
list = self.tree.GetSelectedHierarchy() |
150 |
pass |
pass |
151 |
|
|
152 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
153 |
for b in self.buttons: |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
154 |
b.Enable(on) |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
155 |
|
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
156 |
|
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
157 |
|
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
158 |
|
|
159 |
def __Close(self): |
def __Close(self): |
160 |
self.tree.Close() |
self.tree.Close() |
278 |
def Sort(self): |
def Sort(self): |
279 |
self.SortChildren(self.GetRootItem()) |
self.SortChildren(self.GetRootItem()) |
280 |
|
|
281 |
|
def GetSelectedHierarchy(self): |
282 |
|
id = self.GetSelection() |
283 |
|
|
284 |
|
if not id.IsOk(): |
285 |
|
return (None, None) |
286 |
|
|
287 |
|
layer = self.GetPyData(id) |
288 |
|
group = None |
289 |
|
|
290 |
|
if isinstance(layer, ClassGroup): |
291 |
|
id = self.GetItemParent(id) |
292 |
|
assert id.IsOk() |
293 |
|
group = layer |
294 |
|
layer = self.GetPyData(id) |
295 |
|
|
296 |
|
return (layer, group) |
297 |
|
|
298 |
def _OnMsgMapsChanged(self): |
def _OnMsgMapsChanged(self): |
299 |
#print self.map is self.mainWindow.Map() |
#print self.map is self.mainWindow.Map() |
300 |
self.SetMap(self.mainWindow.Map()) |
self.SetMap(self.mainWindow.Map()) |
301 |
|
|
302 |
def _OnSelChanged(self, event): |
def _OnSelChanged(self, event): |
303 |
|
self.__UpdateSelection() |
|
layer, group = self.GetSelectedHierarchy() |
|
|
self.parent.DoOnSelChanged(layer, group) |
|
304 |
|
|
305 |
def _OnItemActivated(self, event): |
def _OnItemActivated(self, event): |
306 |
self.parent.DoOnProperties() |
self.parent.DoOnProperties() |
316 |
# track of the images in the image list when we replace |
# track of the images in the image list when we replace |
317 |
# a layer. it ends up causing a seg fault. |
# a layer. it ends up causing a seg fault. |
318 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
319 |
|
self.__UpdateSelection() |
320 |
#self.__FillTreeLayer(id) |
#self.__FillTreeLayer(id) |
321 |
|
|
322 |
def _OnMsgMapStackingChanged(self, *args): |
def _OnMsgMapStackingChanged(self, *args): |
325 |
|
|
326 |
if id.IsOk(): |
if id.IsOk(): |
327 |
self.EnsureVisible(id) |
self.EnsureVisible(id) |
328 |
|
self.__UpdateSelection() |
329 |
|
|
330 |
def _OnMsgMapLayersAddedRemoved(self, map): |
def _OnMsgMapLayersAddedRemoved(self, map): |
331 |
assert map is self.map |
assert map is self.map |
332 |
|
|
333 |
self.__FillTree(self.map) |
self.__FillTree(self.map) |
334 |
|
self.__UpdateSelection() |
335 |
|
|
336 |
def _OnMsgLayerVisibilityChanged(self, layer): |
def _OnMsgLayerVisibilityChanged(self, layer): |
337 |
assert isinstance(layer, Layer) |
assert isinstance(layer, Layer) |
338 |
|
|
339 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
340 |
|
self.__UpdateSelection() |
341 |
|
|
342 |
def GetSelectedHierarchy(self): |
def _OnMsgLayerTitleChanged(self, layer): |
|
id = self.GetSelection() |
|
|
assert id.IsOk() |
|
|
|
|
|
layer = self.GetPyData(id) |
|
|
group = None |
|
|
|
|
|
if isinstance(layer, ClassGroup): |
|
|
id = self.GetItemParent(id) |
|
|
assert id.IsOk() |
|
|
group = layer |
|
|
layer = self.GetPyData(id) |
|
343 |
|
|
344 |
return (layer, group) |
id = self.layer2id[layer] |
345 |
|
if id.IsOk(): |
346 |
|
self.SetItemText(id, layer.Title()) |
347 |
|
self.__UpdateSelection() |
348 |
|
|
349 |
|
def __UpdateSelection(self): |
350 |
|
layer, group = self.GetSelectedHierarchy() |
351 |
|
self.parent.DoOnSelChanged(layer, group) |
352 |
|
|
353 |
def __FillTree(self, map): |
def __FillTree(self, map): |
354 |
|
|
355 |
assert isinstance(map, Map) |
assert isinstance(map, Map) |
381 |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
382 |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
383 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
384 |
|
l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
385 |
self.SetPyData(id, l) |
self.SetPyData(id, l) |
386 |
self.__SetVisibilityStyle(l.Visible(), id) |
self.__SetVisibilityStyle(l.Visible(), id) |
387 |
|
|
441 |
self._OnMsgLayerChanged) |
self._OnMsgLayerChanged) |
442 |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
443 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
444 |
|
layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
445 |
|
|
446 |
self.DeleteAllItems() |
self.DeleteAllItems() |
447 |
|
|