[GRASS-SVN] r42681 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 30 07:59:42 EDT 2010


Author: aghisla
Date: 2010-06-30 11:59:42 +0000 (Wed, 30 Jun 2010)
New Revision: 42681

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py
Log:
Backport of develbranch6 r42307 and trunk r42308. Fixes ticket #1051.

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py	2010-06-30 09:53:21 UTC (rev 42680)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py	2010-06-30 11:59:42 UTC (rev 42681)
@@ -1722,28 +1722,28 @@
         
         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 = grassenv.GetGRASSVariable('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)
 
         self.mapsetlb = CheckListMapset(parent=self)
-        self.mapsetlb.LoadData(self.all_mapsets)
+        self.mapsetlb.LoadData(self.all_mapsets_ordered)
         
         sizer.Add(item=self.mapsetlb, proportion=1,
                   flag=wx.ALL | wx.EXPAND, border=5)
 
         # 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,
@@ -1774,7 +1774,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
@@ -1804,14 +1804,7 @@
         locationPath = os.path.join(grassenv.GetGRASSVariable('GISDBASE'),
                                     grassenv.GetGRASSVariable('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)
@@ -1830,6 +1823,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/releasebranch_6_4/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py	2010-06-30 09:53:21 UTC (rev 42680)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py	2010-06-30 11:59:42 UTC (rev 42681)
@@ -198,7 +198,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
@@ -224,6 +224,43 @@
         except:
             raise gcmd.CmdError(_('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:
         # cmd = gcmd.Command(['g.mapsets', '-p'])
         cmd = subprocess.Popen(['g.mapsets' + globalvar.EXT_BIN, '-p'],
@@ -238,6 +275,8 @@
         except:
             raise gcmd.CmdError(_('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