[GRASS-SVN] r44616 - in grass/trunk: gui/wxpython/gui_modules lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 16 09:37:23 EST 2010


Author: martinl
Date: 2010-12-16 06:37:23 -0800 (Thu, 16 Dec 2010)
New Revision: 44616

Modified:
   grass/trunk/gui/wxpython/gui_modules/location_wizard.py
   grass/trunk/lib/python/core.py
Log:
#965 (Location wizard: doesn't create MYNAME)


Modified: grass/trunk/gui/wxpython/gui_modules/location_wizard.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/location_wizard.py	2010-12-16 14:01:19 UTC (rev 44615)
+++ grass/trunk/gui/wxpython/gui_modules/location_wizard.py	2010-12-16 14:37:23 UTC (rev 44616)
@@ -127,14 +127,16 @@
         TitledPage.__init__(self, wizard, _("Define GRASS Database and Location Name"))
 
         self.grassdatabase = grassdatabase
-        self.location = ''
-
+        self.location      = ''
+        self.description   = ''
+        
         # buttons
         self.bbrowse = self.MakeButton(_("Browse"))
 
         # text controls
-        self.tgisdbase = self.MakeTextCtrl(grassdatabase, size=(300, -1))
-        self.tlocation = self.MakeTextCtrl("newLocation", size=(300, -1))
+        self.tgisdbase    = self.MakeTextCtrl(grassdatabase, size=(300, -1))
+        self.tlocation    = self.MakeTextCtrl("newLocation", size=(300, -1))
+        self.tdescription = self.MakeTextCtrl(size=(300, 150), style = wx.TE_MULTILINE)
         
         # layout
         self.sizer.AddGrowableCol(3)
@@ -153,7 +155,7 @@
                        wx.ALIGN_CENTER_VERTICAL |
                        wx.ALL, border=5,
                        pos=(1, 3))
-        #
+        
         self.sizer.Add(item=self.MakeLabel("%s:" % _("Project Location")),
                        flag=wx.ALIGN_RIGHT |
                        wx.ALIGN_CENTER_VERTICAL |
@@ -164,6 +166,17 @@
                        wx.ALIGN_CENTER_VERTICAL |
                        wx.ALL, border=5,
                        pos=(2, 2))
+
+        self.sizer.Add(item=self.MakeLabel("%s:" % _("Description")),
+                       flag=wx.ALIGN_RIGHT |
+                       wx.ALIGN_TOP |
+                       wx.ALL, border=5,
+                       pos=(3, 1))
+        self.sizer.Add(item=self.tdescription,
+                       flag=wx.ALIGN_LEFT |
+                       wx.ALIGN_CENTER_VERTICAL |
+                       wx.ALL, border=5,
+                       pos=(3, 2))
         
         # bindings
         self.Bind(wx.EVT_BUTTON,                self.OnBrowse, self.bbrowse)
@@ -192,26 +205,23 @@
             
         dlg.Destroy()
 
-    def OnPageChanging(self,event=None):
-        error = ''
+    def OnPageChanging(self, event = None):
+        error = None
         if os.path.isdir(os.path.join(self.tgisdbase.GetValue(), self.tlocation.GetValue())):
             error = _("Location already exists in GRASS Database.")
 
-        if error != '':
-            dlg = wx.MessageDialog(parent=self, message="%s <%s>.%s%s" % (_("Unable to create location"),
-                                                                          str(self.tlocation.GetValue()),
-                                                                          os.linesep,
-                                                                          error),
-                                   caption=_("Error"),  style=wx.OK | wx.ICON_ERROR)
-            
-            dlg.ShowModal()
-            dlg.Destroy()
+        if error:
+            gcmd.GError(parent = self,
+                        message="%s <%s>.%s%s" % (_("Unable to create location"),
+                                                  str(self.tlocation.GetValue()),
+                                                  os.linesep,
+                                                  error))
             event.Veto()
             return
 
-        self.location = self.tlocation.GetValue()
+        self.location      = self.tlocation.GetValue()
         self.grassdatabase = self.tgisdbase.GetValue()
-
+        self.description   = self.tdescription.GetValue()
         
 class CoordinateSystemPage(TitledPage):
     """!Wizard page for choosing method for location creation"""
@@ -1952,16 +1962,19 @@
         try:
             if coordsys == "xy":
                 grass.create_location(dbase = self.startpage.grassdatabase,
-                                      location = self.startpage.location)
+                                      location = self.startpage.location,
+                                      desc = self.startpage.description)
             elif coordsys == "proj":
                 grass.create_location(dbase = self.startpage.grassdatabase,
                                       location = self.startpage.location,
                                       proj4 = self.CreateProj4String(),
-                                      datum = self.datumtrans)
+                                      datum = self.datumtrans,
+                                      desc = self.startpage.description)
             elif coordsys == 'custom':
                 grass.create_location(dbase = self.startpage.grassdatabase,
                                       location = self.startpage.location,
-                                      proj4 = self.custompage.customstring)
+                                      proj4 = self.custompage.customstring,
+                                      desc = self.startpage.description)
             elif coordsys == "epsg":
                 if not self.epsgpage.epsgcode:
                     return _('EPSG code missing.')
