/[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 851 by bh, Wed May 7 15:11:12 2003 UTC revision 1268 by bh, Fri Jun 20 16:10:12 2003 UTC
# Line 15  import weakref Line 15  import weakref
15  from messages import MAPS_CHANGED, EXTENSIONS_CHANGED, FILENAME_CHANGED, \  from messages import MAPS_CHANGED, EXTENSIONS_CHANGED, FILENAME_CHANGED, \
16       MAP_LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \       MAP_LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \
17       LAYER_CHANGED, LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED,\       LAYER_CHANGED, LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED,\
18       EXTENSION_CHANGED, EXTENSION_OBJECTS_CHANGED, CHANGED       EXTENSION_CHANGED, EXTENSION_OBJECTS_CHANGED, CHANGED, \
19         TABLE_REMOVED
20    
21  from Thuban import _  from Thuban import _
22    
23  from base import TitledObject, Modifiable  from base import TitledObject, Modifiable
24  from map import Map  from map import Map
25  from data import ShapefileStore  from data import ShapefileStore
26    from table import DBFTable
27    
28  from transientdb import TransientDatabase  from transientdb import TransientDatabase, AutoTransientTable
29    
30  class AutoRemoveFile:  class AutoRemoveFile:
31    
# Line 194  class Session(TitledObject, Modifiable): Line 196  class Session(TitledObject, Modifiable):
196                                    if store is not weakref]                                    if store is not weakref]
197    
198      def Tables(self):      def Tables(self):
199          """Return a list of all table objects open in the session"""          """Return a list of all table objects open in the session
200          # Tables are only available from shapestores at the moment, so  
201          # we just take them from there          The list includes all tables that are indirectly opened through
202          return [store.Table() for store in self.ShapeStores()]          shape stores and the tables that have been opened explicitly.
203            """
204            return self.tables + [store.Table() for store in self.ShapeStores()]
205    
206        def UnreferencedTables(self):
207            """Return the tables that are not referenced by other data sources"""
208            known = {}
209            for table in self.tables:
210                known[id(table)] = 0
211            for table in self.tables + self.ShapeStores():
212                for dep in table.Dependencies():
213                    known[id(dep)] = 1
214            return [table for table in self.tables if known[id(table)] == 0]
215    
216        def AddTable(self, table):
217            """Add the table to the session
218    
219            All tables associated with the session that are not implicitly
220            created by the OpenShapefile method (and maybe other Open*
221            methods in the future) have to be passed to this method to make
222            sure the session knows about it. The session keeps a reference
223            to the table. Only tables managed by the session in this way
224            should be used for layers contained in one of the session's
225            maps.
226    
227            The table parameter may be any object implementing the table
228            interface. If it's not already one of the transient tables
229            instantiate an AutoTransientTable with it and use that instead
230            of the original table (note that the AutoTransientTable keeps a
231            reference to the original table).
232    
233            Return the table object actually used by the session.
234            """
235            if not hasattr(table, "transient_table"):
236                transient_table = AutoTransientTable(self.TransientDB(), table)
237            else:
238                transient_table = table
239            self.tables.append(transient_table)
240            self.changed()
241            return transient_table
242    
243        def RemoveTable(self, table):
244            """Remove the table from the session.
245    
246            The table object must be a table object previously returned by
247            the AddTable method. If the table is not part of the session
248            raise a ValueError.
249    
250            Issue a TABLE_REMOVED message after the table has been removed.
251            The message has the removed table as the single parameter.
252            """
253            tables = [t for t in self.tables if t is not table]
254            if len(tables) == len(self.tables):
255                raise ValueError
256            self.tables = tables
257            self.changed(TABLE_REMOVED, table)
258    
259        def DataContainers(self):
260            """Return all data containers, i.e. shapestores and tables"""
261            return self.tables + self.ShapeStores()
262    
263        def OpenTableFile(self, filename):
264            """Open the table file filename and return the table object.
265    
266            The filename argument must be the name of a DBF file.
267            """
268            return self.AddTable(DBFTable(filename))
269    
270      def temp_directory(self):      def temp_directory(self):
271          """          """
# Line 218  class Session(TitledObject, Modifiable): Line 286  class Session(TitledObject, Modifiable):
286          self._add_shapestore(store)          self._add_shapestore(store)
287          return store          return store
288    
289        def AddShapeStore(self, shapestore):
290            """Add the shapestore to the session.
291    
292            The session only holds a weak reference to the shapestore, so it
293            will automatically be removed from the session when the last
294            reference goes away.
295            """
296            self._add_shapestore(shapestore)
297            return shapestore
298    
299      def TransientDB(self):      def TransientDB(self):
300          if self.transient_db is None:          if self.transient_db is None:
301              filename = os.path.join(self.temp_directory(), "transientdb")              filename = os.path.join(self.temp_directory(), "transientdb")

Legend:
Removed from v.851  
changed lines
  Added in v.1268

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26