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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 23 09:45:32 EST 2010


Author: martinl
Date: 2010-11-23 06:45:32 -0800 (Tue, 23 Nov 2010)
New Revision: 44391

Modified:
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/mcalc_builder.py
   grass/trunk/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI: mcalc fixes
(merge r44387 & 44389 from devbr6)


Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2010-11-23 14:33:08 UTC (rev 44390)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2010-11-23 14:45:32 UTC (rev 44391)
@@ -117,13 +117,23 @@
             # 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 @@
                 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)

Modified: grass/trunk/gui/wxpython/gui_modules/mcalc_builder.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mcalc_builder.py	2010-11-23 14:33:08 UTC (rev 44390)
+++ grass/trunk/gui/wxpython/gui_modules/mcalc_builder.py	2010-11-23 14:45:32 UTC (rev 44391)
@@ -132,7 +132,7 @@
         #
         # 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 @@
                          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 @@
         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 @@
 
     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 @@
         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)

Modified: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	2010-11-23 14:33:08 UTC (rev 44390)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2010-11-23 14:45:32 UTC (rev 44391)
@@ -737,11 +737,30 @@
         
         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 @@
                 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:



More information about the grass-commit mailing list