Opened 15 years ago

Closed 15 years ago

#987 closed defect (fixed)

Location wizard choose from EPSG robustness issues

Reported by: marisn Owned by: martinl
Priority: normal Milestone: 6.4.0
Component: wxGUI Version: svn-releasebranch64
Keywords: location wizard Cc: grass-dev@…
CPU: Unspecified Platform: Linux

Description

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.

Change History (4)

comment:1 by martinl, 15 years ago

Cc: grass-dev@… added
Keywords: location wizard added
Owner: changed from grass-dev@… to martinl
Priority: minornormal
Status: newassigned

Please try out r41316. Martin

comment:2 by marisn, 15 years ago

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()

in reply to:  2 comment:3 by martinl, 15 years ago

Replying to 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

comment:4 by martinl, 15 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.