浏览代码

wxGUI: save named region - clean up

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38320 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 16 年之前
父节点
当前提交
10bd763dc3
共有 3 个文件被更改,包括 59 次插入80 次删除
  1. 33 38
      gui/wxpython/gui_modules/gdialogs.py
  2. 25 38
      gui/wxpython/gui_modules/mapdisp_window.py
  3. 1 4
      gui/wxpython/gui_modules/render.py

+ 33 - 38
gui/wxpython/gui_modules/gdialogs.py

@@ -212,66 +212,61 @@ def CreateNewVector(parent, cmd, title=_('Create new vector map'),
     return (None, dlg.addbox.IsChecked())
 
 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
+    def __init__(self, parent, id = wx.ID_ANY, title="", loadsave='load',
+                 **kwargs):
+        """!Loading and saving of display extents to saved region file
+
+        @param loadsave load or save region?
         """
-        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
+        wx.Dialog.__init__(self, parent, id, title, **kwargs)
 
         self.loadsave = loadsave
         self.wind = ''
-
+        
         sizer = wx.BoxSizer(wx.VERTICAL)
-
+        
         box = wx.BoxSizer(wx.HORIZONTAL)
+        label = wx.StaticText(parent=self, id=wx.ID_ANY)
+        box.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
         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')
-            self.selection.SetFocus()
-            box.Add(item=self.selection, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
-            self.selection.Bind(wx.EVT_TEXT, self.OnSelection)
-
+            label.SetLabel(_("Load region:"))
+            selection = gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
+                                       type='windows')
         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)
-            self.textentry.SetFocus()
-            box.Add(item=self.textentry, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
-            self.textentry.Bind(wx.EVT_TEXT, self.OnText)
-
+            label.SetLabel(_("Save region:"))
+            selection = gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
+                                       type='windows', mapsets = [grass.gisenv()['MAPSET']])
+        
+        box.Add(item=selection, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
+        selection.SetFocus()
+        selection.Bind(wx.EVT_TEXT, self.OnRegion)
+        
         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 = wx.Button(parent = self, id = wx.ID_OK)
         btn.SetDefault()
         btnsizer.AddButton(btn)
-
-        btn = wx.Button(self, wx.ID_CANCEL)
+        
+        btn = wx.Button(parent = self, id = 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.Layout()
+        
+    def OnRegion(self, event):
         self.wind = event.GetString()
-
+    
 class DecorationDialog(wx.Dialog):
     """
     Controls setting options and displaying/hiding map overlay decorations

+ 25 - 38
gui/wxpython/gui_modules/mapdisp_window.py

@@ -2620,19 +2620,22 @@ class BufferedWindow(MapWindow, wx.Window):
         """!Set display geometry to match extents in
         saved region file
         """
-        dlg = gdialogs.SavedRegion(parent = self, id = wx.ID_ANY,
+        dlg = gdialogs.SavedRegion(parent = self,
                                    title = _("Zoom to saved region extents"),
-                                   pos=wx.DefaultPosition, size=wx.DefaultSize,
-                                   style=wx.DEFAULT_DIALOG_STYLE,
                                    loadsave='load')
         
-        if dlg.ShowModal() == wx.ID_CANCEL:
+        if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
             dlg.Destroy()
             return
         
-        wind = dlg.wind
+        if not grass.find_file(name = dlg.wind, element = 'windows')['name']:
+            wx.MessageBox(parent = self,
+                          message = _("Region <%s> not found. Operation canceled.") % dlg.wind,
+                          caption = _("Error"), style = wx.ICON_ERROR | wx.OK | wx.CENTRE)
+            dlg.Destroy()
+            return
         
-        self.Map.GetRegion(regionName = wind,
+        self.Map.GetRegion(regionName = dlg.wind,
                            update = True)
         
         dlg.Destroy()
@@ -2649,49 +2652,33 @@ class BufferedWindow(MapWindow, wx.Window):
         Save display extents to named region file.
         """
 
-        dlg = gdialogs.SavedRegion(self, wx.ID_ANY, "Save display extents to region file",
-                                   pos=wx.DefaultPosition, size=wx.DefaultSize,
-                                   style=wx.DEFAULT_DIALOG_STYLE,
+        dlg = gdialogs.SavedRegion(parent = self,
+                                   title = _("Save display extents to region file"),
                                    loadsave='save')
-        if dlg.ShowModal() == wx.ID_CANCEL:
+        
+        if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
             dlg.Destroy()
             return
 
-        wind = dlg.wind
-
         # test to see if it already exists and ask permission to overwrite
-        windpath = os.path.join(self.Map.env["GISDBASE"], self.Map.env["LOCATION_NAME"],
-                                self.Map.env["MAPSET"],"windows",wind)
-
-        if windpath and not os.path.exists(windpath):
-            self.SaveRegion(wind)
-        elif windpath and os.path.exists(windpath):
-            overwrite = wx.MessageBox(_("Region file <%s> already exists. "
-                                        "Do you want to overwrite it?") % (wind),
-                                      _("Warning"), wx.YES_NO)
+        if grass.find_file(name = dlg.wind, element = 'windows')['name']:
+            overwrite = wx.MessageBox(parent = self,
+                                      message = _("Region file <%s> already exists. "
+                                                  "Do you want to overwrite it?") % (dlg.wind),
+                                      caption = _("Warning"), style = wx.YES_NO | wx.CENTRE)
             if (overwrite == wx.YES):
-                self.SaveRegion(wind)
+                self.SaveRegion(dlg.wind)
         else:
-            pass
-
+            self.SaveRegion(dlg.wind)
+        
         dlg.Destroy()
 
     def SaveRegion(self, wind):
-        """!
-        Save region settings
-        """
-        new = self.Map.AlignResolution()
+        """!Save region settings
 
-        cmdRegion = ["g.region",
-                     "-u",
-                     "n=%f" % new['n'],
-                     "s=%f" % new['s'],
-                     "e=%f" % new['e'],
-                     "w=%f" % new['w'],
-                     "rows=%d" % new['rows'],
-                     "cols=%d" % new['cols'],
-                     "save=%s" % wind,
-                     "--o"]
+        @param wind region name
+        """
+        new = self.Map.GetCurrentRegion()
 
         tmpreg = os.getenv("GRASS_REGION")
         if tmpreg:

+ 1 - 4
gui/wxpython/gui_modules/render.py

@@ -645,10 +645,7 @@ class Map(object):
                               "Force quiting wxGUI. Please run manually g.region to "
                               "fix the problem.")
             e.Show()
-            if not rast and not vect:
-                sys.exit(1)
-            else:
-                return self.region
+            return self.region
 
         for reg in ret.splitlines():
             key, val = reg.split("=", 1)