[GRASS-SVN] r30751 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 27 06:39:11 EDT 2008


Author: martinl
Date: 2008-03-27 06:39:10 -0400 (Thu, 27 Mar 2008)
New Revision: 30751

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxGUI: "Zoom to default region" add to the "Zoom menu", see trac #106


Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2008-03-27 08:43:42 UTC (rev 30750)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2008-03-27 10:39:10 UTC (rev 30751)
@@ -5,7 +5,8 @@
 
 List of classes:
  - NewVectorDialog
-
+ - SavedRegion
+ 
 (C) 2008 by the GRASS Development Team
 
 This program is free software under the GNU General Public
@@ -134,3 +135,62 @@
             return outmap + '@' + grassenv.GetGRASSVariable('MAPSET')
 
     return None
+
+class SavedRegion(wx.Dialog):
+    def __init__(self, parent, id, title="", pos=wx.DefaultPosition, size=wx.DefaultSize,
+                 style=wx.DEFAULT_DIALOG_STYLE,
+                 loadsave='load'):
+        """
+        Loading and saving of display extents to saved region file
+        """
+        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
+
+        self.loadsave = loadsave
+        self.wind = ''
+
+        sizer = wx.BoxSizer(wx.VERTICAL)
+
+        box = wx.BoxSizer(wx.HORIZONTAL)
+        if loadsave == 'load':
+            label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Load region:"))
+            box.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
+            self.selection = gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
+                                            type='windows')
+            box.Add(item=self.selection, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
+            self.selection.Bind(wx.EVT_TEXT, self.OnSelection)
+
+        elif loadsave == 'save':
+            label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Save region:"))
+            box.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
+            self.textentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="",
+                                         size=globalvar.DIALOG_TEXTCTRL_SIZE)
+            box.Add(item=self.textentry, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
+            self.textentry.Bind(wx.EVT_TEXT, self.OnText)
+
+        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)
+
+        btnsizer = wx.StdDialogButtonSizer()
+
+        btn = wx.Button(self, wx.ID_OK)
+        btn.SetDefault()
+        btnsizer.AddButton(btn)
+
+        btn = wx.Button(self, wx.ID_CANCEL)
+        btnsizer.AddButton(btn)
+        btnsizer.Realize()
+
+        sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
+
+        self.SetSizer(sizer)
+        sizer.Fit(self)
+
+    def OnSelection(self, event):
+        self.wind = event.GetString()
+
+    def OnText(self, event):
+        self.wind = event.GetString()

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-27 08:43:42 UTC (rev 30750)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-27 10:39:10 UTC (rev 30751)
@@ -7,7 +7,6 @@
     * MapFrame
     * DecDialog
     * TextDialog
-    * SavedRegion
     * MapApp
 
 PURPOSE:   GIS map display canvas, with toolbar for various display
@@ -63,6 +62,7 @@
 import profile
 import globalvar
 import utils
+import gdialogs
 from digit import DigitCategoryDialog as DigitCategoryDialog
 from digit import DigitZBulkDialog    as DigitZBulkDialog
 from digit import GV_LINES            as Digit_Lines_Type
@@ -1981,7 +1981,7 @@
     def ZoomToWind(self, event):
         """
         Set display geometry to match computational
-        region extents (set with g.region)
+        region settings (set with g.region)
         """
 
         self.Map.region = self.Map.GetRegion()
@@ -1994,6 +1994,19 @@
 
         self.parent.StatusbarUpdate()
 
+    def ZoomToDefault(self, event):
+        """Set display geometry to match default
+        region settings"""
+        self.Map.region = self.Map.GetRegion(default=True)
+        self.Map.AdjustRegion() # aling region extent to the display
+
+        self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
+                         self.Map.region['e'], self.Map.region['w'])
+
+        self.UpdateMap()
+
+        self.parent.StatusbarUpdate()
+        
     def DisplayToWind(self, event):
         """
         Set computational region (WIND file) to
@@ -2027,10 +2040,10 @@
 
         zoomreg = {}
 
-        dlg = SavedRegion(self, wx.ID_ANY, "Zoom to saved region extents",
-                          pos=wx.DefaultPosition, size=wx.DefaultSize,
-                          style=wx.DEFAULT_DIALOG_STYLE,
-                          loadsave='load')
+        dlg = gdialogs.SavedRegion(self, wx.ID_ANY, _("Zoom to saved region extents"),
+                                   pos=wx.DefaultPosition, size=wx.DefaultSize,
+                                   style=wx.DEFAULT_DIALOG_STYLE,
+                                   loadsave='load')
 
         if dlg.ShowModal() == wx.ID_CANCEL:
             dlg.Destroy()
@@ -2061,10 +2074,10 @@
         Save display extents to named region file.
         """
 
-        dlg = SavedRegion(self, wx.ID_ANY, "Save display extents to region file",
-                          pos=wx.DefaultPosition, size=wx.DefaultSize,
-                          style=wx.DEFAULT_DIALOG_STYLE,
-                          loadsave='save')
+        dlg = gdialogs.SavedRegion(self, wx.ID_ANY, "Save display extents to region file",
+                                   pos=wx.DefaultPosition, size=wx.DefaultSize,
+                                   style=wx.DEFAULT_DIALOG_STYLE,
+                                   loadsave='save')
         if dlg.ShowModal() == wx.ID_CANCEL:
             dlg.Destroy()
             return
