12 |
|
|
13 |
from messages import MAPS_CHANGED, EXTENSIONS_CHANGED, FILENAME_CHANGED, \ |
from messages import MAPS_CHANGED, EXTENSIONS_CHANGED, FILENAME_CHANGED, \ |
14 |
LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \ |
LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \ |
15 |
LAYER_LEGEND_CHANGED, LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \ |
LAYER_LEGEND_CHANGED, LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED,\ |
16 |
EXTENSION_CHANGED, EXTENSION_OBJECTS_CHANGED |
EXTENSION_CHANGED, EXTENSION_OBJECTS_CHANGED, CHANGED |
17 |
|
|
18 |
from base import TitledObject, Modifiable |
from base import TitledObject, Modifiable |
19 |
|
|
39 |
LAYERS_CHANGED -- Same as the map's event of the same name. |
LAYERS_CHANGED -- Same as the map's event of the same name. |
40 |
It's simply resent from the session to make |
It's simply resent from the session to make |
41 |
subscriptions easier. |
subscriptions easier. |
42 |
|
|
43 |
|
CHANGED -- Generic changed event. Parameters: the session. The |
44 |
|
event is always issued when any other changed event |
45 |
|
is issused. This is useful for code that needs to be |
46 |
|
notified whenever something in the session has |
47 |
|
changed but it's too cumbersome or error-prone to |
48 |
|
subscribe to all the individual events. |
49 |
""" |
""" |
50 |
|
|
51 |
# message channels that have to be forwarded from maps contained in |
# message channels that have to be forwarded from maps contained in |
52 |
# the session. |
# the session. |
53 |
forwarded_channels = ( |
forwarded_channels = ( |
54 |
|
# generic channels |
55 |
|
CHANGED, |
56 |
|
|
57 |
# map specific channels |
# map specific channels |
58 |
MAP_PROJECTION_CHANGED, |
MAP_PROJECTION_CHANGED, |
59 |
LAYERS_CHANGED, |
LAYERS_CHANGED, |
75 |
self.tables = [] |
self.tables = [] |
76 |
self.extensions = [] |
self.extensions = [] |
77 |
|
|
78 |
|
def changed(self, channel = None, *args): |
79 |
|
"""Like the inherited version but issue a CHANGED message as well. |
80 |
|
|
81 |
|
The CHANGED message is only issued if channel given is a |
82 |
|
different channel than CHANGED. |
83 |
|
""" |
84 |
|
Modifiable.changed(self, channel, *args) |
85 |
|
if channel != CHANGED: |
86 |
|
self.issue(CHANGED, self) |
87 |
|
|
88 |
def SetFilename(self, filename): |
def SetFilename(self, filename): |
89 |
self.filename = filename |
self.filename = filename |
90 |
self.changed(FILENAME_CHANGED) |
self.changed(FILENAME_CHANGED) |
101 |
map.Subscribe(channel, self.forward, channel) |
map.Subscribe(channel, self.forward, channel) |
102 |
self.changed(MAPS_CHANGED) |
self.changed(MAPS_CHANGED) |
103 |
|
|
104 |
|
def RemoveMap(self, map): |
105 |
|
for channel in self.forwarded_channels: |
106 |
|
map.Unsubscribe(channel, self.forward, channel) |
107 |
|
self.maps.remove(map) |
108 |
|
self.changed(MAPS_CHANGED) |
109 |
|
map.Destroy() |
110 |
|
|
111 |
def Extensions(self): |
def Extensions(self): |
112 |
return self.extensions |
return self.extensions |
113 |
|
|
125 |
map.Destroy() |
map.Destroy() |
126 |
self.maps = [] |
self.maps = [] |
127 |
self.tables = [] |
self.tables = [] |
128 |
Publisher.Destroy(self) |
Modifiable.Destroy(self) |
129 |
|
|
130 |
def forward(self, *args): |
def forward(self, *args): |
131 |
"""Reissue events""" |
"""Reissue events. |
132 |
|
|
133 |
|
If the channel the event is forwarded to is a changed-channel |
134 |
|
that is not the CHANGED channel issue CHANGED as well. An |
135 |
|
channel is considered to be a changed-channel if it's name ends |
136 |
|
with 'CHANGED'. |
137 |
|
""" |
138 |
if len(args) > 1: |
if len(args) > 1: |
139 |
args = (args[-1],) + args[:-1] |
args = (args[-1],) + args[:-1] |
140 |
apply(self.issue, args) |
apply(self.issue, args) |
141 |
|
channel = args[0] |
142 |
|
# It's a bit of a kludge to rely on the channel name for this. |
143 |
|
if channel.endswith("CHANGED") and channel != CHANGED: |
144 |
|
self.issue(CHANGED, self) |
145 |
|
|
146 |
def WasModified(self): |
def WasModified(self): |
147 |
"""Return true if the session or one of the maps was modified""" |
"""Return true if the session or one of the maps was modified""" |
159 |
for map in self.maps: |
for map in self.maps: |
160 |
map.UnsetModified() |
map.UnsetModified() |
161 |
|
|
162 |
|
def TreeInfo(self): |
163 |
|
items = [] |
164 |
|
if self.filename is None: |
165 |
|
items.append("Filename:") |
166 |
|
else: |
167 |
|
items.append("Filename: %s" % self.filename) |
168 |
|
|
169 |
|
if self.WasModified(): |
170 |
|
items.append("Modified") |
171 |
|
else: |
172 |
|
items.append("Unmodified") |
173 |
|
|
174 |
|
items.extend(self.maps) |
175 |
|
items.extend(self.extensions) |
176 |
|
|
177 |
|
return ("Session: %s" % self.title, items) |
178 |
|
|
179 |
|
|
180 |
def create_empty_session(): |
def create_empty_session(): |