23 |
from map import Map |
from map import Map |
24 |
from data import ShapefileStore |
from data import ShapefileStore |
25 |
|
|
26 |
from transientdb import TransientDatabase |
from transientdb import TransientDatabase, AutoTransientTable |
27 |
|
|
28 |
class AutoRemoveFile: |
class AutoRemoveFile: |
29 |
|
|
194 |
if store is not weakref] |
if store is not weakref] |
195 |
|
|
196 |
def Tables(self): |
def Tables(self): |
197 |
"""Return a list of all table objects open in the session""" |
"""Return a list of all table objects open in the session |
198 |
# Tables are only available from shapestores at the moment, so |
|
199 |
# we just take them from there |
The list includes all tables that are indirectly opened through |
200 |
return [store.Table() for store in self.ShapeStores()] |
shape stores and the tables that have been opened explicitly. |
201 |
|
""" |
202 |
|
return self.tables + [store.Table() for store in self.ShapeStores()] |
203 |
|
|
204 |
|
def AddTable(self, table): |
205 |
|
"""Add the table to the session |
206 |
|
|
207 |
|
All tables associated with the session that are not implicitly |
208 |
|
created by the OpenShapefile method (and maybe other Open* |
209 |
|
methods in the future) have to be passed to this method to make |
210 |
|
sure the session knows about it. The session keeps a reference |
211 |
|
to the table. Only tables managed by the session in this way |
212 |
|
should be used for layers contained in one of the session's |
213 |
|
maps. |
214 |
|
|
215 |
|
The table parameter may be any object implementing the table |
216 |
|
interface. If it's not already one of the transient tables |
217 |
|
instantiate an AutoTransientTable with it and use that instead |
218 |
|
of the original table (note that the AutoTransientTable keeps a |
219 |
|
reference to the original table). |
220 |
|
|
221 |
|
Return the table object actually used by the session. |
222 |
|
""" |
223 |
|
if not hasattr(table, "transient_table"): |
224 |
|
transient_table = AutoTransientTable(self.TransientDB(), table) |
225 |
|
else: |
226 |
|
transient_table = table |
227 |
|
self.tables.append(transient_table) |
228 |
|
return transient_table |
229 |
|
|
230 |
|
def RemoveTable(self, table): |
231 |
|
"""Remove the table from the session. |
232 |
|
|
233 |
|
The table object must be a table object previously returned by |
234 |
|
the AddTable method. If the table is not part of the session |
235 |
|
raise a ValueError. |
236 |
|
""" |
237 |
|
tables = [t for t in self.tables if t is not table] |
238 |
|
if len(tables) == len(self.tables): |
239 |
|
raise ValueError |
240 |
|
self.tables = tables |
241 |
|
|
242 |
def temp_directory(self): |
def temp_directory(self): |
243 |
""" |
""" |