[GRASS-SVN] r59307 - in grass/trunk/gui/wxpython: core gmodeler gui_core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 24 08:26:03 PDT 2014


Author: martinl
Date: 2014-03-24 08:26:02 -0700 (Mon, 24 Mar 2014)
New Revision: 59307

Modified:
   grass/trunk/gui/wxpython/core/gconsole.py
   grass/trunk/gui/wxpython/core/giface.py
   grass/trunk/gui/wxpython/gmodeler/dialogs.py
   grass/trunk/gui/wxpython/gui_core/forms.py
   grass/trunk/gui/wxpython/gui_core/prompt.py
   grass/trunk/gui/wxpython/lmgr/giface.py
Log:
wxGUI: update prompt history when running command from dialog


Modified: grass/trunk/gui/wxpython/core/gconsole.py
===================================================================
--- grass/trunk/gui/wxpython/core/gconsole.py	2014-03-24 13:47:21 UTC (rev 59306)
+++ grass/trunk/gui/wxpython/core/gconsole.py	2014-03-24 15:26:02 UTC (rev 59307)
@@ -449,25 +449,8 @@
             return
 
         # update history file
-        env = grass.gisenv()
-        try:
-            filePath = os.path.join(env['GISDBASE'],
-                                    env['LOCATION_NAME'],
-                                    env['MAPSET'],
-                                    '.bash_history')
-            fileHistory = codecs.open(filePath, encoding='utf-8', mode='a')
-        except IOError, e:
-            GError(_("Unable to write file '%(filePath)s'.\n\nDetails: %(error)s") % 
-                    {'filePath': filePath, 'error': e},
-                   parent=self._guiparent)
-            fileHistory = None
-
-        if fileHistory:
-            try:
-                fileHistory.write(' '.join(command) + os.linesep)
-            finally:
-                fileHistory.close()
-
+        self.UpdateHistoryFile(' '.join(command))
+        
         if command[0] in globalvar.grassCmd:
             # send GRASS command without arguments to GUI command interface
             # except ignored commands (event is emitted)
@@ -674,3 +657,31 @@
 
     def OnProcessPendingOutputWindowEvents(self, event):
         wx.GetApp().ProcessPendingEvents()
+
+    def UpdateHistoryFile(self, command):
+        """!Update history file
+        
+        @param command the command given as a string
+        """
+        env = grass.gisenv()
+        try:
+            filePath = os.path.join(env['GISDBASE'],
+                                    env['LOCATION_NAME'],
+                                    env['MAPSET'],
+                                    '.bash_history')
+            fileHistory = codecs.open(filePath, encoding='utf-8', mode='a')
+        except IOError, e:
+            GError(_("Unable to write file '%(filePath)s'.\n\nDetails: %(error)s") % 
+                    {'filePath': filePath, 'error': e},
+                   parent=self._guiparent)
+            return
+        
+        try:
+            fileHistory.write(command + os.linesep)
+        finally:
+            fileHistory.close()
+        
+        # update wxGUI prompt
+        if self._giface:
+            self._giface.UpdateCmdHistory(command)
+        

Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py	2014-03-24 13:47:21 UTC (rev 59306)
+++ grass/trunk/gui/wxpython/core/giface.py	2014-03-24 15:26:02 UTC (rev 59307)
@@ -276,3 +276,6 @@
         # TODO: implement some progress with same inface as gui one
         # (probably using g.message or similarly to Write... functions)
         raise NotImplementedError()
+
+    def UpdateCmdHistory(self, cmd):
+        raise NotImplementedError()

Modified: grass/trunk/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/dialogs.py	2014-03-24 13:47:21 UTC (rev 59306)
+++ grass/trunk/gui/wxpython/gmodeler/dialogs.py	2014-03-24 15:26:02 UTC (rev 59307)
@@ -164,7 +164,7 @@
         # menu data for search widget and prompt
         menuModel = LayerManagerMenuData()
         