@@ -1969,7 +1982,8 @@
                 grass.create_location(dbase = self.startpage.grassdatabase,
                                       location = self.startpage.location,
                                       epsg = self.epsgpage.epsgcode,
-                                      datum = self.datumtrans)
+                                      datum = self.datumtrans,
+                                      desc = self.startpage.description)
             elif coordsys == "file":
                 if not self.filepage.georeffile or \
                         not os.path.isfile(self.filepage.georeffile):
@@ -1977,7 +1991,8 @@
                 
                 grass.create_location(dbase = self.startpage.grassdatabase,
                                       location = self.startpage.location,
-                                      filename = self.filepage.georeffile)
+                                      filename = self.filepage.georeffile,
+                                      desc = self.startpage.description)
             elif coordsys == "wkt":
                 if not self.wktpage.wktfile or \
                         not os.path.isfile(self.wktpage.wktfile):
@@ -1985,7 +2000,8 @@
                 
                 grass.create_location(dbase = self.startpage.grassdatabase,
                                       location = self.startpage.location,
-                                      filename = self.wktpage.wktfile)
+                                      filename = self.wktpage.wktfile,
+                                      desc = self.startpage.description)
         
         except grass.ScriptException, e:
             return str(e)
@@ -2035,9 +2051,8 @@
         return proj4string
 
 class RegionDef(BaseClass, wx.Frame):
+    """!Page for setting default region extents and resolution
     """
-    Page for setting default region extents and resolution
-    """
     def __init__(self, parent, id=wx.ID_ANY,
                  title=_("Set default region extent and resolution"), location=None):
         wx.Frame.__init__(self, parent, id, title, size=(650,300))

Modified: grass/trunk/lib/python/core.py
===================================================================
--- grass/trunk/lib/python/core.py	2010-12-16 14:01:19 UTC (rev 44615)
+++ grass/trunk/lib/python/core.py	2010-12-16 14:37:23 UTC (rev 44616)
@@ -941,7 +941,7 @@
 
 def create_location(dbase, location,
                     epsg = None, proj4 = None, filename = None, wkt = None,
-                    datum = None):
+                    datum = None, desc = None):
     """!Create new location
 
     Raise ScriptException on error.
@@ -953,6 +953,7 @@
     @param filename if given create new location based on georeferenced file
     @param wkt if given create new location based on WKT definition (path to PRJ file)
     @param datum datum transformation parameters (used for epsg and proj4)
+    @param desc description of the location (creates MYNAME file)
     """
     gisdbase = None
     if epsg or proj4 or filename or wkt:
@@ -961,7 +962,7 @@
                     set = 'GISDBASE=%s' % dbase)
     if not os.path.exists(dbase):
             os.mkdir(dbase)
-
+    
     kwargs = dict()
     if datum:
         kwargs['datum'] = datum
@@ -973,7 +974,7 @@
                           epsg = epsg,
                           location = location,
                           stderr = PIPE,
-                         **kwargs)
+                          **kwargs)
     elif proj4:
         ps = pipe_command('g.proj',
                           quiet = True,
@@ -997,15 +998,27 @@
                           location = location,
                           stderr = PIPE)
     else:
-        return _create_location_xy(dbase, location)
+        _create_location_xy(dbase, location)
+    
+    if epsg or proj4 or filename or wkt:
+        error = ps.communicate()[1]
+        run_command('g.gisenv',
+                    set = 'GISDBASE=%s' % gisdbase)
+        
+        if ps.returncode != 0 and error:
+            raise ScriptException(repr(error))
 
-    error = ps.communicate()[1]
-    run_command('g.gisenv',
-                set = 'GISDBASE=%s' % gisdbase)
-    
-    if ps.returncode != 0 and error:
-        raise ScriptException(repr(error))
-    
+    try:
+        fd = open(os.path.join(dbase, location,
+                               'PERMANENT', 'MYNAME'), 'w')
+        if desc:
+            fd.write(desc + os.linesep)
+        else:
+            fd.write(os.linesep)
+        fd.close()
+    except OSError, e:
+        raise ScriptException(repr(e))
+        
 def _create_location_xy(database, location):
     """!Create unprojected location
 
@@ -1049,12 +1062,6 @@
         shutil.copy(os.path.join(location, "PERMANENT", "DEFAULT_WIND"),
                     os.path.join(location, "PERMANENT", "WIND"))
         
-        # create MYNAME file
-        myname = open(os.path.join(location, "PERMANENT",
-                                   "MYNAME"), 'w')
-        myname.write('%s' % os.linesep)
-        myname.close()
-        
         os.chdir(cur_dir)
     except OSError, e:
         raise ScriptException(repr(e))



More information about the grass-commit mailing list