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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 25 15:37:11 EST 2009


Author: martinl
Date: 2009-12-25 15:37:11 -0500 (Fri, 25 Dec 2009)
New Revision: 40140

Modified:
   grass/trunk/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI/prompt: read cmd history on start-up


Modified: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-12-25 20:25:56 UTC (rev 40139)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-12-25 20:37:11 UTC (rev 40140)
@@ -517,8 +517,29 @@
         
         # command description (menuform.grassTask)
         self.cmdDesc = None
-        self.cmdbuffer = list()
+        self.cmdbuffer = self._readHistory()
+        self.cmdindex = len(self.cmdbuffer)
         
+    def _readHistory(self):
+        """!Get list of commands from history file"""
+        hist = list()
+        env = grass.gisenv()
+        try:
+            fileHistory = open(os.path.join(env['GISDBASE'],
+                                            env['LOCATION_NAME'],
+                                            env['MAPSET'],
+                                            '.bash_history'), 'r')
+        except IOError:
+            return hist
+        
+        try:
+            for line in fileHistory.readlines():
+                hist.append(line.replace('\n', ''))
+        finally:
+            fileHistory.close()
+        
+        return hist
+        
     def _getListOfModules(self):
         """!Get list of modules"""
         result = dict()
@@ -811,12 +832,9 @@
             
         elif event.GetKeyCode() in [wx.WXK_UP, wx.WXK_DOWN] and event.ControlDown():
             # Command history using ctrl-up and ctrl-down   
-            
             if len(self.cmdbuffer) < 1:
                 return
             
-            txt = ''
-
             self.DocumentEnd()
             
             # move through command history list index values
@@ -832,8 +850,8 @@
             try:
                 txt = self.cmdbuffer[self.cmdindex]
             except:
-                pass
-                
+                txt = ''
+            
             # clear current line and insert command history    
             self.DelLineLeft()
             self.DelLineRight()



More information about the grass-commit mailing list