-        self.cmd_prompt = GPromptSTC(parent = self, menuModel = menuModel.GetModel(), updateCmdHistory = False)
+        self.cmd_prompt = GPromptSTC(parent = self, menuModel = menuModel.GetModel())
         self.cmd_prompt.promptRunCmd.connect(self.OnCommand)
         self.cmd_prompt.commandSelected.connect(lambda command: self.label.SetValue(command))
         self.search = SearchModuleWidget(parent = self.panel,

Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py	2014-03-24 13:47:21 UTC (rev 59306)
+++ grass/trunk/gui/wxpython/gui_core/forms.py	2014-03-24 15:26:02 UTC (rev 59307)
@@ -1771,7 +1771,7 @@
         if self.parent.GetName() == "MainFrame" and self.parent.get_dcmd is None:
             from core.gconsole import GConsole, EVT_CMD_RUN, EVT_CMD_DONE
             from gui_core.goutput import GConsoleWindow
-            self._gconsole = GConsole(guiparent = self.notebook)
+            self._gconsole = GConsole(guiparent = self.notebook, giface = self._giface)
             self.goutput = GConsoleWindow(parent = self.notebook, gconsole = self._gconsole, margin = False)
             self._gconsole.Bind(EVT_CMD_RUN,
                                 lambda event:

Modified: grass/trunk/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/prompt.py	2014-03-24 13:47:21 UTC (rev 59306)
+++ grass/trunk/gui/wxpython/gui_core/prompt.py	2014-03-24 15:26:02 UTC (rev 59307)
@@ -7,7 +7,7 @@
  - prompt::GPrompt
  - prompt::GPromptSTC
 
-(C) 2009-2011 by the GRASS Development Team
+(C) 2009-2014 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -44,7 +44,7 @@
 
     See subclass GPromptPopUp and GPromptSTC.
     """
-    def __init__(self, parent, menuModel, updateCmdHistory):
+    def __init__(self, parent, menuModel):
         self.parent = parent                 # GConsole
         self.panel  = self.parent.GetPanel()
 
@@ -62,8 +62,7 @@
         
         # command description (gtask.grassTask)
         self.cmdDesc   = None
-
-        self._updateCmdHistory = updateCmdHistory
+        
         self.cmdbuffer = self._readHistory()
         self.cmdindex  = len(self.cmdbuffer)
         
@@ -119,7 +118,7 @@
         self.promptRunCmd.emit(cmd=cmd)
 
         # add command to history & clean prompt
-        self.UpdateCmdHistory(cmd)
+        ### self.UpdateCmdHistory(cmd)
         self.OnCmdErase(None)
         self.ShowStatusText('')
         
@@ -134,9 +133,8 @@
 
 class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
     """!Styled wxGUI prompt with autocomplete and calltips"""    
-    def __init__(self, parent, menuModel, updateCmdHistory = True, margin = False):
-        GPrompt.__init__(self, parent = parent, 
-                         menuModel = menuModel, updateCmdHistory = updateCmdHistory)
+    def __init__(self, parent, menuModel, margin = False):
+        GPrompt.__init__(self, parent = parent, menuModel = menuModel)
         wx.stc.StyledTextCtrl.__init__(self, self.panel, id = wx.ID_ANY)
         
         #
@@ -283,12 +281,10 @@
     def UpdateCmdHistory(self, cmd):
         """!Update command history
         
-        @param cmd command given as a list
+        @param cmd command given as a string
         """
-        if not self._updateCmdHistory:
-            return
         # add command to history    
-        self.cmdbuffer.append(' '.join(cmd))
+        self.cmdbuffer.append(cmd)
         
         # keep command history to a managable size
         if len(self.cmdbuffer) > 200:

Modified: grass/trunk/gui/wxpython/lmgr/giface.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/giface.py	2014-03-24 13:47:21 UTC (rev 59306)
+++ grass/trunk/gui/wxpython/lmgr/giface.py	2014-03-24 15:26:02 UTC (rev 59307)
@@ -187,6 +187,8 @@
     def GetProgress(self):
         return self.lmgr.goutput.GetProgressBar()
 
+    def UpdateCmdHistory(self, cmd):
+        self.lmgr.goutput.GetPrompt().UpdateCmdHistory(cmd)
 
 class LayerManagerGrassInterfaceForMapDisplay(object):
     """!Provides reference only to the given layer list (according to tree),



More information about the grass-commit mailing list