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 |
|
|
149 |
pass |
pass |
150 |
|
|
151 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
152 |
for b in self.buttons: |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
153 |
b.Enable(on) |
self.toolBar.EnableTool(ID_LEGEND_LOWER, on) |
154 |
|
self.toolBar.EnableTool(ID_LEGEND_SHOWLAYER, on) |
155 |
|
self.toolBar.EnableTool(ID_LEGEND_HIDELAYER, on) |
156 |
|
self.toolBar.EnableTool(ID_LEGEND_PROPS, on) |
157 |
|
|
158 |
def __Close(self): |
def __Close(self): |
159 |
self.tree.Close() |
self.tree.Close() |
319 |
|
|
320 |
self.__ShowHideLayer(layer) |
self.__ShowHideLayer(layer) |
321 |
|
|
322 |
|
def _OnMsgLayerTitleChanged(self, layer): |
323 |
|
|
324 |
|
id = self.layer2id[layer] |
325 |
|
if id.IsOk(): |
326 |
|
self.SetItemText(id, layer.Title()) |
327 |
|
|
328 |
def GetSelectedHierarchy(self): |
def GetSelectedHierarchy(self): |
329 |
id = self.GetSelection() |
id = self.GetSelection() |
330 |
assert id.IsOk() |
assert id.IsOk() |
371 |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
l.Subscribe(LAYER_CHANGED, self._OnMsgLayerChanged) |
372 |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
l.Subscribe(LAYER_VISIBILITY_CHANGED, |
373 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
374 |
|
l.Subscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
375 |
self.SetPyData(id, l) |
self.SetPyData(id, l) |
376 |
self.__SetVisibilityStyle(l.Visible(), id) |
self.__SetVisibilityStyle(l.Visible(), id) |
377 |
|
|
431 |
self._OnMsgLayerChanged) |
self._OnMsgLayerChanged) |
432 |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
layer.Unsubscribe(LAYER_VISIBILITY_CHANGED, |
433 |
self._OnMsgLayerVisibilityChanged) |
self._OnMsgLayerVisibilityChanged) |
434 |
|
layer.Unsubscribe(TITLE_CHANGED, self._OnMsgLayerTitleChanged) |
435 |
|
|
436 |
self.DeleteAllItems() |
self.DeleteAllItems() |
437 |
|
|