frank: thuban/Thuban/Model load.py,1.49,1.50
cvs@intevation.de
cvs at intevation.de
Mon Dec 13 12:52:36 CET 2004
Author: frank
Update of /thubanrepository/thuban/Thuban/Model
In directory doto:/tmp/cvs-serv6169/Thuban/Model
Modified Files:
load.py
Log Message:
Alternative Path feature:
* test/test_load.py (TestAltPath): New, tests for alternative path feature
in load_session()
(Shapefile_CallBack): Helper, implements controllable callback.
* Thuban/UI/application.py (ThubanApplication.OnInit):
Added "alt_path" to self.path
(ThubanApplication.OpenSession): Added shapefile_callback as second
callback similar to db_connection_callback.
(ThubanApplication.run_alt_path_dialog): New, implementaion of
shapefile_callback. In addition to raising the dialog the control of
self.path('alt_path') is implemented here.
* Thuban/Model/load.py (SessionLoader.__init__): Added shapefile_callback.
(SessionLoader.open_shapefile): Open shapefile, eventually with
alternative path. This wrapps the "theSession.OpenShapefile(filename)"
formerly used in start_fileshapesource()/start_layer().
(SessionLoader.start_fileshapesource): Call open_shapefile().
(SessionLoader.start_layer): Call open_shapefile().
(load_session): Added shapefile_callback.
* Thuban/UI/altpathdialog.py: New, implements dialogs for alternative path
feature (search / check).
Index: load.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/load.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- load.py 3 Oct 2004 21:05:30 -0000 1.49
+++ load.py 13 Dec 2004 11:52:34 -0000 1.50
@@ -3,6 +3,7 @@
# Jan-Oliver Wagner <jan at intevation.de>
# Bernhard Herzog <bh at intevation.de>
# Jonathan Coles <jonathan at intevation.de>
+# Frank Koormann <frank at intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with GRASS for details.
@@ -100,12 +101,13 @@
class SessionLoader(XMLReader):
- def __init__(self, db_connection_callback = None):
+ def __init__(self, db_connection_callback = None,
+ shapefile_callback = None):
"""Inititialize the Sax handler."""
XMLReader.__init__(self)
self.db_connection_callback = db_connection_callback
-
+ self.shapefile_callback = shapefile_callback
self.theSession = None
self.aMap = None
self.aLayer = None
@@ -258,6 +260,41 @@
normalized[d.name] = value
return normalized
+ def open_shapefile(self, filename):
+ """Open shapefile, eventually with alternative path."""
+ from_list = 0
+ while 1:
+ try:
+ store = self.theSession.OpenShapefile(filename)
+ if from_list:
+ # The correct? path has been guessed from a list
+ # Let the user confirm - or select an alternative.
+ filename, from_list = self.shapefile_callback(
+ filename, "check")
+ if filename is None:
+ # Selection cancelled
+ raise LoadCancelled
+ elif store.FileName() == filename:
+ # Proposed file has been accepted
+ break
+ else:
+ # the filename has been changed, try the new file
+ pass
+ else:
+ break
+ except IOError:
+ if self.shapefile_callback is not None:
+ filename, from_list = self.shapefile_callback(
+ filename,
+ mode = "search",
+ second_try = from_list)
+ if filename is None:
+ raise LoadCancelled
+ print filename
+ else:
+ raise
+ return store
+
def start_dbconnection(self, name, qname, attrs):
attrs = self.check_attrs(name, attrs,
[AttrDesc("id", True),
@@ -333,7 +370,7 @@
filetype = attrs["filetype"]
if filetype != "shapefile":
raise LoadError("shapesource filetype %r not supported" % filetype)
- self.idmap[ID] = self.theSession.OpenShapefile(filename)
+ self.idmap[ID] = self.open_shapefile(filename)
def start_derivedshapesource(self, name, qname, attrs):
attrs = self.check_attrs(name, attrs,
@@ -444,7 +481,8 @@
if attrs.has_key((None, "shapestore")):
store = self.idmap[attrs[(None, "shapestore")]]
else:
- store = self.theSession.OpenShapefile(filename)
+ store = self.open_shapefile(filename)
+
self.aLayer = layer_class(title, store,
fill = fill, stroke = stroke,
lineWidth = stroke_width,
@@ -587,7 +625,8 @@
pass
-def load_session(filename, db_connection_callback = None):
+def load_session(filename, db_connection_callback = None,
+ shapefile_callback = None):
"""Load a Thuban session from the file object file
The db_connection_callback, if given should be a callable object
@@ -600,7 +639,7 @@
corrected and perhaps additional parameters like a password or None
to indicate that the user cancelled.
"""
- handler = SessionLoader(db_connection_callback)
+ handler = SessionLoader(db_connection_callback, shapefile_callback)
handler.read(filename)
session = handler.theSession
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)