[GRASS-SVN] r68949 - in grass/trunk: gui/wxpython/core gui/wxpython/datacatalog gui/wxpython/gui_core lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 12 12:06:29 PDT 2016


Author: annakrat
Date: 2016-07-12 12:06:28 -0700 (Tue, 12 Jul 2016)
New Revision: 68949

Modified:
   grass/trunk/gui/wxpython/core/giface.py
   grass/trunk/gui/wxpython/datacatalog/__init__.py
   grass/trunk/gui/wxpython/datacatalog/tree.py
   grass/trunk/gui/wxpython/gui_core/forms.py
   grass/trunk/lib/python/script/core.py
Log:
wxGUI/datacatalog: add reprojection when copying

Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py	2016-07-12 18:53:16 UTC (rev 68948)
+++ grass/trunk/gui/wxpython/core/giface.py	2016-07-12 19:06:28 UTC (rev 68949)
@@ -285,7 +285,7 @@
         os.environ["GRASS_MESSAGE_FORMAT"] = orig
 
     def GetLayerList(self):
-        raise NotImplementedError()
+        return []
 
     def GetLayerTree(self):
         return None

Modified: grass/trunk/gui/wxpython/datacatalog/__init__.py
===================================================================
--- grass/trunk/gui/wxpython/datacatalog/__init__.py	2016-07-12 18:53:16 UTC (rev 68948)
+++ grass/trunk/gui/wxpython/datacatalog/__init__.py	2016-07-12 19:06:28 UTC (rev 68949)
@@ -2,4 +2,5 @@
     'catalog',
     'frame',
     'tree',
+    'dialogs'
 ]

Modified: grass/trunk/gui/wxpython/datacatalog/tree.py
===================================================================
--- grass/trunk/gui/wxpython/datacatalog/tree.py	2016-07-12 18:53:16 UTC (rev 68948)
+++ grass/trunk/gui/wxpython/datacatalog/tree.py	2016-07-12 19:06:28 UTC (rev 68949)
@@ -30,6 +30,7 @@
 from core.giface import StandaloneGrassInterface
 from core.treemodel import TreeModel, DictNode
 from gui_core.treeview import TreeView
+from datacatalog.dialogs import CatalogReprojectionDialog
 
 from grass.pydispatch.signal import Signal
 
@@ -97,25 +98,11 @@
     for node in reversed(nodesToRemove):
         model.RemoveNode(node)
 
-def getEnvironment(gisdbase, location, mapset):
-    """Creates environment to be passed in run_command for example.
-    Returns tuple with temporary file path and the environment. The user
-    of this function is responsile for deleting the file."""
-    tmp_gisrc_file = gscript.tempfile()
-    with open(tmp_gisrc_file, 'w') as f:
-        f.write('MAPSET: {mapset}\n'.format(mapset=mapset))
-        f.write('GISDBASE: {g}\n'.format(g=gisdbase))
-        f.write('LOCATION_NAME: {l}\n'.format(l=location))
-        f.write('GUI: text\n')
-    env = os.environ.copy()
-    env['GISRC'] = tmp_gisrc_file
-    return tmp_gisrc_file, env
 
-
 def getLocationTree(gisdbase, location, queue, mapsets=None):
     """Creates dictionary with mapsets, elements, layers for given location.
     Returns tuple with the dictionary and error (or None)"""
-    tmp_gisrc_file, env = getEnvironment(gisdbase, location, 'PERMANENT')
+    tmp_gisrc_file, env = gscript.create_environment(gisdbase, location, 'PERMANENT')
     env['GRASS_SKIP_MAPSET_OWNER_CHECK'] = '1'
 
     maps_dict = {}
@@ -176,7 +163,7 @@
 
     :param name: name of the map
     :param element: data type ('raster', 'raster_3d', and 'vector')
