[GRASS-SVN] r53825 - in grass/trunk/gui/wxpython: gui_core mapdisp

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 14 10:21:10 PST 2012


Author: martinl
Date: 2012-11-14 10:21:09 -0800 (Wed, 14 Nov 2012)
New Revision: 53825

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
Log:
wxGUI/mapdisplay: add 'Save computational region to named region' to the zoom menu


Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2012-11-14 17:44:41 UTC (rev 53824)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2012-11-14 18:21:09 UTC (rev 53825)
@@ -497,14 +497,14 @@
     return dlg
 
 class SavedRegion(wx.Dialog):
-    def __init__(self, parent, id = wx.ID_ANY, title = "", loadsave = 'load',
+    def __init__(self, parent, title, id = wx.ID_ANY, loadsave = 'load',
                  **kwargs):
-        """!Loading and saving of display extents to saved region file
+        """!Loading or saving of display extents to saved region file
 
         @param loadsave load or save region?
         """
         wx.Dialog.__init__(self, parent, id, title, **kwargs)
-
+        
         self.loadsave = loadsave
         self.wind = ''
         
@@ -526,12 +526,12 @@
         selection.SetFocus()
         selection.Bind(wx.EVT_TEXT, self.OnRegion)
         
-        sizer.Add(item = box, proportion = 0, flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
+        sizer.Add(item = box, proportion = 0, flag = wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
                   border = 5)
         
         line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
         sizer.Add(item = line, proportion = 0,
-                  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 5)
+                  flag = wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border = 5)
         
         btnsizer = wx.StdDialogButtonSizer()
         
@@ -551,6 +551,10 @@
         
     def OnRegion(self, event):
         self.wind = event.GetString()
+
+    def GetName(self):
+        """!Return region name"""
+        return self.wind
     
 class DecorationDialog(wx.Dialog):
     """!Controls setting options and displaying/hiding map overlay

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2012-11-14 17:44:41 UTC (rev 53824)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2012-11-14 18:21:09 UTC (rev 53825)
@@ -1271,40 +1271,34 @@
         """
         self.MapWindow.DisplayToWind()
  
-    def SaveDisplayRegion(self, event):
+    def OnSaveDisplayRegion(self, event):
         """!Save display extents to named region file.
         """
-        self.MapWindow.SaveDisplayRegion()
+        self.MapWindow.SaveRegion(display = True)
+
+    def OnSaveWindRegion(self, event):
+        """!Save computational region to named region file.
+        """
+        self.MapWindow.SaveRegion(display = False)
         
     def OnZoomMenu(self, event):
         """!Popup Zoom menu
         """
         point = wx.GetMousePosition()
         zoommenu = wx.Menu()
-        # Add items to the menu
-
-        zoomwind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to computational region'))
-        zoommenu.AppendItem(zoomwind)
-        self.Bind(wx.EVT_MENU, self.OnZoomToWind, zoomwind)
-
-        zoomdefault = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to default region'))
-        zoommenu.AppendItem(zoomdefault)
-        self.Bind(wx.EVT_MENU, self.OnZoomToDefault, zoomdefault)
-
-        zoomsaved = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to saved region'))
-        zoommenu.AppendItem(zoomsaved)
-        self.Bind(wx.EVT_MENU, self.OnZoomToSaved, zoomsaved)
-
-        savewind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Set computational region from display extent'))
-        zoommenu.AppendItem(savewind)
-        self.Bind(wx.EVT_MENU, self.OnDisplayToWind, savewind)
-
-        savezoom = wx.MenuItem(zoommenu, wx.ID_ANY, _('Save display geometry to named region'))
-        zoommenu.AppendItem(savezoom)
-        self.Bind(wx.EVT_MENU, self.SaveDisplayRegion, savezoom)
-
-        # Popup the menu. If an item is selected then its handler
-        # will be called before PopupMenu returns.
+        
+        for label, handler in ((_('Zoom to computational region'), self.OnZoomToWind),
+                               (_('Zoom to default region'), self.OnZoomToDefault),
+                               (_('Zoom to saved region'), self.OnZoomToSaved),
+                               (_('Set computational region from display extent'), self.OnDisplayToWind),
+                               (_('Save display geometry to named region'), self.OnSaveDisplayRegion),
+                               (_('Save computational region to named region'), self.OnSaveWindRegion)):
+            mid = wx.MenuItem(zoommenu, wx.ID_ANY, label)
+            zoommenu.AppendItem(mid)
+            self.Bind(wx.EVT_MENU, handler, mid)
+            
+        # Popup the menu. If an item is selected then its handler will
+        # be called before PopupMenu returns.
         self.PopupMenu(zoommenu)
         zoommenu.Destroy()
 

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2012-11-14 17:44:41 UTC (rev 53824)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2012-11-14 18:21:09 UTC (rev 53825)
@@ -1696,20 +1696,20 @@
         """
         dlg = SavedRegion(parent = self,
                           title = _("Zoom to saved region extents"),
-                          loadsave='load')
+                          loadsave = 'load')
         
