/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/session.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/Model/session.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (hide annotations)
Fri May 3 14:38:16 2002 UTC (22 years, 10 months ago) by bh
Original Path: trunk/thuban/Thuban/Model/session.py
File MIME type: text/x-python
File size: 3107 byte(s)
	* Thuban/Model/session.py (Session.AddMap, forwarded_channels):
	Move the map channels to be forwarded by the session into the
	class constant with forwarded_channels.

1 bh 128 # Copyright (c) 2001, 2002 by Intevation GmbH
2 bh 6 # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     __version__ = "$Revision$"
9    
10     from Thuban.Lib.connector import Publisher
11    
12 bh 128 from messages import MAPS_CHANGED, FILENAME_CHANGED, \
13     LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \
14     LAYER_LEGEND_CHANGED, LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED
15 bh 6
16     from base import TitledObject, Modifiable
17    
18     from map import Map
19    
20    
21     class Session(TitledObject, Modifiable):
22    
23     """A complete session.
24    
25     A Session consists of arbitrary numbers of maps and tables
26    
27     Session objects send the following events:
28    
29     TITLE_CHANGED -- The title has changed. Parameters: the session.
30    
31     FILENAME_CHANGED -- The filename has changed. No parameters.
32    
33     MAPS_CHANGED -- Maps were added, removed.
34    
35     LAYERS_CHANGED -- Same as the map's event of the same name.
36     It's simply resent from the session to make
37     subscriptions easier.
38     """
39    
40 bh 128 # message channels that have to be forwarded from maps contained in
41     # the session.
42     forwarded_channels = (
43     # map specific channels
44     MAP_PROJECTION_CHANGED,
45     LAYERS_CHANGED,
46    
47     # layer channels forwarded by the map
48     LAYER_PROJECTION_CHANGED,
49     LAYER_LEGEND_CHANGED,
50     LAYER_VISIBILITY_CHANGED)
51    
52 bh 6 def __init__(self, title):
53     TitledObject.__init__(self, title)
54     Modifiable.__init__(self)
55     self.filename = None
56     self.maps = []
57     self.tables = []
58    
59     def SetFilename(self, filename):
60     self.filename = filename
61     self.changed(FILENAME_CHANGED)
62    
63     def Maps(self):
64     return self.maps
65    
66     def HasMaps(self):
67     return len(self.maps) > 0
68    
69     def AddMap(self, map):
70     self.maps.append(map)
71 bh 128 for channel in self.forwarded_channels:
72 bh 6 map.Subscribe(channel, self.forward, channel)
73     self.changed(MAPS_CHANGED)
74    
75     def Destroy(self):
76     for map in self.maps:
77     map.Destroy()
78     self.maps = []
79     self.tables = []
80     Publisher.Destroy(self)
81    
82     def forward(self, *args):
83     """Reissue events"""
84     if len(args) > 1:
85     args = (args[-1],) + args[:-1]
86     apply(self.issue, args)
87    
88     def WasModified(self):
89     """Return true if the session or one of the maps was modified"""
90     if self.modified:
91     return 1
92     else:
93     for map in self.maps:
94     if map.WasModified():
95     return 1
96     return 0
97    
98     def UnsetModified(self):
99     """Unset the modified flag of the session and the maps"""
100     Modifiable.UnsetModified(self)
101     for map in self.maps:
102     map.UnsetModified()
103    
104    
105    
106     def create_empty_session():
107     """Return an empty session useful as a starting point"""
108 jan 103 import os
109 bh 6 session = Session('unnamed session')
110 jan 103 session.SetFilename(None)
111 bh 6 session.AddMap(Map('unnamed map'))
112 bh 56 session.UnsetModified()
113 bh 6 return session

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26