[GRASS-SVN] r41317 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 7 06:10:28 EST 2010


Author: martinl
Date: 2010-03-07 06:10:27 -0500 (Sun, 07 Mar 2010)
New Revision: 41317

Modified:
   grass/branches/develbranch_6/gui/wxpython/gis_set.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
Log:
wxGUI/loc_wiz: bugfix #987
(merge r41316 from relbr64)


Modified: grass/branches/develbranch_6/gui/wxpython/gis_set.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gis_set.py	2010-03-07 10:57:12 UTC (rev 41316)
+++ grass/branches/develbranch_6/gui/wxpython/gis_set.py	2010-03-07 11:10:27 UTC (rev 41317)
@@ -398,7 +398,8 @@
     def OnWizard(self, event):
         """!Location wizard started"""
         from gui_modules import location_wizard
-        gWizard = location_wizard.LocationWizard(self, self.tgisdbase.GetValue())
+        gWizard = location_wizard.LocationWizard(parent = self,
+                                                 grassdatabase = self.tgisdbase.GetValue())
         if gWizard.location != None:
             self.OnSetDatabase(event)
             self.UpdateMapsets(os.path.join(self.gisdbase, gWizard.location))

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2010-03-07 10:57:12 UTC (rev 41316)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2010-03-07 11:10:27 UTC (rev 41317)
@@ -65,14 +65,6 @@
 global wizerror
 global translist
 
-coordsys = ''
-north = ''
-south = ''
-east = ''
-west = ''
-resolution = ''
-transformlist = []
-
 class BaseClass(wx.Object):
     """!Base class providing basic methods"""
     def __init__(self):
@@ -268,6 +260,7 @@
                                              "PROJ.4 parameters"))
         self.radio6 = wx.RadioButton(parent=self, id=wx.ID_ANY,
                                      label=_("Create an arbitrary non-earth coordinate system (XY)"))
+        
         # layout
         self.sizer.AddGrowableCol(1)
         self.sizer.SetVGap(10)
@@ -1302,13 +1295,13 @@
                                     style=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
         # text input
         epsgdir = utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg')
-        self.tfile = self.MakeTextCtrl(text=epsgdir, size=(200,-1))
+        self.tfile = self.MakeTextCtrl(text=epsgdir, size=(200,-1),
+                                       style = wx.TE_PROCESS_ENTER)
         self.tcode = self.MakeTextCtrl(size=(200,-1))
 
         # buttons
         self.bbrowse = self.MakeButton(_("Browse"))
-#        self.bbcodes = self.MakeButton(_("Reload EPSG Codes"))
-
+        
         # search box
         self.searchb = wx.SearchCtrl(self, size=(200,-1),
                                      style=wx.TE_PROCESS_ENTER)
@@ -1342,11 +1335,7 @@
                        flag=wx.ALIGN_LEFT |
                        wx.ALIGN_CENTER_VERTICAL |
                        wx.ALL, border=5, pos=(3, 3))
-#        self.sizer.Add(item=self.bbcodes,
-#                       flag=wx.ALIGN_LEFT |
-#                       wx.ALIGN_CENTER_VERTICAL |
-#                       wx.ALL, border=5, pos=(3, 4))
-
+        
         self.sizer.AddGrowableRow(4)
         self.sizer.Add(item=self.epsglist,
                        flag=wx.ALIGN_LEFT | wx.EXPAND, pos=(4, 1),
@@ -1354,7 +1343,7 @@
 
         # events
         self.bbrowse.Bind(wx.EVT_BUTTON, self.OnBrowse)
-#        self.bbcodes.Bind(wx.EVT_BUTTON, self.OnBrowseCodes)
+        self.tfile.Bind(wx.EVT_TEXT_ENTER, 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)
@@ -1454,15 +1443,15 @@
         path = os.path.dirname(self.tfile.GetValue())
         if not path:
             path = os.getcwd()
-
+        
         dlg = wx.FileDialog(parent=self, message=_("Choose EPSG codes file"),
                             defaultDir=path, defaultFile="", wildcard="*", style=wx.OPEN)
-
+        
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
             self.tfile.SetValue(path)
             self.OnBrowseCodes(None)
-
+        
         dlg.Destroy()
 
         event.Skip()
@@ -1481,18 +1470,19 @@
     def OnBrowseCodes(self, event, search=None):
         """!Browse EPSG codes"""
         self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
-        if type(self.epsgCodeDict) == type(''):
+
+        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)
-            self.epsglist.Populate([], update=True)
+            self.epsglist.Populate(list(), update=True)
             return
