[GRASS-SVN] r42308 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 18 17:32:55 EDT 2010


Author: msieczka
Date: 2010-05-18 17:32:55 -0400 (Tue, 18 May 2010)
New Revision: 42308

Modified:
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
Fix #1051: wxgui: SEARCH_PATH corruption (backport from develbranch6).

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-05-18 21:31:58 UTC (rev 42307)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-05-18 21:32:55 UTC (rev 42308)
@@ -2111,16 +2111,16 @@
         
         wx.Dialog.__init__(self, parent, id, title, pos, size, style)
 
-        self.all_mapsets = utils.ListOfMapsets(all=True)
-        self.accessible_mapsets = utils.ListOfMapsets(all=False)
+        self.all_mapsets_ordered = utils.ListOfMapsets(ordered=True)
+        self.accessible_mapsets = utils.ListOfMapsets(accessible=True)
         self.curr_mapset = grass.gisenv()['MAPSET']
 
         # make a checklistbox from available mapsets and check those that are active
         sizer = wx.BoxSizer(wx.VERTICAL)
 
         label = wx.StaticText(parent=self, id=wx.ID_ANY,
-                              label=_("Check mapset to make it accessible, uncheck it to hide it.%s"
-                                      "Note: PERMANENT and current mapset are always accessible.") % os.linesep)
+                              label=_("Check a mapset to make it accessible, uncheck it to hide it.%s"
+                                      "Note: The current mapset is always accessible.") % os.linesep)
         sizer.Add(item=label, proportion=0,
                   flag=wx.ALL, border=5)
 
@@ -2132,7 +2132,7 @@
 
         # check all accessible mapsets
         for mset in self.accessible_mapsets:
-            self.mapsetlb.CheckItem(self.all_mapsets.index(mset), True)
+            self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
 
         # dialog buttons
         line = wx.StaticLine(parent=self, id=wx.ID_ANY,
@@ -2163,7 +2163,7 @@
         """!Get list of checked mapsets"""
         ms = []
         i = 0
-        for mset in self.all_mapsets:
+        for mset in self.all_mapsets_ordered:
             if self.mapsetlb.IsChecked(i):
                 ms.append(mset)
             i += 1
@@ -2192,17 +2192,7 @@
         gisenv = grass.gisenv()
         locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
 
-        ret = gcmd.RunCommand('g.mapsets',
-                              parent = self,
-                              flags = 'l',
-                              fs = '|',
-                              read = True)
-        
-        mapsets = []
-        if ret:
-            mapsets = ret.replace('\n', '').split('|')
-        
-        for mapset in mapsets:
+        for mapset in self.parent.all_mapsets_ordered:
             index = self.InsertStringItem(sys.maxint, mapset)
             mapsetPath = os.path.join(locationPath,
                                       mapset)
@@ -2221,6 +2211,6 @@
         
     def OnCheckItem(self, index, flag):
         """!Mapset checked/unchecked"""
-        mapset = self.parent.all_mapsets[index]
-        if mapset == 'PERMANENT' or mapset == self.parent.curr_mapset:
+        mapset = self.parent.all_mapsets_ordered[index]
+        if mapset == self.parent.curr_mapset:
             self.CheckItem(index, True)

Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2010-05-18 21:31:58 UTC (rev 42307)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2010-05-18 21:32:55 UTC (rev 42308)
@@ -222,7 +222,7 @@
         
     return catstr.strip(',')
 
-def ListOfMapsets(all=False):
+def ListOfMapsets(all=False, accessible=False, ordered=False):
     """!Get list of available/accessible mapsets
 
     @param all if True get list of all mapsets
@@ -242,6 +242,43 @@
         else:
             raise gcmd.CmdError(cmd = 'g.mapsets',
                                 message = _('Unable to get list of available mapsets.'))
+
+    elif accessible:
+        ret = gcmd.RunCommand('g.mapsets',
+                              read = True,
+                              flags = 'p',
+                              fs = ';')
+        if ret:
+            mapsets = ret.rstrip('\n').split(';')
+        else:
+            raise gcmd.CmdError(cmd = 'g.mapsets',
+                                message = _('Unable to get list of accessible mapsets.'))
+
+    elif ordered:
+        ret = gcmd.RunCommand('g.mapsets',
+                              read = True,
+                              flags = 'l',
+                              fs = ';')
+        if ret:
+            mapsets_available = ret.rstrip('\n').split(';')
+        else:
+            raise gcmd.CmdError(cmd = 'g.mapsets',
+                                message = _('Unable to get list of available mapsets.'))
+ 
+        ret = gcmd.RunCommand('g.mapsets',
+                              read = True,
+                              flags = 'p',
+                              fs = ';')
+        if ret:
+            mapsets_accessible = ret.rstrip('\n').split(';')
+        else:
+            raise gcmd.CmdError(cmd = 'g.mapsets',
+                                message = _('Unable to get list of accessible mapsets.'))
+
+        for mapset in mapsets_accessible:
+            mapsets_available.remove(mapset)
+        mapsets = mapsets_accessible + mapsets_available
+
     else:
         ret = gcmd.RunCommand('g.mapsets',
                               read = True,
@@ -252,7 +289,8 @@
         else:
             raise gcmd.CmdError(cmd = 'g.mapsets',
                                 message = _('Unable to get list of accessible mapsets.'))
-        
+        # This one sorts mapset names, thus prevents the user from modifying their
+        # order in the SEARH_PATH from GUI, unlike the `ordered' above.
         ListSortLower(mapsets)
     
     return mapsets



More information about the grass-commit mailing list