-        if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
+        if dlg.ShowModal() == wx.ID_CANCEL or not dlg.GetName():
             dlg.Destroy()
             return
         
-        if not grass.find_file(name = dlg.wind, element = 'windows')['name']:
+        if not grass.find_file(name = dlg.GetName(), element = 'windows')['name']:
             wx.MessageBox(parent = self,
-                          message = _("Region <%s> not found. Operation canceled.") % dlg.wind,
+                          message = _("Region <%s> not found. Operation canceled.") % dlg.GetName(),
                           caption = _("Error"), style = wx.ICON_ERROR | wx.OK | wx.CENTRE)
             dlg.Destroy()
             return
         
-        self.Map.GetRegion(regionName = dlg.wind,
+        self.Map.GetRegion(regionName = dlg.GetName(),
                            update = True)
         
         dlg.Destroy()
@@ -1721,34 +1721,54 @@
         
         self.UpdateMap()
                 
-    def SaveDisplayRegion(self):
-        """!Save display extents to named region file.
+    def SaveRegion(self, display = True):
+        """!Save display extents/compulational region to named region
+        file.
+
+        @param display True for display extends otherwise computational region
         """
-        dlg = SavedRegion(parent = self,
-                          title = _("Save display extents to region file"),
-                          loadsave='save')
+        if display:
+            title = _("Save display extents to region file")
+        else:
+            title = _("Save computational region to region file")
         
-        if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
+        dlg = SavedRegion(parent = self, title = title, loadsave = 'save')
+        if dlg.ShowModal() == wx.ID_CANCEL or not dlg.GetName():
             dlg.Destroy()
             return
         
         # test to see if it already exists and ask permission to overwrite
-        if grass.find_file(name = dlg.wind, element = 'windows')['name']:
+        if grass.find_file(name = dlg.GetName(), element = 'windows')['name']:
             overwrite = wx.MessageBox(parent = self,
                                       message = _("Region file <%s> already exists. "
-                                                  "Do you want to overwrite it?") % (dlg.wind),
+                                                  "Do you want to overwrite it?") % (dlg.GetName()),
                                       caption = _("Warning"), style = wx.YES_NO | wx.CENTRE)
-            if (overwrite == wx.YES):
-                self.SaveRegion(dlg.wind)
+            if overwrite != wx.YES:
+                dlg.Destroy()
+                return
+        
+        if display:
+            self._saveDisplayRegion(dlg.GetName())
         else:
-            self.SaveRegion(dlg.wind)
+            self._saveCompRegion(dlg.GetName())
         
         dlg.Destroy()
+
+    def _saveCompRegion(self, name):
+        """!Save region settings to region file
         
-    def SaveRegion(self, wind):
-        """!Save region settings
+        @param name region name
+        """
+        RunCommand('g.region',
+                   overwrite = True,
+                   parent = self,
+                   flags = 'u',
+                   save = name)
         
-        @param wind region name
+    def _saveDisplayRegion(self, name):
+        """!Save display extents to region file
+        
+        @param name region name
         """
         new = self.Map.GetCurrentRegion()
         
@@ -1766,7 +1786,7 @@
                    w = new['w'],
                    rows = int(new['rows']),
                    cols = int(new['cols']),
-                   save = wind)
+                   save = name)
         
         if tmpreg:
             os.environ["GRASS_REGION"] = tmpreg



More information about the grass-commit mailing list