/[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 1036 by bh, Mon May 26 17:30:29 2003 UTC
# Line 22  from Thuban import _ Line 22  from Thuban import _
22  from base import TitledObject, Modifiable  from base import TitledObject, Modifiable
23  from map import Map  from map import Map
24  from data import ShapefileStore  from data import ShapefileStore
25    from table import DBFTable
26    
27  from transientdb import TransientDatabase  from transientdb import TransientDatabase, AutoTransientTable
28    
29  class AutoRemoveFile:  class AutoRemoveFile:
30    
# Line 194  class Session(TitledObject, Modifiable): Line 195  class Session(TitledObject, Modifiable):
195                                    if store is not weakref]                                    if store is not weakref]
196    
197      def Tables(self):      def Tables(self):
198          """Return a list of all table objects open in the session"""          """Return a list of all table objects open in the session
199          # Tables are only available from shapestores at the moment, so  
200          # we just take them from there          The list includes all tables that are indirectly opened through
201          return [store.Table() for store in self.ShapeStores()]          shape stores and the tables that have been opened explicitly.
202            """
203            return self.tables + [store.Table() for store in self.ShapeStores()]
204    
205        def AddTable(self, table):
206            """Add the table to the session
207    
208            All tables associated with the session that are not implicitly
209            created by the OpenShapefile method (and maybe other Open*
210            methods in the future) have to be passed to this method to make
211            sure the session knows about it. The session keeps a reference
212            to the table. Only tables managed by the session in this way
213            should be used for layers contained in one of the session's
214            maps.
215    
216            The table parameter may be any object implementing the table
217            interface. If it's not already one of the transient tables
218            instantiate an AutoTransientTable with it and use that instead
219            of the original table (note that the AutoTransientTable keeps a
220            reference to the original table).
221    
222            Return the table object actually used by the session.
223            """
224            if not hasattr(table, "transient_table"):
225                transient_table = AutoTransientTable(self.TransientDB(), table)
226            else:
227                transient_table = table
228            self.tables.append(transient_table)
229            return transient_table
230    
231        def RemoveTable(self, table):
232            """Remove the table from the session.
233    
234            The table object must be a table object previously returned by
235            the AddTable method. If the table is not part of the session
236            raise a ValueError.
237            """
238            tables = [t for t in self.tables if t is not table]
239            if len(tables) == len(self.tables):
240                raise ValueError
241            self.tables = tables
242    
243        def OpenTableFile(self, filename):
244            """Open the table file filename and return the table object.
245    
246            The filename argument must be the name of a DBF file.
247            """
248            return self.AddTable(DBFTable(filename))
249    
250      def temp_directory(self):      def temp_directory(self):
251          """          """
# Line 218  class Session(TitledObject, Modifiable): Line 266  class Session(TitledObject, Modifiable):
266          self._add_shapestore(store)          self._add_shapestore(store)
267          return store          return store
268    
269        def AddShapeStore(self, shapestore):
270            """Add the shapestore to the session.
271    
272            The session only holds a weak reference to the shapestore, so it
273            will automatically be removed from the session when the last
274            reference goes away.
275            """
276            self._add_shapestore(shapestore)
277            return shapestore
278    
279      def TransientDB(self):      def TransientDB(self):
280          if self.transient_db is None:          if self.transient_db is None:
281              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.1036

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26