[GRASS-dev] [GRASS GIS] #987: Location wizard choose from EPSG robustness issues

#987: Location wizard choose from EPSG robustness issues
-------------------------+--------------------------------------------------
Reporter: marisn | Owner: grass-dev@lists.osgeo.org
     Type: defect | Status: new
Priority: minor | Milestone: 6.4.0
Component: wxGUI | Version: svn-releasebranch64
Keywords: | Platform: Linux
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
Start location wizard -> Select EPSG code -> Path to EPSG codes file
displays wrong file (that's OK), but I see uncaught exception in console:

{{{
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1381, in
OnEnterPage
     self.OnBrowseCodes(None)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1491, in
OnBrowseCodes
     f = open(self.tfile.GetValue(), "r")
IOError: [Errno 2] No such file or directory:
u'/usr/local/share/proj/epsg'
}}}
Can be fixed by something like:

{{{
Index: location_wizard.py

--- location_wizard.py (revision 41315)
+++ location_wizard.py (working copy)
@@ -1488,7 +1488,10 @@
          if True:
              data =
              self.epsgCodeDict = {}
- f = open(self.tfile.GetValue(), "r")
+ try:
+ f = open(self.tfile.GetValue(), "r")
+ except IOError:
+ return
              i = 0
              code = None
              for line in f.readlines():
}}}

Now cancel Location wizard and repeat previous steps: Location wizard ->
Select EPSG (choice is PRESELECTED) -> NEXT gives Choose by code and not
EPSG code. WTF?
Seems like location wizard is not ready to be run more than one time
during GRASS startup session.

Now edit path to EPSG code file (i.e. delete "local" from
"/usr/local/share/proj") -> PATH to epsg is correct, still it's impossible
to search EPSG code list or press "Next" when correct code is set.
Location wizard should also check for onChanged event for EPSG code file
entry.

Also other EPSG window elements should check for presence of valid EPSG
code file before issuing any actions:
{{{
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1381, in
OnEnterPage
     self.OnBrowseCodes(None)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1491, in
OnBrowseCodes
     f = open(self.tfile.GetValue(), "r")
IOError: [Errno 2] No such file or directory:
u'/usr/local/share/proj/epsg'
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1447, in OnSearch
     self.epsglist.Search(index=[0,1,2], pattern=value)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 646, in Search
     for i in range(len(self.sourceData)):
TypeError: object of type 'NoneType' has no len()
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1447, in OnSearch
     self.epsglist.Search(index=[0,1,2], pattern=value)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 646, in Search
     for i in range(len(self.sourceData)):
TypeError: object of type 'NoneType' has no len()
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1447, in OnSearch
     self.epsglist.Search(index=[0,1,2], pattern=value)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 646, in Search
     for i in range(len(self.sourceData)):
TypeError: object of type 'NoneType' has no len()
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1447, in OnSearch
     self.epsglist.Search(index=[0,1,2], pattern=value)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 646, in Search
     for i in range(len(self.sourceData)):
TypeError: object of type 'NoneType' has no len()
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1447, in OnSearch
     self.epsglist.Search(index=[0,1,2], pattern=value)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 646, in Search
     for i in range(len(self.sourceData)):
TypeError: object of type 'NoneType' has no len()
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1381, in
OnEnterPage
     self.OnBrowseCodes(None)
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1491, in
OnBrowseCodes
     f = open(self.tfile.GetValue(), "r")
IOError: [Errno 2] No such file or directory:
u'/usr/local/share/proj/epsg'
}}}

Tested with GRASS 6.4 r41315 running dev-python/wxpython-2.8.10.1 on
~AMD64 Gentoo.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/987&gt;
GRASS GIS <http://grass.osgeo.org>

#987: Location wizard choose from EPSG robustness issues
---------------------+------------------------------------------------------
  Reporter: marisn | Owner: martinl
      Type: defect | Status: assigned
  Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: svn-releasebranch64
Resolution: | Keywords: location wizard
  Platform: Linux | Cpu: Unspecified
---------------------+------------------------------------------------------
Changes (by martinl):

* cc: grass-dev@lists.osgeo.org (added)
  * keywords: => location wizard
  * status: new => assigned
  * owner: grass-dev@lists.osgeo.org => martinl
  * priority: minor => normal

Comment:

Please try out r41316. Martin

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/987#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#987: Location wizard choose from EPSG robustness issues
---------------------+------------------------------------------------------
  Reporter: marisn | Owner: martinl
      Type: defect | Status: assigned
  Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: svn-releasebranch64
Resolution: | Keywords: location wizard
  Platform: Linux | Cpu: Unspecified
---------------------+------------------------------------------------------
Comment (by marisn):

That's much better.

Still search should not be performed if proper file is not selected:
{{{
Traceback (most recent call last):
   File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1437, in OnSearch
     self.epsglist.Search(index=[0,1,2], pattern=value)
ValueError: need more than 0 values to unpack
}}}

Also currently EPSG file change is detected only after browse or on ENTER.
It would be nice to detect simple edits without need to press ENTER.
Following approach has one disadvantage - if file name field has focus
when user chooses CANCEL, it also gives an warning about improper file
name if it's wrong one. As I have no idea how events work in wxpython, I
can't provide code, just an idea.
{{{
Index: wxpython/gui_modules/location_wizard.py

--- wxpython/gui_modules/location_wizard.py (revision 41318)
+++ wxpython/gui_modules/location_wizard.py (working copy)
@@ -1350,6 +1350,7 @@
          # events
          self.bbrowse.Bind(wx.EVT_BUTTON, self.OnBrowse)
          self.tfile.Bind(wx.EVT_TEXT_ENTER, self.OnBrowseCodes)
+ self.tfile.Bind(wx.EVT_KILL_FOCUS, self.OnBrowseCodes)
          self.tcode.Bind(wx.EVT_TEXT, self.OnText)
          self.tcode.Bind(wx.EVT_TEXT_ENTER, self.OnText)
          self.epsglist.Bind(wx.EVT_LIST_ITEM_SELECTED,
self.OnItemSelected)
@@ -1368,6 +1369,7 @@

          # load default epsg database file
          self.OnBrowseCodes(None)
+ self.searchb.SetFocus()

          event.Skip()

}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/987#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#987: Location wizard choose from EPSG robustness issues
---------------------+------------------------------------------------------
  Reporter: marisn | Owner: martinl
      Type: defect | Status: assigned
  Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: svn-releasebranch64
Resolution: | Keywords: location wizard
  Platform: Linux | Cpu: Unspecified
---------------------+------------------------------------------------------
Comment (by martinl):

Replying to [comment:2 marisn]:

> Still search should not be performed if proper file is not selected:
{{{
> Traceback (most recent call last):
> File "/home/maris/soft/grass_64/dist.x86_64-unknown-linux-
gnu/etc/wxpython/gui_modules/location_wizard.py", line 1437, in OnSearch
> self.epsglist.Search(index=[0,1,2], pattern=value)
> ValueError: need more than 0 values to unpack
}}}

Fixed r41345.

> Also currently EPSG file change is detected only after browse or on
ENTER. It would be nice to detect simple edits without need to press
ENTER. Following approach has one disadvantage - if file name field has
focus when user chooses CANCEL, it also gives an warning about improper
file name if it's wrong one. As I have no idea how events work in
wxpython, I can't provide code, just an idea.

Loading EPSG codes can be quite consuming task. Pressing Enter on loading
codes or searching in codes seems to be adequate to me.

Martin

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/987#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#987: Location wizard choose from EPSG robustness issues
---------------------+------------------------------------------------------
  Reporter: marisn | Owner: martinl
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: svn-releasebranch64
Resolution: fixed | Keywords: location wizard
  Platform: Linux | Cpu: Unspecified
---------------------+------------------------------------------------------
Changes (by martinl):

  * status: assigned => closed
  * resolution: => fixed

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/987#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>