Sfoglia il codice sorgente

wxGUI: mcalc fixes
(merge https://trac.osgeo.org/grass/changeset/44387 & 44389 from devbr6)


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

Martin Landa 14 anni fa
parent
commit
84a79509bc

+ 15 - 5
gui/wxpython/gui_modules/goutput.py

@@ -117,13 +117,23 @@ class CmdThread(threading.Thread):
             # set default color table for raster data
             if UserSettings.Get(group='cmd', key='rasterColorTable', subkey='enabled') and \
                     args[0][0][:2] == 'r.':
-                moduleInterface = menuform.GUI().ParseCommand(args[0], show = None)
-                outputParam = moduleInterface.get_param(value = 'output', raiseError = False)
                 colorTable = UserSettings.Get(group='cmd', key='rasterColorTable', subkey='selection')
-                if outputParam and outputParam['prompt'] == 'raster':
+                mapName = None
+                if args[0][0] == 'r.mapcalc':
+                    try:
+                        mapName = args[0][1].split('=', 1)[0].strip()
+                    except KeyError:
+                        pass
+                else:
+                    moduleInterface = menuform.GUI().ParseCommand(args[0], show = None)
+                    outputParam = moduleInterface.get_param(value = 'output', raiseError = False)
+                    if outputParam and outputParam['prompt'] == 'raster':
+                        mapName = outputParam['value']
+                
+                if mapName:
                     argsColor = list(args)
                     argsColor[0] = [ 'r.colors',
-                                     'map=%s' % outputParam['value'],
+                                     'map=%s' % mapName,
                                      'color=%s' % colorTable ]
                     self.requestCmdColor = callable(*argsColor, **kwds)
                     self.resultQ.put((requestId, self.requestCmdColor.run()))
@@ -481,7 +491,7 @@ class GMConsole(wx.SplitterWindow):
                 else:
                     lname = None
                 
-                if self.parent.GetName() == "LayerManager":                
+                if self.parent.GetName() == "LayerManager":
                     self.parent.curr_page.maptree.AddLayer(ltype=layertype,
                                                            lname=lname,
                                                            lcmd=command)

+ 16 - 12
gui/wxpython/gui_modules/mcalc_builder.py

@@ -132,7 +132,7 @@ class MapCalcFrame(wx.Frame):
         #
         # Buttons
         #
-        self.btn_clear = wx.Button(parent = self.panel, id = wx.ID_CLEAR)
+        self.btn_clear = wx.Button(parent = self.panel, id = wx.ID_CLEAR, label = _("Cl&ear"))
         self.btn_help = wx.Button(parent = self.panel, id = wx.ID_HELP)
         self.btn_run = wx.Button(parent = self.panel, id = wx.ID_ANY, label = _("&Run"))
         self.btn_run.SetDefault()
@@ -320,7 +320,7 @@ class MapCalcFrame(wx.Frame):
                          flag = wx.ALL, border = 5)
         buttonSizer4.Add(item = self.btn_save,
                          flag = wx.ALL, border = 5)                         
