[GRASS-SVN] r68204 - in grass/trunk/gui/wxpython: core gui_core location_wizard
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 2 03:21:40 PDT 2016
Author: martinl
Date: 2016-04-02 03:21:40 -0700 (Sat, 02 Apr 2016)
New Revision: 68204
Modified:
grass/trunk/gui/wxpython/core/utils.py
grass/trunk/gui/wxpython/gui_core/preferences.py
grass/trunk/gui/wxpython/location_wizard/wizard.py
Log:
wxGUI: ReadEpsgCodes() raise OpenError exception of failure (no need for backport)
Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py 2016-04-02 10:01:24 UTC (rev 68203)
+++ grass/trunk/gui/wxpython/core/utils.py 2016-04-02 10:21:40 UTC (rev 68204)
@@ -23,6 +23,7 @@
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 @@
: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 @@
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 @@
f.close()
except StandardError as e:
- return e
+ raise OpenError('{}'.format(e))
return epsgCodeDict
Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py 2016-04-02 10:01:24 UTC (rev 68203)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py 2016-04-02 10:21:40 UTC (rev 68204)
@@ -41,8 +41,8 @@
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 @@
"""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,
Modified: grass/trunk/gui/wxpython/location_wizard/wizard.py
===================================================================
--- grass/trunk/gui/wxpython/location_wizard/wizard.py 2016-04-02 10:01:24 UTC (rev 68203)
+++ grass/trunk/gui/wxpython/location_wizard/wizard.py 2016-04-02 10:21:40 UTC (rev 68204)
@@ -50,6 +50,7 @@
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 @@
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 @@
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 @@
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
More information about the grass-commit
mailing list