-
-        data = []
+        
+        data = list()
         for code, val in self.epsgCodeDict.iteritems():
             if code is not None:
                 data.append((code, val[0], val[1]))
-                
+        
         self.epsglist.Populate(data, update=True)
         
 class CustomPage(TitledPage):
@@ -1729,23 +1719,22 @@
             event.Skip()
 
 class LocationWizard(wx.Object):
-    """
+    """!
     Start wizard here and finish wizard here
     """
     def __init__(self, parent, grassdatabase):
+        self.__cleanUp()
+        
         global coordsys
         self.parent = parent
 
         #
         # define wizard image
         #
-        # file = "loc_wizard.png"
-        file = "loc_wizard_qgis.png"
-        imagePath = os.path.join(globalvar.ETCWXDIR, "images", file)
+        imagePath = os.path.join(globalvar.ETCWXDIR, "images", "loc_wizard_qgis.png")
         wizbmp = wx.Image(imagePath, wx.BITMAP_TYPE_PNG)
-        # wizbmp.Rescale(250,600)
         wizbmp = wizbmp.ConvertToBitmap()
-
+        
         #
         # get georeferencing information from tables in $GISBASE/etc
         #
@@ -1865,12 +1854,34 @@
                                     'err' : msg },
                               caption=_("Location wizard"),
                               style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-        else:
-            win = wx.MessageBox(parent=self.parent,
-                                message=_("Location wizard canceled. "
-                                          "Location not created."),
-                                caption=_("Location wizard"))
-    
+        else: # -> cancelled
+            self.wizard.Destroy()
+            wx.MessageBox(parent=self.parent,
+                          message=_("Location wizard canceled. "
+                                    "Location not created."),
+                          caption=_("Location wizard"),
+                          style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+        
+        self.__cleanUp()
+        
+    def __cleanUp(self):
+        global coordsys
+        global north
+        global south
+        global east
+        global west
+        global resolution
+        global wizerror
+        global translist
+        
+        coordsys = None
+        north = None
+        south = None
+        east = None
+        west = None
+        resolution = None
+        transformlist = list()
+
     def __readData(self):
         """!Get georeferencing information from tables in $GISBASE/etc"""
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2010-03-07 10:57:12 UTC (rev 41316)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2010-03-07 11:10:27 UTC (rev 41317)
@@ -478,7 +478,11 @@
     """
     epsgCodeDict = dict()
     try:
-        f = open(path, "r")
+        try:
+            f = open(path, "r")
+        except IOError:
+            return _("failed to open '%s'" % path)
+        
         i = 0
         code = None
         for line in f.readlines():
@@ -490,15 +494,19 @@
                 descr = line[1:].strip()
             elif line[0] == '<':
                 code, params = line.split(" ", 1)
-                code = int(code.replace('<', '').replace('>', ''))
-
+                try:
+                    code = int(code.replace('<', '').replace('>', ''))
+                except ValueError:
+                    return e
+            
             if code is not None:
                 epsgCodeDict[code] = (descr, params)
                 code = None
             i += 1
+        
         f.close()
     except StandardError, e:
-        return str(e)
+        return e
     
     return epsgCodeDict
 



More information about the grass-commit mailing list