1 |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jonathan Coles <[email protected]> |
4 |
# Frank Koormann <[email protected]> |
# Frank Koormann <[email protected]> |
15 |
import resource |
import resource |
16 |
|
|
17 |
from wxPython.wx import * |
from wxPython.wx import * |
18 |
|
import wxPython |
19 |
|
|
20 |
from Thuban.Model.layer import BaseLayer |
from Thuban.Model.layer import BaseLayer |
21 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
32 |
from Thuban.UI.dock import DockPanel |
from Thuban.UI.dock import DockPanel |
33 |
from Thuban.UI.scalebar import ScaleBar |
from Thuban.UI.scalebar import ScaleBar |
34 |
|
|
35 |
|
from Thuban.UI.menu import Menu |
36 |
|
|
37 |
from Thuban.Lib.connector import ConnectorError |
from Thuban.Lib.connector import ConnectorError |
38 |
|
|
39 |
ID_LEGEND_TOP = 4001 |
ID_LEGEND_TOP = 4001 |
45 |
ID_LEGEND_SHOWLAYER = 4007 |
ID_LEGEND_SHOWLAYER = 4007 |
46 |
ID_LEGEND_HIDELAYER = 4008 |
ID_LEGEND_HIDELAYER = 4008 |
47 |
|
|
48 |
ID_POPUP_TOP = 4501 |
BMP_SIZE_W = 16 |
49 |
ID_POPUP_UP = 4502 |
BMP_SIZE_H = 16 |
|
ID_POPUP_DOWN = 4503 |
|
|
ID_POPUP_BOTTOM = 4504 |
|
|
ID_POPUP_PROPS = 4506 |
|
|
ID_POPUP_VISIBLE = 4507 |
|
|
ID_POPUP_PROJ = 4509 |
|
|
|
|
|
BMP_SIZE_W = 15 |
|
|
BMP_SIZE_H = 15 |
|
50 |
|
|
51 |
TOP_BMP = "top_layer" |
TOP_BMP = "top_layer" |
52 |
RAISE_BMP = "raise_layer" |
RAISE_BMP = "raise_layer" |
56 |
HIDE_BMP = "hide_layer" |
HIDE_BMP = "hide_layer" |
57 |
PROPS_BMP = "layer_properties" |
PROPS_BMP = "layer_properties" |
58 |
|
|
|
|
|
59 |
class LegendPanel(DockPanel): |
class LegendPanel(DockPanel): |
60 |
|
|
61 |
def __init__(self, parent, map, mainWindow): |
def __init__(self, parent, map, mainWindow): |
110 |
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
EVT_TOOL(self, ID_LEGEND_SHOWLAYER, self._OnShowLayer) |
111 |
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
EVT_TOOL(self, ID_LEGEND_HIDELAYER, self._OnHideLayer) |
112 |
|
|
|
EVT_MENU(self, ID_POPUP_PROPS, self._OnProperties) |
|
|
EVT_MENU(self, ID_POPUP_TOP, self._OnMoveTop) |
|
|
EVT_MENU(self, ID_POPUP_UP, self._OnMoveUp) |
|
|
EVT_MENU(self, ID_POPUP_DOWN, self._OnMoveDown) |
|
|
EVT_MENU(self, ID_POPUP_BOTTOM, self._OnMoveBottom) |
|
|
EVT_MENU(self, ID_POPUP_VISIBLE, self._OnToggleVisibility) |
|
|
EVT_MENU(self, ID_POPUP_PROJ, self._OnProjection) |
|
|
|
|
113 |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
self.tree = LegendTree(self, ID_LEGEND_TREE, map, mainWindow) |
114 |
|
|
115 |
panelBox.Add(self.tree, 1, wxGROW, 0) |
panelBox.Add(self.tree, 1, wxGROW, 0) |
190 |
def _OnProjection(self, event): |
def _OnProjection(self, event): |
191 |
self.tree.LayerProjection() |
self.tree.LayerProjection() |
192 |
|
|
193 |
|
def _OnRemoveLayer(self, event): |
194 |
|
self.mainWindow.RemoveLayer() |
195 |
|
|
196 |
|
def _OnShowTable(self, event): |
197 |
|
self.mainWindow.LayerShowTable() |
198 |
|
|
199 |
def __EnableButtons(self, on): |
def __EnableButtons(self, on): |
200 |
self.toolBar.EnableTool(ID_LEGEND_TOP, on) |
self.toolBar.EnableTool(ID_LEGEND_TOP, on) |
201 |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
self.toolBar.EnableTool(ID_LEGEND_RAISE, on) |
250 |
|
|
251 |
self.SetMap(map) |
self.SetMap(map) |
252 |
|
|
253 |
|
def _OnRightClick(self, event): |
254 |
|
"""Select item and pop up a context menu""" |
255 |
|
|
256 |
|
# The pop up menu is related to the legend tree, so we have direct |
257 |
|
# access on the tree items. The events issued by the menu are handled |
258 |
|
# by the legend panel, since most of the handlers are already |
259 |
|
# implemented there. |
260 |
|
|
261 |
|
# Update item selection to the right click |
262 |
|
item = event.GetItem() |
263 |
|
self.SelectItem(item) |
264 |
|
|
265 |
|
# Define the menu |
266 |
|
popup_menu = Menu("PopUp", "", |
267 |
|
[ "layer_visibility", |
268 |
|
None, |
269 |
|
"layer_properties", |
270 |
|
"layer_projection", |
271 |
|
"layer_remove", |
272 |
|
"layer_show_table", |
273 |
|
None, |
274 |
|
"layer_to_top", |
275 |
|
"layer_raise", |
276 |
|
"layer_lower", |
277 |
|
"layer_to_bottom" |
278 |
|
]) |
279 |
|
|
280 |
|
# Display the menu |
281 |
|
pos = event.GetPoint() |
282 |
|
shift = self.ClientToScreen((0,0)) |
283 |
|
self.PopupMenu(self.mainWindow.build_menu(popup_menu), pos) |
284 |
|
|
285 |
def find_layer(self, layer): |
def find_layer(self, layer): |
286 |
"""Return the tree item for the layer""" |
"""Return the tree item for the layer""" |
287 |
root = self.GetRootItem() |
root = self.GetRootItem() |
288 |
id, cookie = self.GetFirstChild(root, 0) |
id, cookie = self.GetFirstChild(root) |
289 |
while id.IsOk(): |
while id.IsOk(): |
290 |
if self.GetPyData(id) is layer: |
if self.GetPyData(id) is layer: |
291 |
return id |
return id |
449 |
event.Veto() |
event.Veto() |
450 |
self.preventExpandCollapse = False |
self.preventExpandCollapse = False |
451 |
|
|
|
def _OnRightClick(self, event): |
|
|
"""Select item and pop up a context menu""" |
|
|
|
|
|
# The pop up menu is related to the legend tree, so we have direct |
|
|
# access on the tree items. The events issued by the menu are handled |
|
|
# by the legend panel, since most of the handlers are already |
|
|
# implemented there. |
|
|
|
|
|
# Update item selection to the right click |
|
|
item = event.GetItem() |
|
|
self.SelectItem(item) |
|
|
|
|
|
# Create the menu |
|
|
menu = wxMenu("", 0) |
|
|
|
|
|
# The "Visible" item is a special ... |
|
|
menuitem = wxMenuItem(menu, ID_POPUP_VISIBLE, _("Visible"), |
|
|
"", wxITEM_CHECK) |
|
|
menu.AppendItem(menuitem) |
|
|
layer, group = self.GetSelectedHierarchy() |
|
|
menuitem.Check(layer.Visible()) |
|
|
|
|
|
menu.AppendSeparator() |
|
|
menu.Append(ID_POPUP_PROPS, _("Properties")) |
|
|
menu.Append(ID_POPUP_PROJ, _("Projection")) |
|
|
menu.AppendSeparator() |
|
|
menu.Append(ID_POPUP_TOP, _("Top")) |
|
|
menu.Append(ID_POPUP_UP, _("Up")) |
|
|
menu.Append(ID_POPUP_DOWN, _("Down")) |
|
|
menu.Append(ID_POPUP_BOTTOM, _("Bottom")) |
|
|
|
|
|
# Display the menu |
|
|
pos = event.GetPoint() |
|
|
shift = self.ClientToScreen((0,0)) |
|
|
self.PopupMenu(menu, pos) |
|
|
|
|
452 |
def _OnItemActivated(self, event): |
def _OnItemActivated(self, event): |
453 |
# The following looks strange but is need under Windows to |
# The following looks strange but is need under Windows to |
454 |
# raise the Properties on double-click: The tree control |
# raise the Properties on double-click: The tree control |
488 |
# Build a dict with all layers known by the the tree as keys |
# Build a dict with all layers known by the the tree as keys |
489 |
layers = {} |
layers = {} |
490 |
root = self.GetRootItem() |
root = self.GetRootItem() |
491 |
id, cookie = self.GetFirstChild(root, 0) |
id, cookie = self.GetFirstChild(root) |
492 |
while id.IsOk(): |
while id.IsOk(): |
493 |
layers[self.GetPyData(id)] = 1 |
layers[self.GetPyData(id)] = 1 |
494 |
id, cookie = self.GetNextChild(root, cookie) |
id, cookie = self.GetNextChild(root, cookie) |
507 |
layers = map.Layers() |
layers = map.Layers() |
508 |
|
|
509 |
root = self.GetRootItem() |
root = self.GetRootItem() |
510 |
id, cookie = self.GetFirstChild(root, 0) |
id, cookie = self.GetFirstChild(root) |
511 |
while id.IsOk(): |
while id.IsOk(): |
512 |
if self.GetPyData(id) not in layers: |
if self.GetPyData(id) not in layers: |
513 |
self.__RemoveLayer(id) |
self.__RemoveLayer(id) |
547 |
self.Thaw() |
self.Thaw() |
548 |
|
|
549 |
def __FillTreeLayer(self, pid): |
def __FillTreeLayer(self, pid): |
550 |
|
|
551 |
layer = self.GetPyData(pid) |
layer = self.GetPyData(pid) |
552 |
|
|
553 |
self.Freeze() |
self.Freeze() |
570 |
bmp = self.__BuildGroupImage(g, shapeType) |
bmp = self.__BuildGroupImage(g, shapeType) |
571 |
|
|
572 |
if bmp is None: |
if bmp is None: |
573 |
self.SetItemImage(id, -1) |
self.SetItemImage(id, -1, wxTreeItemIcon_Normal) |
574 |
self.SetItemSelectedImage(id, -1) |
self.SetItemImage(id, -1, wxTreeItemIcon_Selected) |
575 |
|
#self.SetItemSelectedImage(id, -1) |
576 |
else: |
else: |
577 |
if self.availImgListIndices: |
if self.availImgListIndices: |
578 |
i = self.availImgListIndices.pop(0) |
i = self.availImgListIndices.pop(0) |
580 |
else: |
else: |
581 |
i = self.image_list.Add(bmp) |
i = self.image_list.Add(bmp) |
582 |
|
|
583 |
self.SetItemImage(id, i) |
self.SetItemImage(id, i, wxTreeItemIcon_Normal) |
584 |
self.SetItemSelectedImage(id, i) |
self.SetItemImage(id, i, wxTreeItemIcon_Selected) |
585 |
|
#self.SetItemlectedImage(id, i) |
586 |
|
|
587 |
self.Thaw() |
self.Thaw() |
588 |
|
|
602 |
|
|
603 |
pid = self.GetRootItem() |
pid = self.GetRootItem() |
604 |
|
|
605 |
id, cookie = self.GetFirstChild(pid, 123) |
id, cookie = self.GetFirstChild(pid) |
606 |
while id.IsOk(): |
while id.IsOk(): |
607 |
self.__RemoveLayer(id) |
self.__RemoveLayer(id) |
608 |
id, cookie = self.GetNextChild(pid, cookie) |
id, cookie = self.GetNextChild(pid, cookie) |
640 |
self.Delete(id) |
self.Delete(id) |
641 |
|
|
642 |
def DeleteChildren(self, pid): |
def DeleteChildren(self, pid): |
643 |
id, cookie = self.GetFirstChild(pid, 123) |
id, cookie = self.GetFirstChild(pid) |
644 |
while id.IsOk(): |
while id.IsOk(): |
645 |
self.availImgListIndices.append(self.GetItemImage(id)) |
self.availImgListIndices.append(self.GetItemImage(id)) |
646 |
id, cookie = self.GetNextChild(pid, cookie) |
id, cookie = self.GetNextChild(pid, cookie) |
696 |
|
|
697 |
self.__SetVisibilityStyle(visible, parent) |
self.__SetVisibilityStyle(visible, parent) |
698 |
|
|
699 |
id, cookie = self.GetFirstChild(parent, 123) |
id, cookie = self.GetFirstChild(parent) |
700 |
|
|
701 |
while id.IsOk(): |
while id.IsOk(): |
702 |
self.__SetVisibilityStyle(visible, id) |
self.__SetVisibilityStyle(visible, id) |
703 |
id, cookie = self.GetNextChild(parent, cookie) |
id, cookie = self.GetNextChild(parent, cookie) |
704 |
|
|
705 |
|
# In wxPython 2.4 the GetFirstChild method has to be called with a |
706 |
|
# second argument and in 2.5 it must not. Reading the code of |
707 |
|
# wxPython 2.4 it seems that the second parameter was intended to be |
708 |
|
# optional there but due to a bug in the C++ code it doesn't work |
709 |
|
# and omitting the second argument leads to a segfault. To cope |
710 |
|
# with this and to make the code usable with both 2.5 and 2.4 we |
711 |
|
# overwrite the inherited method when running with 2.4 to provide a |
712 |
|
# default value for the second argument. |
713 |
|
if map(int, wxPython.__version__.split(".")[:2]) < [2, 5]: |
714 |
|
def GetFirstChild(self, item): |
715 |
|
return wxTreeCtrl.GetFirstChild(self, item, 0) |
716 |
|
|
717 |
|
|
718 |
class ScaleBarBitmap(wxBoxSizer): |
class ScaleBarBitmap(wxBoxSizer): |
719 |
|
|
720 |
def __init__(self, parent, map, mainWindow): |
def __init__(self, parent, map, mainWindow): |