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, AutoTransientTable |
from transientdb import TransientDatabase, AutoTransientTable |
29 |
|
|
203 |
""" |
""" |
204 |
return self.tables + [store.Table() for store in self.ShapeStores()] |
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): |
def AddTable(self, table): |
217 |
"""Add the table to the session |
"""Add the table to the session |
218 |
|
|
239 |
self.tables.append(transient_table) |
self.tables.append(transient_table) |
240 |
return transient_table |
return transient_table |
241 |
|
|
242 |
|
def RemoveTable(self, table): |
243 |
|
"""Remove the table from the session. |
244 |
|
|
245 |
|
The table object must be a table object previously returned by |
246 |
|
the AddTable method. If the table is not part of the session |
247 |
|
raise a ValueError. |
248 |
|
|
249 |
|
Issue a TABLE_REMOVED message after the table has been removed. |
250 |
|
The message has the removed table as the single parameter. |
251 |
|
""" |
252 |
|
tables = [t for t in self.tables if t is not table] |
253 |
|
if len(tables) == len(self.tables): |
254 |
|
raise ValueError |
255 |
|
self.tables = tables |
256 |
|
self.changed(TABLE_REMOVED, table) |
257 |
|
|
258 |
|
def OpenTableFile(self, filename): |
259 |
|
"""Open the table file filename and return the table object. |
260 |
|
|
261 |
|
The filename argument must be the name of a DBF file. |
262 |
|
""" |
263 |
|
return self.AddTable(DBFTable(filename)) |
264 |
|
|
265 |
def temp_directory(self): |
def temp_directory(self): |
266 |
""" |
""" |
267 |
Return the name of the directory for session specific temporary files |
Return the name of the directory for session specific temporary files |
281 |
self._add_shapestore(store) |
self._add_shapestore(store) |
282 |
return store |
return store |
283 |
|
|
284 |
|
def AddShapeStore(self, shapestore): |
285 |
|
"""Add the shapestore to the session. |
286 |
|
|
287 |
|
The session only holds a weak reference to the shapestore, so it |
288 |
|
will automatically be removed from the session when the last |
289 |
|
reference goes away. |
290 |
|
""" |
291 |
|
self._add_shapestore(shapestore) |
292 |
|
return shapestore |
293 |
|
|
294 |
def TransientDB(self): |
def TransientDB(self): |
295 |
if self.transient_db is None: |
if self.transient_db is None: |
296 |
filename = os.path.join(self.temp_directory(), "transientdb") |
filename = os.path.join(self.temp_directory(), "transientdb") |