1 |
#! /usr/bin/python |
#! /usr/bin/python |
2 |
# Copyright (c) 2001 by Intevation GmbH |
# Copyright (c) 2001, 2002 by Intevation GmbH |
3 |
# Authors: |
# Authors: |
4 |
# Jan-Oliver Wagner <[email protected]> |
# Jan-Oliver Wagner <[email protected]> |
5 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
12 |
from wxPython.wx import * |
from wxPython.wx import * |
13 |
|
|
14 |
from Thuban.Model.messages import MAPS_CHANGED, MAP_PROJECTION_CHANGED, \ |
from Thuban.Model.messages import MAPS_CHANGED, MAP_PROJECTION_CHANGED, \ |
15 |
LAYERS_CHANGED, LAYER_LEGEND_CHANGED, LAYER_VISIBILITY_CHANGED |
LAYERS_CHANGED, LAYER_LEGEND_CHANGED, LAYER_VISIBILITY_CHANGED, \ |
16 |
|
EXTENSIONS_CHANGED, EXTENSION_OBJECTS_CHANGED |
17 |
from Thuban.Model.layer import Layer, shapetype_names |
from Thuban.Model.layer import Layer, shapetype_names |
18 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
19 |
|
|
28 |
|
|
29 |
class SessionTreeCtrl(wxTreeCtrl): |
class SessionTreeCtrl(wxTreeCtrl): |
30 |
|
|
31 |
|
# the session channels to subscribe to update the tree |
32 |
|
session_channels = (MAPS_CHANGED, MAP_PROJECTION_CHANGED, |
33 |
|
LAYERS_CHANGED, LAYER_LEGEND_CHANGED, |
34 |
|
LAYER_VISIBILITY_CHANGED, EXTENSIONS_CHANGED, |
35 |
|
EXTENSION_OBJECTS_CHANGED) |
36 |
|
|
37 |
def __init__(self, parent, ID, app): |
def __init__(self, parent, ID, app): |
38 |
# Use the WANTS_CHARS style so the panel doesn't eat the Return key. |
# Use the WANTS_CHARS style so the panel doesn't eat the Return key. |
39 |
wxTreeCtrl.__init__(self, parent, ID) |
wxTreeCtrl.__init__(self, parent, ID) |
48 |
|
|
49 |
self.app.Subscribe(SESSION_CHANGED, self.session_changed) |
self.app.Subscribe(SESSION_CHANGED, self.session_changed) |
50 |
self.app.interactor.Subscribe(SELECTED_LAYER, self.layer_selected) |
self.app.interactor.Subscribe(SELECTED_LAYER, self.layer_selected) |
51 |
|
|
52 |
|
# the session currently displayed in the tree |
53 |
|
self.session = None |
54 |
|
|
55 |
# pretend the session has changed to build the initial tree |
# pretend the session has changed to build the initial tree |
56 |
self.session_changed() |
self.session_changed() |
57 |
|
|
58 |
EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged) |
EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged) |
59 |
|
|
60 |
|
def unsubscribe_all(self): |
61 |
|
if self.session is not None: |
62 |
|
for channel in self.session_channels: |
63 |
|
self.session.Unsubscribe(channel, self.update_tree) |
64 |
|
self.session = None |
65 |
|
self.app.Unsubscribe(SESSION_CHANGED, self.session_changed) |
66 |
|
self.app.interactor.Unsubscribe(SELECTED_LAYER, self.layer_selected) |
67 |
|
|
68 |
def update_tree(self, *args): |
def update_tree(self, *args): |
69 |
"""Clear and rebuild the tree""" |
"""Clear and rebuild the tree""" |
70 |
self.DeleteAllItems() |
self.DeleteAllItems() |
113 |
text = "Hidden" |
text = "Hidden" |
114 |
self.AppendItem(layeritem, text) |
self.AppendItem(layeritem, text) |
115 |
self.AppendItem(layeritem, "Shapes: %d" %layer.NumShapes()) |
self.AppendItem(layeritem, "Shapes: %d" %layer.NumShapes()) |
116 |
self.AppendItem(layeritem, |
bbox = layer.LatLongBoundingBox() |
117 |
("Extent (lat-lon): (%g, %g, %g, %g)" |
if bbox is not None: |
118 |
% layer.LatLongBoundingBox())) |
self.AppendItem(layeritem, |
119 |
|
("Extent (lat-lon): (%g, %g, %g, %g)" |
120 |
|
% bbox)) |
121 |
|
else: |
122 |
|
self.AppendItem(layeritem, ("Extent (lat-lon):")) |
123 |
self.AppendItem(layeritem, |
self.AppendItem(layeritem, |
124 |
"Shapetype: %s" |
"Shapetype: %s" |
125 |
% shapetype_names[layer.ShapeType()]) |
% shapetype_names[layer.ShapeType()]) |
131 |
self.Expand(mapitem) |
self.Expand(mapitem) |
132 |
self.Expand(root) |
self.Expand(root) |
133 |
|
|
134 |
|
for extension in session.Extensions(): |
135 |
|
extensionitem = self.AppendItem(root, "Extension: %s" % |
136 |
|
extension.title) |
137 |
|
for object in extension.Objects(): |
138 |
|
objectitem = self.AppendItem(extensionitem, "%s: %s" % |
139 |
|
(object.title, object.name)) |
140 |
|
self.Expand(extensionitem) |
141 |
|
|
142 |
|
|
143 |
def session_changed(self, *args): |
def session_changed(self, *args): |
144 |
for channel in (MAPS_CHANGED, |
new_session = self.app.session |
145 |
MAP_PROJECTION_CHANGED, |
# if the session has changed subscribe/unsubscribe |
146 |
LAYERS_CHANGED, |
if self.session is not new_session: |
147 |
LAYER_LEGEND_CHANGED, |
if self.session is not None: |
148 |
LAYER_VISIBILITY_CHANGED): |
for channel in self.session_channels: |
149 |
self.app.session.Subscribe(channel, self.update_tree) |
self.session.Unsubscribe(channel, self.update_tree) |
150 |
|
if new_session is not None: |
151 |
|
for channel in self.session_channels: |
152 |
|
new_session.Subscribe(channel, self.update_tree) |
153 |
|
self.session = new_session |
154 |
self.update_tree() |
self.update_tree() |
155 |
|
|
156 |
def normalize_selection(self): |
def normalize_selection(self): |
205 |
#self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape) |
#self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape) |
206 |
NonModalDialog.OnClose(self, event) |
NonModalDialog.OnClose(self, event) |
207 |
|
|
208 |
|
# if there were a way to get notified when the tree control |
209 |
|
# itself is destroyed we could use that to unsubscribe instead |
210 |
|
# of doing it here. (EVT_WINDOW_DESTROY doesn't seem to sent at |
211 |
|
# all) |
212 |
|
self.tree.unsubscribe_all() |