-        buttonSizer4.AddSpacer(10)
+        buttonSizer4.AddSpacer(30)
         buttonSizer4.Add(item = self.btn_help,
                          flag = wx.ALL, border = 5)
         buttonSizer4.Add(item = self.btn_run,
@@ -351,15 +351,16 @@ class MapCalcFrame(wx.Frame):
         sizer.Add(item = expressSizer, proportion = 1,
                   flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
                   border = 5)
+        sizer.Add(item = buttonSizer4, proportion = 0,
+                  flag = wx.ALIGN_RIGHT | wx.ALL, border = 3)
+        
         sizer.Add(item = self.overwrite, proportion = 0,
-                  flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
+                  flag = wx.LEFT | wx.RIGHT,
                   border = 5)
         if self.addbox.IsShown():
             sizer.Add(item = self.addbox, proportion = 0,
-                      flag = wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT,
+                      flag = wx.LEFT | wx.RIGHT,
                       border = 5)
-        sizer.Add(item = buttonSizer4, proportion = 0,
-                  flag = wx.ALL | wx.ALIGN_RIGHT, border = 1)
         
         self.panel.SetAutoLayout(True)
         self.panel.SetSizer(sizer)
@@ -406,8 +407,8 @@ class MapCalcFrame(wx.Frame):
 
     def OnUpdateStatusBar(self, event):
         """!Update statusbar text"""
-        self.SetStatusText("r.mapcalc ' %s = %s'" % (self.newmaptxt.GetValue(),
-                                                     self.text_mcalc.GetValue()))
+        self.SetStatusText("r.mapcalc '%s = %s'" % (self.newmaptxt.GetValue(),
+                                                    self.text_mcalc.GetValue()))
         event.Skip()
         
     def _addSomething(self, what):
@@ -474,10 +475,13 @@ class MapCalcFrame(wx.Frame):
         if not self.addbox.IsChecked():
             return
         name = self.newmaptxt.GetValue().strip() + '@' + grass.gisenv()['MAPSET']
-        self.parent.GetLayerTree().AddLayer(ltype = 'raster',
-                                            lname = name,
-                                            lcmd = ['d.rast', 'map=%s' % name],
-                                            multiple = False)
+        mapTree = self.parent.GetLayerTree()
+        if not mapTree.GetMap().GetListOfLayers(l_name = name):
+            mapTree.AddLayer(ltype = 'raster',
+                             lname = name,
+                             lcmd = ['d.rast', 'map=%s' % name],
+                             multiple = False)
+        
         display = self.parent.GetLayerTree().GetMapDisplay()
         if display and display.IsAutoRendered():
             display.GetWindow().UpdateMap(render = True)

+ 26 - 14
gui/wxpython/gui_modules/prompt.py

@@ -737,10 +737,29 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
         
         cmd = text.split()[0]
         if not self.cmdDesc or cmd != self.cmdDesc.get_name():
-            try:
-                self.cmdDesc = menuform.GUI().ParseInterface(cmd = [cmd])
-            except IOError:
-                self.cmdDesc = None
+            if cmd in ('r.mapcalc', 'r3.mapcalc'):
+                self.parent.parent.OnMapCalculator(event = None, cmd = [cmd])
+                # add command to history & clean prompt
+                self.UpdateCmdHistory([cmd])
+                self.OnCmdErase(None)
+            else:
+                try:
+                    self.cmdDesc = menuform.GUI().ParseInterface(cmd = [cmd])
+                except IOError:
+                    self.cmdDesc = None
+        
+    def UpdateCmdHistory(self, cmd):
+        """!Update command history
+        
+        @param cmd command given as a list
+        """
+        # add command to history    
+        self.cmdbuffer.append(' '.join(cmd))
+        
+        # keep command history to a managable size
+        if len(self.cmdbuffer) > 200:
+            del self.cmdbuffer[0]
+        self.cmdindex = len(self.cmdbuffer)
         
     def OnKeyPressed(self, event):
         """!Key press capture for autocompletion, calltips, and command history
@@ -898,20 +917,13 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
                 cmd = utils.split(utils.EncodeString((line)))
             
             #  send the command list to the processor 
-            if cmd[0] in ('r.mapcalc', 'r3.mapcalc'):
+            if cmd[0] in ('r.mapcalc', 'r3.mapcalc') and len(cmd) == 1:
                 self.parent.parent.OnMapCalculator(event = None, cmd = cmd)
             else:
                 self.parent.RunCmd(cmd)
             
-            # add command to history    
-            self.cmdbuffer.append(' '.join(cmd))
-            
-            # keep command history to a managable size
-            if len(self.cmdbuffer) > 200:
-                del self.cmdbuffer[0]
-            self.cmdindex = len(self.cmdbuffer)
-            
-            # reset command-line
+            # add command to history & clean prompt
+            self.UpdateCmdHistory(cmd)
             self.OnCmdErase(None)
             
         elif event.GetKeyCode() == wx.WXK_SPACE: