[GRASS-SVN] r68393 - in grass/trunk/gui/wxpython: datacatalog lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 7 09:52:41 PDT 2016


Author: annakrat
Date: 2016-05-07 09:52:41 -0700 (Sat, 07 May 2016)
New Revision: 68393

Modified:
   grass/trunk/gui/wxpython/datacatalog/catalog.py
   grass/trunk/gui/wxpython/datacatalog/frame.py
   grass/trunk/gui/wxpython/datacatalog/tree.py
   grass/trunk/gui/wxpython/lmgr/frame.py
Log:
wxGUI/datacatalog: add option to switch mapset

Modified: grass/trunk/gui/wxpython/datacatalog/catalog.py
===================================================================
--- grass/trunk/gui/wxpython/datacatalog/catalog.py	2016-05-07 11:38:08 UTC (rev 68392)
+++ grass/trunk/gui/wxpython/datacatalog/catalog.py	2016-05-07 16:52:41 UTC (rev 68393)
@@ -33,6 +33,8 @@
                  title=_("Data catalog"), name='catalog', **kwargs):
         """Panel constructor  """
         self.showNotification = Signal('DataCatalog.showNotification')
+        self.changeMapset = Signal('DataCatalog.changeMapset')
+        self.changeLocation = Signal('DataCatalog.changeLocation')
         self.parent = parent
         self.baseTitle = title
         wx.Panel.__init__(self, parent=parent, id=id, **kwargs)
@@ -48,6 +50,8 @@
         self.thread = gThread()
         self._loaded = False
         self.tree.showNotification.connect(self.showNotification)
+        self.tree.changeMapset.connect(self.changeMapset)
+        self.tree.changeLocation.connect(self.changeLocation)
 
         # some layout
         self._layout()

Modified: grass/trunk/gui/wxpython/datacatalog/frame.py
===================================================================
--- grass/trunk/gui/wxpython/datacatalog/frame.py	2016-05-07 11:38:08 UTC (rev 68392)
+++ grass/trunk/gui/wxpython/datacatalog/frame.py	2016-05-07 16:52:41 UTC (rev 68393)
@@ -23,6 +23,7 @@
 
 from core.utils import _
 from core.globalvar import ICONDIR
+from core.gcmd import RunCommand, GMessage
 from datacatalog.tree import DataCatalogTree
 from datacatalog.toolbars import DataCatalogToolbar
 
@@ -53,6 +54,12 @@
         self.tree = DataCatalogTree(parent=self.panel, giface=self._giface)
         self.tree.InitTreeItems()
         self.tree.ExpandCurrentMapset()
+        self.tree.changeMapset.connect(lambda mapset:
+                                       self.ChangeLocationMapset(location=None,
+                                                                 mapset=mapset))
+        self.tree.changeLocation.connect(lambda mapset, location:
+                                         self.ChangeLocationMapset(location=location,
+                                                                   mapset=mapset))
 
         # buttons
         self.btnClose = wx.Button(parent=self.panel, id=wx.ID_CLOSE)
@@ -101,3 +108,20 @@
     def SetRestriction(self, restrict):
         """Allow editing other mapsets or restrict editing to current mapset"""
         self.tree.SetRestriction(restrict)
+
+    def ChangeLocationMapset(self, mapset, location=None):
+        """Change mapset or location"""
+        if location:
+            if RunCommand('g.mapset', parent=self,
+                          location=location,
+                          mapset=mapset) == 0:
+                GMessage(parent=self,
+                         message=_("Current location is <%(loc)s>.\n"
+                                   "Current mapset is <%(mapset)s>.") %
+                         {'loc': location, 'mapset': mapset})
+        else:
+            if RunCommand('g.mapset',
+                          parent=self,
+                          mapset=mapset) == 0:
+                GMessage(parent=self,
+                         message=_("Current mapset is <%s>.") % mapset)

Modified: grass/trunk/gui/wxpython/datacatalog/tree.py
===================================================================
--- grass/trunk/gui/wxpython/datacatalog/tree.py	2016-05-07 11:38:08 UTC (rev 68392)
+++ grass/trunk/gui/wxpython/datacatalog/tree.py	2016-05-07 16:52:41 UTC (rev 68393)
@@ -218,6 +218,8 @@
             id=wx.ID_ANY,
             style=style)
         self.showNotification = Signal('Tree.showNotification')
