[GRASS-SVN] r42307 - grass/branches/develbranch_6/gui/wxpython/gui_modules

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


Author: msieczka
Date: 2010-05-18 17:31:58 -0400 (Tue, 18 May 2010)
New Revision: 42307

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
Log:
Fix #1051: wxgui: SEARCH_PATH corruption.

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2010-05-18 19:22:21 UTC (rev 42306)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2010-05-18 21:31:58 UTC (rev 42307)
@@ -2160,16 +2160,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)
 
@@ -2181,7 +2181,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,
@@ -2212,7 +2212,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
@@ -2241,14 +2241,7 @@
         gisenv = grass.gisenv()
         locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
 
-        ret = gcmd.RunCommand('g.mapsets',
-                              flags = 'l',
-                              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)
@@ -2267,6 +2260,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/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2010-05-18 19:22:21 UTC (rev 42306)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2010-05-18 21:31:58 UTC (rev 42307)
@@ -215,7 +215,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
@@ -223,17 +223,50 @@
     @return list of mapsets
     """
     mapsets = []
-    
+
     if all:
         ret = gcmd.RunCommand('g.mapsets',
                               read = True,
                               flags = 'l')
-    
         if ret:
             mapsets = ret.rstrip('\n').strip().split(' ')
         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')
+        if ret:
+            mapsets = ret.rstrip('\n').strip().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')
+        if ret:
+            mapsets_available = ret.rstrip('\n').strip().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')
+        if ret:
+            mapsets_accessible = ret.rstrip('\n').strip().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,
@@ -243,9 +276,10 @@
         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
 
 def ListSortLower(list):



More information about the grass-commit mailing list