瀏覽代碼

wxGUI: bug fix trac https://trac.osgeo.org/grass/ticket/282 -- r.what in wxGUI should not depend on computational region
use `del os.environ[key] rather then os.unsetenv(key)
(merge from devbr6, https://trac.osgeo.org/grass/changeset/33276)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33277 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 年之前
父節點
當前提交
caa0ba273b

+ 4 - 4
gui/wxpython/gui_modules/gcmd.py

@@ -369,9 +369,9 @@ class Command:
 
 
         if verbose_orig:
         if verbose_orig:
             os.environ["GRASS_VERBOSE"] = verbose_orig
             os.environ["GRASS_VERBOSE"] = verbose_orig
-        else:
-            os.unsetenv("GRASS_VERBOSE")
-
+        elif os.environ.has_key("GRASS_VERBOSE"):
+            del os.environ["GRASS_VERBOSE"]
+            
     def __ReadOutput(self, stream):
     def __ReadOutput(self, stream):
         """Read stream and return list of lines
         """Read stream and return list of lines
 
 
@@ -508,7 +508,7 @@ class CommandThread(Thread):
         if self.message_format:
         if self.message_format:
             os.environ["GRASS_MESSAGE_FORMAT"] = self.message_format
             os.environ["GRASS_MESSAGE_FORMAT"] = self.message_format
         else:
         else:
-            os.unsetenv("GRASS_MESSAGE_FORMAT")
+            del os.environ["GRASS_MESSAGE_FORMAT"]
         
         
     def run(self):
     def run(self):
         if len(self.cmd) == 0:
         if len(self.cmd) == 0:

+ 11 - 4
gui/wxpython/gui_modules/goutput.py

@@ -243,7 +243,7 @@ class GMConsole(wx.Panel):
         """Write out line in warning style"""
         """Write out line in warning style"""
         self.WriteLog(line, style=self.cmd_output.StyleWarning)
         self.WriteLog(line, style=self.cmd_output.StyleWarning)
 
 
-    def RunCmd(self, command):
+    def RunCmd(self, command, compReg=True):
         """
         """
         Run in GUI GRASS (or other) commands typed into
         Run in GUI GRASS (or other) commands typed into
         console command text widget, and send stdout output to output
         console command text widget, and send stdout output to output
@@ -255,6 +255,9 @@ class GMConsole(wx.Panel):
         processed separately by mapdisp.py. Display commands are
         processed separately by mapdisp.py. Display commands are
         rendered in map display widget that currently has
         rendered in map display widget that currently has
         the focus (as indicted by mdidx).
         the focus (as indicted by mdidx).
+
+        @param command command (list)
+        @param compReg if true use computation region
         """
         """
         
         
         # map display window available ?
         # map display window available ?
@@ -304,10 +307,13 @@ class GMConsole(wx.Panel):
                 #
                 #
                 # other GRASS commands (r|v|g|...)
                 # other GRASS commands (r|v|g|...)
                 #
                 #
+                
                 # activate computational region (set with g.region)
                 # activate computational region (set with g.region)
                 # for all non-display commands.
                 # for all non-display commands.
-                tmpreg = os.getenv("GRASS_REGION")
-                os.unsetenv("GRASS_REGION")
+                if compReg:
+                    tmpreg = os.getenv("GRASS_REGION")
+                    del os.environ["GRASS_REGION"]
+                    
                 if len(cmdlist) == 1:
                 if len(cmdlist) == 1:
                     import menuform
                     import menuform
                     # process GRASS command without argument
                     # process GRASS command without argument
@@ -321,8 +327,9 @@ class GMConsole(wx.Panel):
                     self.cmd_output_timer.Start(50)
                     self.cmd_output_timer.Start(50)
 
 
                     return None
                     return None
+                
                 # deactivate computational region and return to display settings
                 # deactivate computational region and return to display settings
-                if tmpreg:
+                if compReg and tmpreg:
                     os.environ["GRASS_REGION"] = tmpreg
                     os.environ["GRASS_REGION"] = tmpreg
         else:
         else:
             # Send any other command to the shell. Send output to
             # Send any other command to the shell. Send output to

+ 14 - 4
gui/wxpython/gui_modules/mapdisp.py

@@ -2280,7 +2280,8 @@ class BufferedWindow(MapWindow, wx.Window):
         match display extents
         match display extents
         """
         """
         tmpreg = os.getenv("GRASS_REGION")
         tmpreg = os.getenv("GRASS_REGION")
-        os.unsetenv("GRASS_REGION")
+        if tmpreg:
+            del os.environ["GRASS_REGION"]
 
 
         # We ONLY want to set extents here. Don't mess with resolution. Leave that
         # We ONLY want to set extents here. Don't mess with resolution. Leave that
         # for user to set explicitly with g.region
         # for user to set explicitly with g.region
@@ -2384,8 +2385,9 @@ class BufferedWindow(MapWindow, wx.Window):
                      "--o"]
                      "--o"]
 
 
         tmpreg = os.getenv("GRASS_REGION")
         tmpreg = os.getenv("GRASS_REGION")
-        os.unsetenv("GRASS_REGION")
-
+        if tmpreg:
+            del os.environ["GRASS_REGION"]
+        
         p = gcmd.Command(cmdRegion)
         p = gcmd.Command(cmdRegion)
 
 
         if tmpreg:
         if tmpreg:
@@ -3331,6 +3333,10 @@ class MapFrame(wx.Frame):
             elif type in ('vector', 'thememap', 'themechart'):
             elif type in ('vector', 'thememap', 'themechart'):
                 vectstr += "%s," % name
                 vectstr += "%s," % name
 
 
+        # use display region settings instead of computation region settings
+        tmpreg = os.getenv("GRASS_REGION")
+        os.environ["GRASS_REGION"] = self.Map.SetRegion(windres=False)
+        
         # build query commands for any selected rasters and vectors
         # build query commands for any selected rasters and vectors
         if raststr != '':
         if raststr != '':
             rcmd = ['r.what', '--q',
             rcmd = ['r.what', '--q',
@@ -3365,7 +3371,7 @@ class MapFrame(wx.Frame):
         # parse query command(s)
         # parse query command(s)
         if self.gismanager:
         if self.gismanager:
             if rcmd:
             if rcmd:
-                self.gismanager.goutput.RunCmd(rcmd)
+                self.gismanager.goutput.RunCmd(rcmd, compReg=False)
             if vcmd:
             if vcmd:
                 self.gismanager.goutput.RunCmd(vcmd)
                 self.gismanager.goutput.RunCmd(vcmd)
         else:
         else:
@@ -3374,6 +3380,10 @@ class MapFrame(wx.Frame):
             if vcmd:
             if vcmd:
                 gcmd.Command(vcmd)
                 gcmd.Command(vcmd)
 
 
+        # restore GRASS_REGION
+        if tmpreg:
+            os.environ["GRASS_REGION"] = tmpreg
+        
     def QueryVector(self, x, y):
     def QueryVector(self, x, y):
         """
         """
         Query vector map layer features
         Query vector map layer features

+ 7 - 13
gui/wxpython/gui_modules/render.py

@@ -175,7 +175,7 @@ class Layer(object):
         #
         #
         # stop monitor
         # stop monitor
         #
         #
-	os.unsetenv("GRASS_PNGFILE")
+        del os.environ["GRASS_PNGFILE"]
         
         
         self.force_render = False
         self.force_render = False
         
         
@@ -569,7 +569,8 @@ class Map(object):
         region = {}
         region = {}
 
 
         tmpreg = os.getenv("GRASS_REGION")
         tmpreg = os.getenv("GRASS_REGION")
-        os.unsetenv("GRASS_REGION")
+        if tmpreg:
+            del os.environ["GRASS_REGION"]
 
 
         # use external gisrc if defined
         # use external gisrc if defined
         gisrc_orig = os.getenv("GISRC")
         gisrc_orig = os.getenv("GISRC")
@@ -654,13 +655,7 @@ class Map(object):
         # adjust region settings to match monitor
         # adjust region settings to match monitor
         if not windres:
         if not windres:
             self.region = self.AdjustRegion()
             self.region = self.AdjustRegion()
-
-        #        newextents = self.AlignResolution()
-        #        self.region['n'] = newextents['n']
-        #        self.region['s'] = newextents['s']
-        #        self.region['e'] = newextents['e']
-        #        self.region['w'] = newextents['w']
-
+        
         # read values from wind file
         # read values from wind file
         try:
         try:
             for key in self.wind.keys():
             for key in self.wind.keys():
@@ -899,12 +894,11 @@ class Map(object):
 
 
 
 
         # render overlays
         # render overlays
-
-        os.unsetenv("GRASS_REGION")
-
         if tmp_region:
         if tmp_region:
             os.environ["GRASS_REGION"] = tmp_region
             os.environ["GRASS_REGION"] = tmp_region
-
+        else:
+            del os.environ["GRASS_REGION"]
+        
         # run g.pngcomp to get composite image
         # run g.pngcomp to get composite image
         try:
         try:
             gcmd.Command(complist)
             gcmd.Command(complist)