+        self.changeMapset = Signal('Tree.changeMapset')
+        self.changeLocation = Signal('Tree.changeLocation')
         self.parent = parent
         self.contextMenu.connect(self.OnRightClick)
         self.itemActivated.connect(self.OnDoubleClick)
@@ -776,6 +778,14 @@
             else:
                 event.Veto()
 
+    def OnSwitchLocationMapset(self, event):
+        genv = gisenv()
+        if self.selected_location.label == genv['LOCATION_NAME']:
+            self.changeMapset.emit(mapset=self.selected_mapset.label)
+        else:
+            self.changeLocation.emit(mapset=self.selected_mapset.label, location=self.selected_location.label)
+        self.ExpandCurrentMapset()
+
     def _getNewMapName(self, message, title, value, element, mapset, env):
         """Dialog for simple text entry"""
         dlg = NameEntryDialog(parent=self, message=message, caption=title,
@@ -845,6 +855,7 @@
     def _popupMenuMapset(self):
         """Create popup menu for mapsets"""
         menu = wx.Menu()
+        genv = gisenv()
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
@@ -852,6 +863,12 @@
         if not (self.copy_layer and self.selected_location == self.copy_location):
             item.Enable(False)
 
+        item = wx.MenuItem(menu, wx.NewId(), _("&Switch mapset"))
+        menu.AppendItem(item)
+        self.Bind(wx.EVT_MENU, self.OnSwitchLocationMapset, item)
+        if (self.selected_location.label == genv['LOCATION_NAME']
+                and self.selected_mapset.label == genv['MAPSET']):
+            item.Enable(False)
         self.PopupMenu(menu)
         menu.Destroy()
 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2016-05-07 11:38:08 UTC (rev 68392)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2016-05-07 16:52:41 UTC (rev 68393)
@@ -371,6 +371,8 @@
             parent=self.notebook, giface=self._giface)
         self.datacatalog.showNotification.connect(
             lambda message: self.SetStatusText(message))
+        self.datacatalog.changeMapset.connect(lambda mapset: self.ChangeMapset(mapset))
+        self.datacatalog.changeLocation.connect(lambda mapset, location: self.ChangeLocation(location, mapset))
         self.notebook.AddPage(
             page=self.datacatalog,
             text=_("Data"),
@@ -1019,19 +1021,21 @@
                     message=_(
                         "No location/mapset provided. Operation canceled."))
                 return  # this should not happen
+            self.ChangeLocation(location, mapset)
 
-            if RunCommand('g.mapset', parent=self,
-                          location=location,
-                          mapset=mapset) != 0:
-                return  # error reported
+    def ChangeLocation(self, location, mapset):
+        if RunCommand('g.mapset', parent=self,
+                      location=location,
+                      mapset=mapset) != 0:
+            return  # error reported
 
-            # close current workspace and create new one
-            self.OnWorkspaceClose()
-            self.OnWorkspaceNew()
-            GMessage(parent=self,
-                     message=_("Current location is <%(loc)s>.\n"
-                               "Current mapset is <%(mapset)s>.") %
-                     {'loc': location, 'mapset': mapset})
+        # close current workspace and create new one
+        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"""
@@ -1066,17 +1070,20 @@
                 GError(parent=self,
                        message=_("No mapset provided. Operation canceled."))
                 return
+            self.ChangeMapset(mapset)
 
-            if RunCommand('g.mapset',
-                          parent=self,
-                          mapset=mapset) == 0:
-                GMessage(parent=self,
-                         message=_("Current mapset is <%s>.") % mapset)
+    def ChangeMapset(self, mapset):
+        """Change current mapset and update map display title"""
+        if RunCommand('g.mapset',
+                      parent=self,
+                      mapset=mapset) == 0:
+            GMessage(parent=self,
+                     message=_("Current mapset is <%s>.") % mapset)
 
-                dispId = 1
-                for display in self.GetMapDisplay(onlyCurrent=False):
-                    display.SetTitleNumber(dispId)  # TODO: signal ?
-                    dispId += 1
+            dispId = 1
+            for display in self.GetMapDisplay(onlyCurrent=False):
+                display.SetTitleNumber(dispId)  # TODO: signal ?
+                dispId += 1
 
     def OnChangeCWD(self, event=None, cmd=None):
         """Change current working directory



More information about the grass-commit mailing list