فهرست منبع

wxGUI: ReadEpsgCodes() raise OpenError exception of failure (no need for backport)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68204 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 سال پیش
والد
کامیت
31954a17e6
3فایلهای تغییر یافته به همراه30 افزوده شده و 21 حذف شده
  1. 6 4
      gui/wxpython/core/utils.py
  2. 10 3
      gui/wxpython/gui_core/preferences.py
  3. 14 14
      gui/wxpython/location_wizard/wizard.py

+ 6 - 4
gui/wxpython/core/utils.py

@@ -23,6 +23,7 @@ import inspect
 
 from grass.script import core as grass
 from grass.script import task as gtask
+from grass.exceptions import OpenError
 
 from core import globalvar
 from core.gcmd  import RunCommand
@@ -496,15 +497,16 @@ def ReadEpsgCodes(path):
 
     :param path: full path to the file with EPSG codes
 
+    Raise OpenError on failure.
+
     :return: dictionary of EPSG code
-    :return: string on error
     """
     epsgCodeDict = dict()
     try:
         try:
             f = open(path, "r")
         except IOError:
-            return _("failed to open '%s'" % path)
+            raise OpenError(_("failed to open '{}'").format(path))
 
         code = None
         for line in f.readlines():
@@ -519,7 +521,7 @@ def ReadEpsgCodes(path):
                 try:
                     code = int(code.replace('<', '').replace('>', ''))
                 except ValueError as e:
-                    return e
+                    raise OpenError('{}'.format(e))
             
             if code is not None:
                 epsgCodeDict[code] = (descr, params)
@@ -527,7 +529,7 @@ def ReadEpsgCodes(path):
         
         f.close()
     except StandardError as e:
-        return e
+        raise OpenError('{}'.format(e))
     
     return epsgCodeDict
 

+ 10 - 3
gui/wxpython/gui_core/preferences.py

@@ -41,8 +41,8 @@ import wx.lib.mixins.listctrl as listmix
 import wx.lib.scrolledpanel as SP
 
 from grass.pydispatch.signal import Signal
-
 from grass.script import core as grass
+from grass.exceptions import OpenError
 
 from core          import globalvar
 from core.gcmd     import RunCommand, GError
@@ -1373,10 +1373,17 @@ class PreferencesDialog(PreferencesBaseDialog):
         """Load EPSG codes from the file"""
         win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
         path = win.GetValue()
+        epsgCombo = self.FindWindowById(self.winId['projection:statusbar:epsg'])
         wx.BeginBusyCursor()
-        self.epsgCodeDict = ReadEpsgCodes(path)
+        try:
+            self.epsgCodeDict = ReadEpsgCodes(path)
+        except OpenError as e:
+            wx.EndBusyCursor()
+            epsgCombo.SetItems([])
+            GError(parent = self,
+                   message = _("Unable to read EPGS codes: {}").format(e), showTraceback=False)
+            return
 
-        epsgCombo = self.FindWindowById(self.winId['projection:statusbar:epsg'])
         if type(self.epsgCodeDict) == type(''):
             wx.MessageBox(parent = self,
                           message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict,

+ 14 - 14
gui/wxpython/location_wizard/wizard.py

@@ -50,6 +50,7 @@ from location_wizard.base    import BaseClass
 from location_wizard.dialogs import SelectTransformDialog
 
 from grass.script import core as grass
+from grass.exceptions import OpenError
 
 global coordsys
 global north
@@ -1449,8 +1450,9 @@ class EPSGPage(TitledPage):
             self.epsgcode = None
             
         nextButton = wx.FindWindowById(wx.ID_FORWARD)
-
-        if self.epsgcode and self.epsgcode in self.epsgCodeDict.keys():
+        
+        if self.epsgcode and self.epsgCodeDict and \
+                self.epsgcode in self.epsgCodeDict.keys():
             self.epsgdesc = self.epsgCodeDict[self.epsgcode][0]
             self.epsgparams = self.epsgCodeDict[self.epsgcode][1]
             if not nextButton.IsEnabled():
@@ -1512,12 +1514,11 @@ class EPSGPage(TitledPage):
         
     def OnBrowseCodes(self, event, search = None):
         """Browse EPSG codes"""
-        self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
-
-        if type(self.epsgCodeDict) != dict:
-            wx.MessageBox(parent = self,
-                          message = _("Unable to read EPGS codes: %s") % self.epsgCodeDict,
-                          caption = _("Error"),  style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
+        try:
+            self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
+        except OpenError as e:
+            GError(parent = self,
+                   message = _("Unable to read EPGS codes: {}").format(e), showTraceback=False)
             self.epsglist.Populate(list(), update = True)
             return
         
@@ -1738,12 +1739,11 @@ class IAUPage(TitledPage):
         
     def OnBrowseCodes(self, event, search = None):
         """Browse IAU codes"""
-        self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
-
-        if type(self.epsgCodeDict) != dict:
-            wx.MessageBox(parent = self,
-                          message = _("Unable to read IAU codes: %s") % self.epsgCodeDict,
-                          caption = _("Error"),  style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
+        try:
+            self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
+        except OpenError as e:
+            GError(parent = self,
+                   message = _("Unable to read IAU codes: {}").format(e), showTraceback=False)
             self.epsglist.Populate(list(), update = True)
             return