[GRASS-SVN] r38032 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 23 03:23:12 EDT 2009


Author: martinl
Date: 2009-06-23 03:23:12 -0400 (Tue, 23 Jun 2009)
New Revision: 38032

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI history support for the prompt
	(merge from trunk, r38031)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2009-06-23 07:22:01 UTC (rev 38031)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2009-06-23 07:23:12 UTC (rev 38032)
@@ -29,6 +29,8 @@
 import wx.stc
 from wx.lib.newevent import NewEvent
 
+import grass.script as grass
+
 import globalvar
 import gcmd
 import utils
@@ -308,7 +310,24 @@
             cmdlist = command.strip().split(' ')
         except:
             cmdlist = command
+        
+        # update history file
+        env = grass.gisenv()
+        fileHistory = open(os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'],
+                                        '.bash_history'), 'a')
+        cmdString = ' '.join(cmdlist)
+        try:
+            fileHistory.write(cmdString + '\n')
+        finally:
+            fileHistory.close()
 
+        # update history items
+        if self.parent.GetName() == 'LayerManager':
+            try:
+                self.parent.cmdinput.SetHistoryItems()
+            except AttributeError:
+                pass
+        
         if cmdlist[0] in globalvar.grassCmd['all']:
             # send GRASS command without arguments to GUI command interface
             # except display commands (they are handled differently)
@@ -388,7 +407,7 @@
                              stderr=self.cmd_stderr)
             except gcmd.CmdError, e:
                 print >> sys.stderr, e
-
+        
         return None
 
     def ClearHistory(self, event):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py	2009-06-23 07:22:01 UTC (rev 38031)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py	2009-06-23 07:23:12 UTC (rev 38032)
@@ -19,6 +19,7 @@
 @author Martin Landa <landa.martin gmail.com>
 """
 
+import os
 import sys
 import shlex
 
@@ -218,7 +219,7 @@
         wx.ListCtrl.__init__(self, parent, id, pos, size, style)
         listmix.ListCtrlAutoWidthMixin.__init__(self)
         
-class TextCtrlAutoComplete(wx.TextCtrl, listmix.ColumnSorterMixin):
+class TextCtrlAutoComplete(wx.ComboBox, listmix.ColumnSorterMixin):
     def __init__ (self, parent, statusbar, 
                   id = wx.ID_ANY, choices = [], **kwargs):
         """!Constructor works just like wx.TextCtrl except you can pass in a
@@ -234,7 +235,7 @@
         else:
             kwargs['style'] = wx.TE_PROCESS_ENTER
         
-        wx.TextCtrl.__init__(self, parent, id, **kwargs)
+        wx.ComboBox.__init__(self, parent, id, **kwargs)
 
         # some variables
         self._choices = choices
@@ -269,6 +270,9 @@
         # first search for GRASS module
         self.SetChoices(self._choicesCmd)
 
+        # read history
+        self.SetHistoryItems()
+        
         # bindings...
         self.Bind(wx.EVT_KILL_FOCUS, self.OnControlChanged, self)
         self.Bind(wx.EVT_TEXT, self.OnEnteredText, self)
@@ -279,6 +283,8 @@
         self.dropdownlistbox.Bind(wx.EVT_LEFT_DOWN, self.OnListClick)
         self.dropdownlistbox.Bind(wx.EVT_LEFT_DCLICK, self.OnListDClick)
         self.dropdownlistbox.Bind(wx.EVT_LIST_COL_CLICK, self.OnListColClick)
+
+        self.Bind(wx.EVT_COMBOBOX, self.OnCommandSelect)
         
     def _updateDataList(self, choices):
         """!Update data list"""
@@ -376,6 +382,23 @@
         """!Method required by listmix.ColumnSorterMixin"""
         return self.dropdownlistbox
     
+    def SetHistoryItems(self):
+        """!Read history file and update combobox items"""
+        env = grass.gisenv()
+        fileHistory = open(os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'],
+                                        '.bash_history'), 'r')
+        try:
+            hist = []
+            for line in fileHistory.readlines():
+                hist.append(line.replace('\n', ''))
+            
+            self.SetItems(hist)
+        finally:
+            fileHistory.close()
+            return
+        
+        self.SetItems([])
+        
     def SetChoices(self, choices, type = 'module'):
         """!Sets the choices available in the popup wx.ListBox.
         The items will be sorted case insensitively.
@@ -403,6 +426,10 @@
         # there is only one choice for both search and fetch if setting a single column:
         self._colSearch = 0
         self._colFetch = -1
+
+    def OnCommandSelect(self, event):
+        """!Command selected from history"""
+        self.SetFocus()
         
     def OnListClick(self, evt):
         """!Left mouse button pressed"""



More information about the grass-commit mailing list