[GRASS-SVN] r49755 - in grass/trunk/gui/wxpython: gui_core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 14 15:50:39 EST 2011


Author: martinl
Date: 2011-12-14 12:50:39 -0800 (Wed, 14 Dec 2011)
New Revision: 49755

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/gui_core/gselect.py
   grass/trunk/gui/wxpython/lmgr/frame.py
Log:
wxGUI: change location/mapset - don't show current mapset
      call `g.mapset` to switch location/mapset
      (merge r49754 from devbr6)


Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2011-12-14 20:36:11 UTC (rev 49754)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2011-12-14 20:50:39 UTC (rev 49755)
@@ -148,14 +148,14 @@
         
         self.element1 = MapsetSelect(parent = self.panel, id = wx.ID_ANY,
                                      size = globalvar.DIALOG_GSELECT_SIZE,
-                                     setItems = False)
+                                     setItems = False, skipCurrent = True)
         
         self.PostInit()
         
-        self.__Layout()
+        self._layout()
         self.SetMinSize(self.GetSize())
 
-    def __Layout(self):
+    def _layout(self):
         """!Do layout"""
         self.dataSizer.Add(self.element, proportion = 0,
                            flag = wx.EXPAND | wx.ALL, border = 1)
@@ -176,7 +176,7 @@
         
         if location:
             dbase = grass.gisenv()['GISDBASE']
-            self.element1.SetItems(GetListOfMapsets(dbase, location, selectable = True))
+            self.element1.UpdateItems(dbase = dbase, location = location)
             self.element1.SetSelection(0)
             mapset = self.element1.GetStringSelection()
         
@@ -199,7 +199,7 @@
         else:
             self.SetTitle(self.GetTitle() + ' <%s>' % grass.gisenv()['LOCATION_NAME'])
         
-        self.element = MapsetSelect(parent = self.panel, id = wx.ID_ANY,
+        self.element = MapsetSelect(parent = self.panel, id = wx.ID_ANY, skipCurrent = True,
                                     size = globalvar.DIALOG_GSELECT_SIZE)
         
         self.PostInit()

Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2011-12-14 20:36:11 UTC (rev 49754)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2011-12-14 20:50:39 UTC (rev 49755)
@@ -915,13 +915,15 @@
     """!Widget for selecting GRASS mapset"""
     def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_COMBOBOX_SIZE, 
                  gisdbase = None, location = None, setItems = True,
-                 searchPath = False, new = False, **kwargs):
+                 searchPath = False, new = False, skipCurrent = False, **kwargs):
         style = 0
         if not new:
             style = wx.CB_READONLY
+        
         super(MapsetSelect, self).__init__(parent, id, size = size, 
                                            style = style, **kwargs)
-        self.searchPath = searchPath
+        self.searchPath  = searchPath
+        self.skipCurrent = skipCurrent
         
         self.SetName("MapsetSelect")
         if not gisdbase:
@@ -953,13 +955,21 @@
      
     def _getMapsets(self):
         if self.searchPath:
-            return RunCommand('g.mapsets',
-                              read = True,
-                              flags = 'p',
-                              fs = 'newline').splitlines()
+            mlist = RunCommand('g.mapsets',
+                               read = True, flags = 'p',
+                               fs = 'newline').splitlines()
+        else:
+            mlist = GetListOfMapsets(self.gisdbase, self.location,
+                                     selectable = False)
         
-        return GetListOfMapsets(self.gisdbase, self.location, selectable = False)
-            
+        gisenv = grass.gisenv()
+        if self.skipCurrent and \
+                gisenv['LOCATION_NAME'] == self.location and \
+                gisenv['MAPSET'] in mlist:
+            mlist.remove(gisenv['MAPSET'])
+        
+        return mlist
+    
 class SubGroupSelect(wx.ComboBox):
     """!Widget for selecting subgroups"""
     def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE, 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2011-12-14 20:36:11 UTC (rev 49754)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2011-12-14 20:50:39 UTC (rev 49755)
@@ -592,26 +592,26 @@
         dlg = LocationDialog(parent = self)
         if dlg.ShowModal() == wx.ID_OK:
             location, mapset = dlg.GetValues()
-            if location and mapset:
-                ret = RunCommand("g.gisenv",
-                                 set = "LOCATION_NAME=%s" % location)
-                ret += RunCommand("g.gisenv",
-                                  set = "MAPSET=%s" % mapset)
-                if ret > 0:
-                    wx.MessageBox(parent = self,
-                                  message = _("Unable to switch to location <%(loc)s> mapset <%(mapset)s>.") % \
-                                      { 'loc' : location, 'mapset' : mapset },
-                                  caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
-                else:
-                    # close workspace
-                    self.OnWorkspaceClose()
-                    self.OnWorkspaceNew()
-                    wx.MessageBox(parent = self,
-                                  message = _("Current location is <%(loc)s>.\n"
-                                              "Current mapset is <%(mapset)s>.") % \
-                                      { 'loc' : location, 'mapset' : mapset },
-                                  caption = _("Info"), style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
-                    
+            dlg.Destroy()
+            
+            if not location or not mapset:
+                GError(parent = self,
+                       message = _("No location/mapset provided. Operation canceled."))
+                return # this should not happen
+            
+            if RunCommand('g.mapset', parent = self,
+                          location = location,
+                          mapset = mapset) != 0:
+                return # error reported
+            
+            # close workspace
+            self.OnWorkspaceClose()
+            self.OnWorkspaceNew()
+            GMessage(parent = self,
+                     message = _("Current location is <%(loc)s>.\n"
+                                 "Current mapset is <%(mapset)s>.") % \
+                         { 'loc' : location, 'mapset' : mapset })
+        
     def OnCreateMapset(self, event):
         """!Create new mapset"""
         dlg = wx.TextEntryDialog(parent = self,
@@ -639,16 +639,16 @@
         
         if dlg.ShowModal() == wx.ID_OK:
             mapset = dlg.GetMapset()
+            dlg.Destroy()
+            
             if not mapset:
                 GError(parent = self,
                        message = _("No mapset provided. Operation canceled."))
                 return
             
-            ret = RunCommand('g.mapset',
-                             parent = self,
-                             mapset = mapset)
-            
-            if ret == 0:
+            if RunCommand('g.mapset',
+                          parent = self,
+                          mapset = mapset) == 0:
                 GMessage(parent = self,
                          message = _("Current mapset is <%s>.") % mapset)
         



More information about the grass-commit mailing list