-    :param env environment created by function getEnvironment
+    :param env environment created by function gscript.create_environment
     """
     if not mapset:
         mapset = gscript.run_command('g.mapset', flags='p', env=env).strip()
@@ -591,7 +578,7 @@
     def OnRenameMap(self, event):
         """Rename layer with dialog"""
         old_name = self.selected_layer.label
-        gisrc, env = getEnvironment(
+        gisrc, env = gscript.create_environment(
             gisenv()['GISDBASE'],
             self.selected_location.label, mapset=self.selected_mapset.label)
         new_name = self._getNewMapName(
@@ -624,7 +611,7 @@
     def Rename(self, old, new):
         """Rename layer"""
         string = old + ',' + new
-        gisrc, env = getEnvironment(
+        gisrc, env = gscript.create_environment(
             gisenv()['GISDBASE'],
             self.selected_location.label, self.selected_mapset.label)
         label = _("Renaming map <{name}>...").format(name=string)
@@ -652,7 +639,7 @@
             GMessage(_("No map selected for copying."), parent=self)
             return
         if self.selected_location == self.copy_location:
-            gisrc, env = getEnvironment(
+            gisrc, env = gscript.create_environment(
                 gisenv()['GISDBASE'], self.selected_location.label, mapset=self.selected_mapset.label)
             new_name = self._getNewMapName(
                 _('New name'),
@@ -725,9 +712,15 @@
                     message=_("g.copy completed").format(cmd=cmd))
             gscript.try_remove(gisrc)
         else:
-            GError(
-                _("Failed to copy map: action is allowed only within the same location."),
-                parent=self)
+            if self.copy_type.label == 'raster_3d':
+                 GError(_("Reprojection is not implemented for 3D rasters"), parent=self)
+                 return
+            gisdbase = gisenv()['GISDBASE']
+            dlg = CatalogReprojectionDialog(self, self._giface, gisdbase, self.copy_location.label,
+                                            self.copy_mapset.label, self.copy_layer.label,
+                                            gisdbase, self.selected_location.label, self.selected_mapset.label,
+                                            etype=self.copy_type.label)
+            dlg.Show()
 
         # expand selected mapset
         self.ExpandNode(self.selected_mapset, recursive=True)
@@ -752,7 +745,7 @@
     def OnDeleteMap(self, event):
         """Delete layer or mapset"""
         name = self.selected_layer.label
-        gisrc, env = getEnvironment(
+        gisrc, env = gscript.create_environment(
             gisenv()['GISDBASE'],
             self.selected_location.label, self.selected_mapset.label)
         if self._confirmDialog(
@@ -894,30 +887,31 @@
         dlg.Destroy()
         return res
 
-    def _popupMenuLayer(self):
-        """Create popup menu for layers"""
-        menu = wx.Menu()
-        genv = gisenv()
+    def _isCurrent(self, genv):
         if self._restricted:
             currentMapset = currentLocation = False
             if self.selected_location.label == genv['LOCATION_NAME']:
                 currentLocation = True
                 if self.selected_mapset.label == genv['MAPSET']:
                     currentMapset = True
+            return currentLocation, currentMapset
         else:
-            currentMapset = currentLocation = True
+            return True, True
 
+    def _popupMenuLayer(self):
+        """Create popup menu for layers"""
+        menu = wx.Menu()
+        genv = gisenv()
+        currentLocation, currentMapset = self._isCurrent(genv)
+
         item = wx.MenuItem(menu, wx.NewId(), _("&Copy"))
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnCopyMap, item)
-        item.Enable(currentLocation)
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
-        if not(
-                currentLocation and self.copy_layer and self.selected_location ==
-                self.copy_location):
+        if not(currentLocation and self.copy_layer):
             item.Enable(False)
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Delete"))
@@ -944,11 +938,12 @@
         """Create popup menu for mapsets"""
         menu = wx.Menu()
         genv = gisenv()
+        currentLocation, currentMapset = self._isCurrent(genv)
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
-        if not (self.copy_layer and self.selected_location == self.copy_location):
+        if not(currentLocation and self.copy_layer):
             item.Enable(False)
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Switch mapset"))
@@ -966,7 +961,9 @@
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
-        if not (self.copy_layer and self.selected_location == self.copy_location):
+        genv = gisenv()
+        currentLocation, currentMapset = self._isCurrent(genv)
+        if not(currentLocation and self.copy_layer):
             item.Enable(False)
 
         self.PopupMenu(menu)

Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py	2016-07-12 18:53:16 UTC (rev 68948)
+++ grass/trunk/gui/wxpython/gui_core/forms.py	2016-07-12 19:06:28 UTC (rev 68949)
@@ -2076,6 +2076,9 @@
         pLocation = None
         pMapset = None
         for p in self.task.params:
+            if self.task.blackList['enabled'] and self.task.get_name() in self.task.blackList['items'] and \
+               p.get('name', '') in self.task.blackList['items'][self.task.get_name()]['params']:
+                continue
             guidep = p.get('guidependency', '')
 
             if guidep:

Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2016-07-12 18:53:16 UTC (rev 68948)
+++ grass/trunk/lib/python/script/core.py	2016-07-12 19:06:28 UTC (rev 68949)
@@ -1570,6 +1570,21 @@
     return True
 
 
+def create_environment(gisdbase, location, mapset):
+    """Creates environment to be passed in run_command for example.
+    Returns tuple with temporary file path and the environment. The user
+    of this function is responsile for deleting the file."""
+    tmp_gisrc_file = tempfile()
+    with open(tmp_gisrc_file, 'w') as f:
+        f.write('MAPSET: {mapset}\n'.format(mapset=mapset))
+        f.write('GISDBASE: {g}\n'.format(g=gisdbase))
+        f.write('LOCATION_NAME: {l}\n'.format(l=location))
+        f.write('GUI: text\n')
+    env = os.environ.copy()
+    env['GISRC'] = tmp_gisrc_file
+    return tmp_gisrc_file, env
+
+
 if __name__ == '__main__':
     import doctest
     doctest.testmod()



More information about the grass-commit mailing list