/[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 6 - (hide annotations)
Tue Aug 28 15:41:52 2001 UTC (23 years, 6 months ago) by bh
Original Path: trunk/thuban/Thuban/Model/session.py
File MIME type: text/x-python
File size: 2843 byte(s)
import all the source files

1 bh 6 # Copyright (c) 2001 by Intevation GmbH
2     # 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     from messages import MAPS_CHANGED, LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \
13     LAYER_LEGEND_CHANGED, FILENAME_CHANGED
14    
15     from base import TitledObject, Modifiable
16    
17     from map import Map
18    
19    
20     class Session(TitledObject, Modifiable):
21    
22     """A complete session.
23    
24     A Session consists of arbitrary numbers of maps and tables
25    
26     Session objects send the following events:
27    
28     TITLE_CHANGED -- The title has changed. Parameters: the session.
29    
30     FILENAME_CHANGED -- The filename has changed. No parameters.
31    
32     MAPS_CHANGED -- Maps were added, removed.
33    
34     LAYERS_CHANGED -- Same as the map's event of the same name.
35     It's simply resent from the session to make
36     subscriptions easier.
37     """
38    
39     def __init__(self, title):
40     TitledObject.__init__(self, title)
41     Modifiable.__init__(self)
42     self.filename = None
43     self.maps = []
44     self.tables = []
45    
46     def SetFilename(self, filename):
47     self.filename = filename
48     self.changed(FILENAME_CHANGED)
49    
50     def Maps(self):
51     return self.maps
52    
53     def HasMaps(self):
54     return len(self.maps) > 0
55    
56     def AddMap(self, map):
57     self.maps.append(map)
58     for channel in (LAYERS_CHANGED, MAP_PROJECTION_CHANGED,
59     LAYER_LEGEND_CHANGED):
60     map.Subscribe(channel, self.forward, channel)
61     self.changed(MAPS_CHANGED)
62    
63     def Destroy(self):
64     for map in self.maps:
65     map.Destroy()
66     self.maps = []
67     self.tables = []
68     Publisher.Destroy(self)
69    
70     def forward(self, *args):
71     """Reissue events"""
72     if len(args) > 1:
73     args = (args[-1],) + args[:-1]
74     apply(self.issue, args)
75    
76     def WasModified(self):
77     """Return true if the session or one of the maps was modified"""
78     if self.modified:
79     return 1
80     else:
81     for map in self.maps:
82     if map.WasModified():
83     return 1
84     return 0
85    
86     def UnsetModified(self):
87     """Unset the modified flag of the session and the maps"""
88     print "Session.UnsetModified: entry", self.modified
89     Modifiable.UnsetModified(self)
90     for map in self.maps:
91     map.UnsetModified()
92     print "Session.UnsetModified: exit", self.modified
93    
94    
95    
96     def create_empty_session():
97     """Return an empty session useful as a starting point"""
98     session = Session('unnamed session')
99     session.SetFilename('unnamed.session')
100     session.AddMap(Map('unnamed map'))
101     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