[GRASS-SVN] r55185 - grass/branches/releasebranch_6_4/gui/wxpython

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 24 08:24:55 PST 2013


Author: annakrat
Date: 2013-02-24 08:24:55 -0800 (Sun, 24 Feb 2013)
New Revision: 55185

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gis_set.py
Log:
wxGUI start screen: go back after creating new location

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gis_set.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gis_set.py	2013-02-23 17:57:09 UTC (rev 55184)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gis_set.py	2013-02-24 16:24:55 UTC (rev 55185)
@@ -26,6 +26,7 @@
 import copy
 import platform
 import codecs
+import getpass
 
 ### i18N
 import gettext
@@ -419,7 +420,13 @@
             else:
                 self.SetDefaultRegion(location = gWizard.location)
 
-            self.ExitSuccessfully()
+            dlg = wx.TextEntryDialog(parent=self,
+                                     message=_("Do you want to create new mapset?"),
+                                     caption=_("Create new mapset"),
+                                     defaultValue=self._getDefaultMapsetName())
+            if dlg.ShowModal() == wx.ID_OK:
+                mapsetName = dlg.GetValue()
+                self.CreateNewMapset(mapsetName)
 
     def SetDefaultRegion(self, location):
         """!Asks to set default region."""
@@ -771,39 +778,43 @@
         
         dlg.Destroy()
 
-    def OnCreateMapset(self,event):
+    def OnCreateMapset(self, event):
         """!Create new mapset"""
-        self.gisdbase = self.tgisdbase.GetValue()
-        location = self.listOfLocations[self.lblocations.GetSelection()]
 
         dlg = wx.TextEntryDialog(parent = self,
                                  message = _('Enter name for new mapset:'),
-                                 caption = _('Create new mapset'))
+                                 caption = _('Create new mapset'),
+                                 defaultValue = self._getDefaultMapsetName())
 
-        if dlg.ShowModal() ==  wx.ID_OK:
+        if dlg.ShowModal() == wx.ID_OK:
             mapset = dlg.GetValue()
-            if mapset in self.listOfMapsets:
-                GMessage(parent = self,
-                         message = _("Mapset <%s> already exists.") % mapset)
-                return
-            
-            try:
-                os.mkdir(os.path.join(self.gisdbase, location, mapset))
-                # copy WIND file and its permissions from PERMANENT and set permissions to u+rw,go+r
-                shutil.copy(os.path.join(self.gisdbase, location, 'PERMANENT', 'WIND'),
-                            os.path.join(self.gisdbase, location, mapset))
-                # os.chmod(os.path.join(database,location,mapset,'WIND'), 0644)
-                self.OnSelectLocation(None)
-                self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
-            except StandardError, e:
-                GError(parent = self,
-                       message = _("Unable to create new mapset: %s") % e,
-                       showTraceback = False)
-                return False
+            return self.CreateNewMapset(mapset = mapset)
+        else:
+            return False
+
+    def CreateNewMapset(self, mapset):
+        if mapset in self.listOfMapsets:
+            GMessage(parent = self,
+                     message = _("Mapset <%s> already exists.") % mapset)
+            return False
         
-        self.bstart.SetFocus()
-        
-        return True
+        try:
+            self.gisdbase = self.tgisdbase.GetValue()
+            location = self.listOfLocations[self.lblocations.GetSelection()]
+            os.mkdir(os.path.join(self.gisdbase, location, mapset))
+            # copy WIND file and its permissions from PERMANENT and set permissions to u+rw,go+r
+            shutil.copy(os.path.join(self.gisdbase, location, 'PERMANENT', 'WIND'),
+                        os.path.join(self.gisdbase, location, mapset))
+            # os.chmod(os.path.join(database,location,mapset,'WIND'), 0644)
+            self.OnSelectLocation(None)
+            self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
+            self.bstart.SetFocus()
+            return True
+        except StandardError, e:
+            GError(parent = self,
+                   message = _("Unable to create new mapset: %s") % e,
+                   showTraceback = False)
+            return False
 
     def OnStart(self, event):
         """'Start GRASS' button clicked"""
@@ -859,8 +870,18 @@
                    set = "LOCATION_NAME=%s" % location)
         RunCommand("g.gisenv",
                    set = "MAPSET=%s" % mapset)
-        
 
+
+    def _getDefaultMapsetName(self):
+        """!Returns default name for mapset."""
+        try:
+            defaultName = getpass.getuser()
+            defaultName.encode('ascii') # raise error if not ascii (not valid mapset name)
+        except: # whatever might go wrong
+            defaultName = 'user'
+
+        return defaultName
+
     def ExitSuccessfully(self):
         self.Destroy()
         sys.exit(0)



More information about the grass-commit mailing list