[Greater-commits] r3764 - branches/3.0.0-all-models/greater-pre-processing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 12 11:32:24 CEST 2011


Author: aheinecke
Date: 2011-08-12 11:32:23 +0200 (Fri, 12 Aug 2011)
New Revision: 3764

Modified:
   branches/3.0.0-all-models/greater-pre-processing/ChangeLog
   branches/3.0.0-all-models/greater-pre-processing/upload-catchment.py
Log:
Make upload catchment callable from a shortcut without
having to change the working directory by opening a file
dialog that querys for the catchment description


Modified: branches/3.0.0-all-models/greater-pre-processing/ChangeLog
===================================================================
--- branches/3.0.0-all-models/greater-pre-processing/ChangeLog	2011-08-02 11:39:54 UTC (rev 3763)
+++ branches/3.0.0-all-models/greater-pre-processing/ChangeLog	2011-08-12 09:32:23 UTC (rev 3764)
@@ -1,3 +1,8 @@
+2011-08-12  Andre Heinecke <aheinecke at intevation.de>
+
+	* upload-catchment.py: - Remove oracle option from the wizzard
+	- Make the catchment directory selectable
+
 2007-06-06  Frank Koormann     <frank.koormann at intevation.de>
 
 	* doc/greater-preprocessing-manual.tex, doc/howto.tex, doc/sourcefiles.tex:

Modified: branches/3.0.0-all-models/greater-pre-processing/upload-catchment.py
===================================================================
--- branches/3.0.0-all-models/greater-pre-processing/upload-catchment.py	2011-08-02 11:39:54 UTC (rev 3763)
+++ branches/3.0.0-all-models/greater-pre-processing/upload-catchment.py	2011-08-12 09:32:23 UTC (rev 3764)
@@ -74,7 +74,7 @@
         return 0.0
 
 def read_catchment_desc(verbose=True):
-    """Read the file 'catchment.desc' in the current directory
+    """Look for catchment_desc and read it
 
     In case of errors exceptions will be raised.  If the file is not
     present or if it cannot be opened IOError is raised and it can be
@@ -82,8 +82,28 @@
     denied vs. file not found).  If there's a problem with the content
     of the file, a ValueError is raised containing a suitable error
     message.
+
+    If the catchment data is not found in the current directory
+    there is a dialog shown to select the correct File.
+
+    To allow path releations to the catchment be relative the
+    working directory is changed to the catchments direcotry.
     """
-    catchment_desc = open('catchment.desc', 'r').readlines()
+    try:
+        catchment_desc = open('catchment.desc', 'r').readlines()
+    except:
+        filters = 'Catchment Description (*.desc)|*.desc|All files (*.*)|*.*'
+        dialog = wx.wxFileDialog(None,
+                              "Please select the catchment you want to upload" ,
+                              os.getcwd(),
+                              wildcard = filters,
+                              style = wx.wxOPEN)
+        if dialog.ShowModal() == wx.wxID_OK:
+            catchment_file = dialog.GetPath()
+            catchment_desc = open(catchment_file, 'r').readlines()
+            os.chdir(os.path.dirname(catchment_file))
+        else:
+            raise IOError("No catchment file selected.")
 
     global catch_id
     global backgrounds
@@ -340,10 +360,10 @@
     def __init__(self, parent):
         TitledPage.__init__(self, parent, "Database Connection")
 
-        self.dbtype = wx.wxRadioBox(self, -1, "Database Type",
-                                    wx.wxDefaultPosition, wx.wxDefaultSize,
-                                    ["Oracle", "PostgreSQL"], 1)
-        self.sizer.Add(self.dbtype, 0, wx.wxEXPAND|wx.wxALL,5)
+#        self.dbtype = wx.wxRadioBox(self, -1, "Database Type",
+#                                    wx.wxDefaultPosition, wx.wxDefaultSize,
+#                                    ["Oracle", "PostgreSQL"], 1)
+#        self.sizer.Add(self.dbtype, 0, wx.wxEXPAND|wx.wxALL,5)
 
         grid = wx.wxFlexGridSizer(3, 2, 0, 0)
         self.sizer.Add(grid, 0, wx.wxEXPAND|wx.wxALL,5)
@@ -362,9 +382,10 @@
     def GetDBType(self):
         """Return the database type selected by the user.
 
-        The return value is one of the strings 'postgresql' or 'oracle'.
+        The return value is postgresql.
         """
-        return ("oracle", "postgresql")[self.dbtype.GetSelection()]
+        return "postgresql"
+#        return ("oracle", "postgresql")[self.dbtype.GetSelection()]
 
     def GetDBInfo(self):
         """Return the dabase login settings entered by the user.
@@ -459,12 +480,6 @@
     def OnInit(self):
         """Read the catchment.desc file and creat the wizard as the main window
         """
-        try:
-            read_catchment_desc()
-        except:
-            catchment_error = sys.exc_info()[1]
-        else:
-            catchment_error = None
 
         wx.wxInitAllImageHandlers()
         bitmap_filename = os.path.join(
@@ -476,6 +491,12 @@
             bitmap = wx.wxNullBitmap    
         wizard = self.wizard = wxWizard(wx.NULL, -1,
                                         "GREAT-ER Catchment Upload", bitmap)
+        try:
+            read_catchment_desc()
+        except:
+            catchment_error = sys.exc_info()[1]
+        else:
+            catchment_error = None
         if catchment_error is not None:
             # some error occurred.  Only one page with the error message
             intro_page = SimpleTextPage(wizard, "Catchment",



More information about the Greater-commits mailing list