[GRASS-SVN] r41574 - grass/branches/develbranch_6/gui/wxpython

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 27 05:58:54 EDT 2010


Author: martinl
Date: 2010-03-27 05:58:54 -0400 (Sat, 27 Mar 2010)
New Revision: 41574

Modified:
   grass/branches/develbranch_6/gui/wxpython/gis_set.py
Log:
wxGUI: rename mapset/location - better error handling
(merge r41573 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gis_set.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gis_set.py	2010-03-27 09:57:40 UTC (rev 41573)
+++ grass/branches/develbranch_6/gui/wxpython/gis_set.py	2010-03-27 09:58:54 UTC (rev 41574)
@@ -427,54 +427,75 @@
             self.DeleteLocation()
 
     def RenameMapset(self):
+        """!Rename selected mapset
         """
-        Rename selected mapset
-        """
-
-        location = self.listOfLocations[self.lblocations.GetSelection()]
-        mapset   = self.listOfMapsets[self.lbmapsets.GetSelection()]
-
+        location = utils.UnicodeString(self.listOfLocations[self.lblocations.GetSelection()])
+        mapset   = utils.UnicodeString(self.listOfMapsets[self.lbmapsets.GetSelection()])
+        
         dlg = wx.TextEntryDialog(parent=self,
-                                 message=_('Current name: %s\nEnter new name:') % mapset,
+                                 message=_('Current name: %s\n\nEnter new name:') % mapset,
                                  caption=_('Rename selected mapset'))
-
+        
         if dlg.ShowModal() == wx.ID_OK:
             newmapset = dlg.GetValue()
-            if newmapset != mapset:
+            if newmapset == mapset:
+                dlg.Destroy()
+                return
+            
+            if newmapset in self.listOfMapsets:
+                wx.MessageBox(parent = self,
+                              caption = _('Message'),
+                              message=_('Unable to rename mapset.\n\n'
+                                        'Mapset <%s> already exists in location.') % newmapset,
+                              style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+            else:
                 try:
                     os.rename(os.path.join(self.gisdbase, location, mapset),
                               os.path.join(self.gisdbase, location, newmapset))
                     self.OnSelectLocation(None)
                     self.lbmapsets.SetSelection(self.listOfMapsets.index(newmapset))
-                except:
-                    wx.MessageBox(message=_('Unable to rename mapset'))
-
+                except StandardError, e:
+                    wx.MessageBox(parent = self,
+                                  caption = _('Error'),
+                                  message=_('Unable to rename mapset.\n\n%s') % e,
+                                  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            
         dlg.Destroy()
 
     def RenameLocation(self):
+        """!Rename selected location
         """
-        Rename selected location
-        """
+        location = utils.UnicodeString(self.listOfLocations[self.lblocations.GetSelection()])
 
-        location = self.listOfLocations[self.lblocations.GetSelection()]
-
         dlg = wx.TextEntryDialog(parent=self,
-                                 message=_('Current name: %s\nEnter new name:') % location,
+                                 message=_('Current name: %s\n\nEnter new name:') % location,
                                  caption=_('Rename selected location'))
 
         if dlg.ShowModal() == wx.ID_OK:
             newlocation = dlg.GetValue()
-            if newlocation != location:
-                mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
+            if newlocation == location:
+                dlg.Destroy()
+                return
+
+            if newlocation in self.listOfLocations:
+                wx.MessageBox(parent = self,
+                              caption = _('Message'),
+                              message=_('Unable to rename location.\n\n'
+                                        'Location <%s> already exists in GRASS database.') % newlocation,
+                              style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+            else:
                 try:
                     os.rename(os.path.join(self.gisdbase, location),
                               os.path.join(self.gisdbase, newlocation))
                     self.UpdateLocations(self.gisdbase)
                     self.lblocations.SetSelection(self.listOfLocations.index(newlocation))
                     self.UpdateMapsets(newlocation)
-                except:
-                    wx.MessageBox(message=_('Unable to rename location'))
-
+                except StandardError, e:
+                    wx.MessageBox(parent = self,
+                                  caption = _('Error'),
+                                  message=_('Unable to rename location.\n\n%s') % e,
+                                  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+        
         dlg.Destroy()
 
     def DeleteMapset(self):



More information about the grass-commit mailing list