@@ -3366,14 +3379,18 @@
         zoommenu.AppendItem(zoomwind)
         self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToWind, zoomwind)
 
-        savewind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Set computational region from display'))
-        zoommenu.AppendItem(savewind)
-        self.Bind(wx.EVT_MENU, self.MapWindow.DisplayToWind, savewind)
+        zoomdefault = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to default region'))
+        zoommenu.AppendItem(zoomdefault)
+        self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToDefault, zoomdefault)
 
         zoomsaved = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to saved region'))
         zoommenu.AppendItem(zoomsaved)
         self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToSaved, zoomsaved)
 
+        savewind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Set computational region from display'))
+        zoommenu.AppendItem(savewind)
+        self.Bind(wx.EVT_MENU, self.MapWindow.DisplayToWind, savewind)
+
         savezoom = wx.MenuItem(zoommenu, wx.ID_ANY, _('Save display geometry to named region'))
         zoommenu.AppendItem(savezoom)
         self.Bind(wx.EVT_MENU, self.MapWindow.SaveDisplayRegion, savezoom)
@@ -3592,66 +3609,6 @@
 
         dlg.Destroy()
 
-
-class SavedRegion(wx.Dialog):
-    def __init__(self, parent, id, title="", pos=wx.DefaultPosition, size=wx.DefaultSize,
-                 style=wx.DEFAULT_DIALOG_STYLE,
-                 loadsave='load'):
-        """
-        Loading and saving of display extents to saved region file
-        """
-        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
-
-        self.loadsave = loadsave
-        self.wind = ''
-
-        sizer = wx.BoxSizer(wx.VERTICAL)
-
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        if loadsave == 'load':
-            label = wx.StaticText(self, wx.ID_ANY, "Load region:")
-            box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-            self.selection = gselect.Select(self, id=wx.ID_ANY, size=(300,-1),
-                                              type='windows')
-            box.Add(self.selection, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-            self.selection.Bind(wx.EVT_TEXT, self.onSelection)
-
-        elif loadsave == 'save':
-            label = wx.StaticText(self, wx.ID_ANY, "Save region:")
-            box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-            self.textentry = wx.TextCtrl(self, wx.ID_ANY, "", size=(200,-1))
-            box.Add(self.textentry, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-            self.textentry.Bind(wx.EVT_TEXT, self.onText)
-
-        sizer.Add(item=box, proportion=0, flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
-                  border=5)
-
-        line = wx.StaticLine(self, 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)
-
-        btnsizer = wx.StdDialogButtonSizer()
-
-        btn = wx.Button(self, wx.ID_OK)
-        btn.SetDefault()
-        btnsizer.AddButton(btn)
-
-        btn = wx.Button(self, wx.ID_CANCEL)
-        btnsizer.AddButton(btn)
-        btnsizer.Realize()
-
-
-        sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
-
-        self.SetSizer(sizer)
-        sizer.Fit(self)
-
-    def onSelection(self, event):
-        self.wind = event.GetString()
-
-    def onText(self, event):
-        self.wind = event.GetString()
-
 class MapApp(wx.App):
     """
     MapApp class

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-27 08:43:42 UTC (rev 30750)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-27 10:39:10 UTC (rev 30751)
@@ -297,7 +297,7 @@
 
         return self.wind
         
-    def __adjustRegion(self):
+    def AdjustRegion(self):
         """
         Adjusts display resolution to match monitor size in pixels.
         Maintains constant display resolution, not related to computational
@@ -314,7 +314,7 @@
         self.region['cols']  = round(mapwidth / self.region["ewres"])
         self.region['cells'] = self.region['rows'] * self.region['cols']
 
-        Debug.msg (3, "Map.__adjustRegion(): %s" % self.region)
+        Debug.msg (3, "Map.AdjustRegion(): %s" % self.region)
 
         return self.region
 
@@ -394,7 +394,7 @@
             return False
 
     def GetRegion(self, rast=None, vect=None,
-                  n=None, s=None, e=None, w=None):
+                  n=None, s=None, e=None, w=None, default=False):
         """
         Get region settings
 
@@ -402,9 +402,11 @@
 
         @param rast raster name or None
         @param vect vector name or None
+        @param n,s,e,w force extent
+        @param default force default region settings
         
         @return region settings as directory, e.g. {
-        "n":"4928010", "s":"4913700", "w":"589980",...}
+        'n':'4928010', 's':'4913700', 'w':'589980',...}
         """
 
         region = {}
@@ -415,6 +417,9 @@
         # do not update & shell style output
         cmdList = ["g.region", "-u", "-g", "-p", "-c"]
 
+        if default:
+            cmdList.append('-d')
+            
         if n:
             cmdList.append('n=%s' % n)
         if s:
@@ -470,8 +475,8 @@
         """
         grass_region = ""
 
-        # adjust region settigns to match monitor
-        self.region = self.__adjustRegion()
+        # adjust region settings to match monitor
+        self.region = self.AdjustRegion()
 
         #        newextents = self.AlignResolution()
         #        self.region['n'] = newextents['n']



More information about the grass-commit mailing list