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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 217 by bh, Wed Jul 17 10:50:40 2002 UTC revision 374 by jan, Mon Jan 27 14:20:02 2003 UTC
# Line 12  from Thuban.Lib.connector import Publish Line 12  from Thuban.Lib.connector import Publish
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 Thuban import _
19    
20  from base import TitledObject, Modifiable  from base import TitledObject, Modifiable
21    
# Line 39  class Session(TitledObject, Modifiable): Line 41  class Session(TitledObject, Modifiable):
41          LAYERS_CHANGED -- Same as the map's event of the same name.          LAYERS_CHANGED -- Same as the map's event of the same name.
42                            It's simply resent from the session to make                            It's simply resent from the session to make
43                            subscriptions easier.                            subscriptions easier.
44    
45            CHANGED -- Generic changed event. Parameters: the session. The
46                       event is always issued when any other changed event
47                       is issused. This is useful for code that needs to be
48                       notified whenever something in the session has
49                       changed but it's too cumbersome or error-prone to
50                       subscribe to all the individual events.
51      """      """
52    
53      # message channels that have to be forwarded from maps contained in      # message channels that have to be forwarded from maps contained in
54      # the session.      # the session.
55      forwarded_channels = (      forwarded_channels = (
56            # generic channels
57            CHANGED,
58    
59          # map specific channels          # map specific channels
60          MAP_PROJECTION_CHANGED,          MAP_PROJECTION_CHANGED,
61          LAYERS_CHANGED,          LAYERS_CHANGED,
# Line 65  class Session(TitledObject, Modifiable): Line 77  class Session(TitledObject, Modifiable):
77          self.tables = []          self.tables = []
78          self.extensions = []          self.extensions = []
79    
80        def changed(self, channel = None, *args):
81            """Like the inherited version but issue a CHANGED message as well.
82    
83            The CHANGED message is only issued if channel given is a
84            different channel than CHANGED.
85            """
86            Modifiable.changed(self, channel, *args)
87            if channel != CHANGED:
88                self.issue(CHANGED, self)
89    
90      def SetFilename(self, filename):      def SetFilename(self, filename):
91          self.filename = filename          self.filename = filename
92          self.changed(FILENAME_CHANGED)          self.changed(FILENAME_CHANGED)
# Line 81  class Session(TitledObject, Modifiable): Line 103  class Session(TitledObject, Modifiable):
103              map.Subscribe(channel, self.forward, channel)              map.Subscribe(channel, self.forward, channel)
104          self.changed(MAPS_CHANGED)          self.changed(MAPS_CHANGED)
105    
106        def RemoveMap(self, map):
107            for channel in self.forwarded_channels:
108                map.Unsubscribe(channel, self.forward, channel)
109            self.maps.remove(map)
110            self.changed(MAPS_CHANGED)
111            map.Destroy()
112    
113      def Extensions(self):      def Extensions(self):
114          return self.extensions          return self.extensions
115    
# Line 98  class Session(TitledObject, Modifiable): Line 127  class Session(TitledObject, Modifiable):
127              map.Destroy()              map.Destroy()
128          self.maps = []          self.maps = []
129          self.tables = []          self.tables = []
130          Publisher.Destroy(self)          Modifiable.Destroy(self)
131    
132      def forward(self, *args):      def forward(self, *args):
133          """Reissue events"""          """Reissue events.
134    
135            If the channel the event is forwarded to is a changed-channel
136            that is not the CHANGED channel issue CHANGED as well. An
137            channel is considered to be a changed-channel if it's name ends
138            with 'CHANGED'.
139            """
140          if len(args) > 1:          if len(args) > 1:
141              args = (args[-1],) + args[:-1]              args = (args[-1],) + args[:-1]
142          apply(self.issue, args)          apply(self.issue, args)
143            channel = args[0]
144            # It's a bit of a kludge to rely on the channel name for this.
145            if channel.endswith("CHANGED") and channel != CHANGED:
146                self.issue(CHANGED, self)
147    
148      def WasModified(self):      def WasModified(self):
149          """Return true if the session or one of the maps was modified"""          """Return true if the session or one of the maps was modified"""
# Line 125  class Session(TitledObject, Modifiable): Line 164  class Session(TitledObject, Modifiable):
164      def TreeInfo(self):      def TreeInfo(self):
165          items = []          items = []
166          if self.filename is None:          if self.filename is None:
167              items.append("Filename:")              items.append(_("Filename:"))
168          else:          else:
169              items.append("Filename: %s" % self.filename)              items.append(_("Filename: %s") % self.filename)
170    
171          if self.WasModified():          if self.WasModified():
172              items.append("Modified")              items.append(_("Modified"))
173          else:          else:
174              items.append("Unmodified")              items.append(_("Unmodified"))
175    
176          items.extend(self.maps)          items.extend(self.maps)
177          items.extend(self.extensions)          items.extend(self.extensions)
178    
179          return ("Session: %s" % self.title, items)          return (_("Session: %s") % self.title, items)
180    
181    
182  def create_empty_session():  def create_empty_session():
183      """Return an empty session useful as a starting point"""      """Return an empty session useful as a starting point"""
184      import os      import os
185      session = Session('unnamed session')      session = Session(_('unnamed session'))
186      session.SetFilename(None)      session.SetFilename(None)
187      session.AddMap(Map('unnamed map'))      session.AddMap(Map(_('unnamed map')))
188      session.UnsetModified()      session.UnsetModified()
189      return session      return session

Legend:
Removed from v.217  
changed lines
  Added in v.374

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26