31 |
from Thuban.UI.dock import DockPanel |
from Thuban.UI.dock import DockPanel |
32 |
from Thuban.UI.scalebar import ScaleBar |
from Thuban.UI.scalebar import ScaleBar |
33 |
|
|
34 |
|
from Thuban.UI.menu import Menu |
35 |
|
|
36 |
from Thuban.Lib.connector import ConnectorError |
from Thuban.Lib.connector import ConnectorError |
37 |
|
|
38 |
ID_LEGEND_TOP = 4001 |
ID_LEGEND_TOP = 4001 |
55 |
HIDE_BMP = "hide_layer" |
HIDE_BMP = "hide_layer" |
56 |
PROPS_BMP = "layer_properties" |
PROPS_BMP = "layer_properties" |
57 |
|
|
|
|
|
58 |
class LegendPanel(DockPanel): |
class LegendPanel(DockPanel): |
59 |
|
|
60 |
def __init__(self, parent, map, mainWindow): |
def __init__(self, parent, map, mainWindow): |
183 |
self.tree.DoOnHideLayer() |
self.tree.DoOnHideLayer() |
184 |
pass |
pass |
185 |
|
|
186 |
|
def _OnToggleVisibility(self, event): |
187 |
|
self.tree.ToggleVisibility() |
188 |
|
|
189 |
|
def _OnProjection(self, event): |
190 |
|
self.tree.LayerProjection() |
191 |
|
|
192 |
|
def _OnRemoveLayer(self, event): |
193 |
|
self.mainWindow.RemoveLayer() |
194 |
|
|
195 |
|
def _OnShowTable(self, event): |
196 |
|
self.mainWindow.LayerShowTable() |
197 |
|
|
198 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
199 |
self.toolBar.EnableTool(ID_LEGEND_TOP, on) |
self.toolBar.EnableTool(ID_LEGEND_TOP, on) |
200 |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
243 |
EVT_TREE_SEL_CHANGED(self, ID_LEGEND_TREE, self._OnSelChanged) |
EVT_TREE_SEL_CHANGED(self, ID_LEGEND_TREE, self._OnSelChanged) |
244 |
EVT_TREE_ITEM_EXPANDING(self, ID_LEGEND_TREE, self.OnItemExpandCollapse) |
EVT_TREE_ITEM_EXPANDING(self, ID_LEGEND_TREE, self.OnItemExpandCollapse) |
245 |
EVT_TREE_ITEM_COLLAPSING(self, ID_LEGEND_TREE, self.OnItemExpandCollapse) |
EVT_TREE_ITEM_COLLAPSING(self, ID_LEGEND_TREE, self.OnItemExpandCollapse) |
246 |
|
EVT_TREE_ITEM_RIGHT_CLICK(self, ID_LEGEND_TREE, self._OnRightClick) |
247 |
|
|
248 |
EVT_CLOSE(self, self._OnClose) |
EVT_CLOSE(self, self._OnClose) |
249 |
|
|
250 |
self.SetMap(map) |
self.SetMap(map) |
251 |
|
|
252 |
|
def _OnRightClick(self, event): |
253 |
|
"""Select item and pop up a context menu""" |
254 |
|
|
255 |
|
# The pop up menu is related to the legend tree, so we have direct |
256 |
|
# access on the tree items. The events issued by the menu are handled |
257 |
|
# by the legend panel, since most of the handlers are already |
258 |
|
# implemented there. |
259 |
|
|
260 |
|
# Update item selection to the right click |
261 |
|
item = event.GetItem() |
262 |
|
self.SelectItem(item) |
263 |
|
|
264 |
|
# Define the menu |
265 |
|
popup_menu = Menu("PopUp", "", |
266 |
|
[ "layer_visibility", |
267 |
|
None, |
268 |
|
"layer_properties", |
269 |
|
"layer_projection", |
270 |
|
"layer_remove", |
271 |
|
"layer_show_table", |
272 |
|
None, |
273 |
|
"layer_to_top", |
274 |
|
"layer_raise", |
275 |
|
"layer_lower", |
276 |
|
"layer_to_bottom" |
277 |
|
]) |
278 |
|
|
279 |
|
# Display the menu |
280 |
|
pos = event.GetPoint() |
281 |
|
shift = self.ClientToScreen((0,0)) |
282 |
|
self.PopupMenu(self.mainWindow.build_menu(popup_menu), pos) |
283 |
|
|
284 |
def find_layer(self, layer): |
def find_layer(self, layer): |
285 |
"""Return the tree item for the layer""" |
"""Return the tree item for the layer""" |
286 |
root = self.GetRootItem() |
root = self.GetRootItem() |
379 |
layer, group = self.GetSelectedHierarchy() |
layer, group = self.GetSelectedHierarchy() |
380 |
layer.SetVisible(False) |
layer.SetVisible(False) |
381 |
|
|
382 |
|
def ToggleVisibility(self): |
383 |
|
layer, group = self.GetSelectedHierarchy() |
384 |
|
|
385 |
|
layer.SetVisible(not layer.Visible()) |
386 |
|
|
387 |
|
def LayerProjection(self): |
388 |
|
self.parent.mainWindow.LayerProjection() |
389 |
|
|
390 |
def Sort(self): |
def Sort(self): |
391 |
self.SortChildren(self.GetRootItem()) |
self.SortChildren(self.GetRootItem()) |
392 |
|
|