frank: thuban/Thuban/UI altpathdialog.py, NONE, 1.1 application.py, 1.37, 1.38
cvs@intevation.de
cvs at intevation.de
Mon Dec 13 12:52:36 CET 2004
Author: frank
Update of /thubanrepository/thuban/Thuban/UI
In directory doto:/tmp/cvs-serv6169/Thuban/UI
Modified Files:
application.py
Added Files:
altpathdialog.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).
--- NEW FILE: altpathdialog.py ---
# Copyright (c) 2004 by Intevation GmbH
# Authors:
# Frank Koormann <frank at intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.
"""Dialogs for alternative paths (path recovery).
AltPathFileDialog: File dialog to specify alterative path.
AltPathConfirmDialog: Confirm or cancel alternative path suggestion.
"""
from Thuban import _
from wxPython.wx import wxFileDialog, wxMessageDialog, wxOPEN, \
wxYES_NO, wxYES_DEFAULT, wxICON_INFORMATION, \
wxID_OK, wxID_YES
import os
class AltPathFileDialog(wxFileDialog):
def __init__(self, filename):
msg = _("Select an alternative data file for %s" % \
os.path.basename(filename))
wxFileDialog.__init__(self, None,
msg,
os.path.dirname(filename),
os.path.basename(filename),
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" +
_("All Files (*.*)") + "|*.*",
wxOPEN)
def RunDialog(self):
val = self.ShowModal()
self.Destroy()
if val == wxID_OK:
return self.GetPaths()[0]
else:
return None
class AltPathConfirmDialog(wxMessageDialog):
def __init__(self, filename):
self.filename = filename
msg = _("Found the following as an alternative for %s.\n%s\n\n Please confirm with Yes or select alternative with No." % (os.path.basename(filename), filename))
wxMessageDialog.__init__(self, None, msg, _("Alternative Path"),
wxYES_NO|wxYES_DEFAULT|wxICON_INFORMATION)
def RunDialog(self):
val = self.ShowModal()
self.Destroy()
if val == wxID_YES:
return self.filename
else:
dlg = AltPathFileDialog(self.filename)
fname = dlg.RunDialog()
return fname
Index: application.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/application.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- application.py 19 Feb 2004 15:19:39 -0000 1.37
+++ application.py 13 Dec 2004 11:52:34 -0000 1.38
@@ -34,6 +34,7 @@
import tree
import mainwindow
import dbdialog
+import altpathdialog
import exceptiondialog
from messages import SESSION_REPLACED
@@ -59,7 +60,7 @@
# from the application.
# Defaults for the directories used in file dialogs
- self.path={"data":".", "projection":"."}
+ self.path={"data":".", "projection":".", "alt_path":""}
self.session = None
self.top = None
@@ -217,7 +218,8 @@
"""
self.SetSession(create_empty_session())
- def OpenSession(self, filename, db_connection_callback = None):
+ def OpenSession(self, filename, db_connection_callback = None,
+ shapefile_callback = None):
"""Open the session in the file named filename"""
# Make sure we deal with an absolute pathname. Otherwise we can
# get problems when saving because the saving code expects an
@@ -225,9 +227,12 @@
filename = os.path.abspath(filename)
if db_connection_callback is None:
db_connection_callback = self.run_db_param_dialog
+ if shapefile_callback is None:
+ shapefile_callback = self.run_alt_path_dialog
try:
session = load_session(filename,
- db_connection_callback=db_connection_callback)
+ db_connection_callback=db_connection_callback,
+ shapefile_callback=shapefile_callback)
except LoadCancelled:
return
session.SetFilename(filename)
@@ -255,6 +260,54 @@
dlg = dbdialog.DBDialog(None, _("DB Connection Parameters"),
parameters, message)
return dlg.RunDialog()
+
+ # run_alt_path_dialog: Raise a dialog to ask for an alternative path
+ # if the shapefile couldn't be found.
+ # TODO:
+ # - Store a list of already used alternative paths and return these
+ # iteratively (using a generator)
+ # - How do we interact with the user to tell him we used a different
+ # shapefile (location), mode "check"? The current approach with the
+ # file dialog is not that comfortable.
+ #
+ def run_alt_path_dialog(self, filename, mode = None, second_try = 0):
+ """Implemetation of the shapefile_callback while loading sessions.
+
+ This implements two modes:
+ - search: Search for an alternative path. If available from a
+ list of alrady known paths, else interactivly by file dialog.
+ Currently the "second_try" is important since else the user might
+ be caught in a loop.
+ - check: Ask the user for confirmation, if a path from list has
+ been found successful.
+
+ Returns:
+ - fname: The full path to the (shape) file.
+ - from_list: Flags if the path was taken from list or entered
+ manually.
+ """
+
+ if mode == "search":
+ if self.Path('alt_path') == "" or second_try:
+ dlg = altpathdialog.AltPathFileDialog(filename)
+ fname = dlg.RunDialog()
+ if fname is not None:
+ self.SetPath('alt_path', fname)
+ from_list = 0
+ else:
+ fname = os.path.join(self.Path('alt_path'),
+ os.path.basename(filename))
+ from_list = 1
+ elif mode == "check":
+ dlg = altpathdialog.AltPathConfirmDialog(filename)
+ fname = dlg.RunDialog()
+ if fname is not None:
+ self.SetPath('alt_path', fname)
+ from_list = 0
+ else:
+ fname = None
+ from_list = 0
+ return fname, from_list
def SaveSession(self):
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)