[GRASS-SVN] r46485 - in grass/trunk/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 1 15:32:46 EDT 2011


Author: martinl
Date: 2011-06-01 12:32:45 -0700 (Wed, 01 Jun 2011)
New Revision: 46485

Added:
   grass/trunk/gui/wxpython/gui_modules/gpyshell.py
Modified:
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: implement interactive python shell


Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-06-01 13:46:50 UTC (rev 46484)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-06-01 19:32:45 UTC (rev 46485)
@@ -602,10 +602,9 @@
             self.history += '\n'
 
         wildcard = "Text file (*.txt)|*.txt"
-        dlg = wx.FileDialog(
-            self, message=_("Save file as..."), defaultDir=os.getcwd(),
-            defaultFile="grass_cmd_history.txt", wildcard=wildcard,
-            style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
+        dlg = wx.FileDialog(self, message = _("Save file as..."), defaultDir = os.getcwd(),
+            defaultFile = "grass_cmd_history.txt", wildcard = wildcard,
+            style = wx.SAVE | wx.FD_OVERWRITE_PROMPT)
 
         # Show the dialog and retrieve the user response. If it is the OK response,
         # process the data.

Added: grass/trunk/gui/wxpython/gui_modules/gpyshell.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gpyshell.py	                        (rev 0)
+++ grass/trunk/gui/wxpython/gui_modules/gpyshell.py	2011-06-01 19:32:45 UTC (rev 46485)
@@ -0,0 +1,74 @@
+"""!
+ at package gpyshell.py
+
+ at brief wxGUI Interactive Python Shell
+
+Classes:
+ - PyShellWindow
+
+(C) 2011 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.
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import os
+import sys
+
+import wx
+from wx.py.shell import Shell as PyShell
+from wx.py.version import VERSION
+
+import grass.script as grass
+
+class PyShellWindow(wx.Panel):
+    """!Python Shell Window"""
+    def __init__(self, parent, id = wx.ID_ANY, **kwargs):
+        self.parent = parent
+        
+        wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
+        
+        self.intro = _("Welcome to wxGUI Python Shell %s") % VERSION
+        self.shell = PyShell(parent = self, id = wx.ID_ANY,
+                             introText = self.intro, locals = {'grass' : grass})
+        
+        sys.displayhook = self._displayhook
+        
+        self.btnClear = wx.Button(self, wx.ID_CLEAR)
+        self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
+        self.btnClear.SetToolTipString(_("Delete all text from the shell"))
+                
+        self._layout()
+        
+    def _displayhook(self, value):
+        print value # do not modify __builtin__._
+        
+    def _layout(self):
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        
+        sizer.Add(item = self.shell, proportion = 1,
+                  flag = wx.EXPAND)
+        
+        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+        btnSizer.Add(item = self.btnClear, proportion = 0,
+                     flag = wx.EXPAND | wx.RIGHT, border = 5)
+        sizer.Add(item = btnSizer, proportion = 0,
+                  flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
+        
+        sizer.Fit(self)
+        sizer.SetSizeHints(self)
+        
+        self.SetSizer(sizer)
+        
+        self.Fit()
+        self.SetAutoLayout(True)        
+        self.Layout()
+
+    def OnClear(self, event):
+        """!Delete all text from the shell
+        """
+        self.shell.clear()
+        self.shell.showIntro(self.intro)
+        self.shell.prompt()


Property changes on: grass/trunk/gui/wxpython/gui_modules/gpyshell.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2011-06-01 13:46:50 UTC (rev 46484)
+++ grass/trunk/gui/wxpython/wxgui.py	2011-06-01 19:32:45 UTC (rev 46485)
@@ -81,10 +81,11 @@
 from gui_modules import gmodeler
 from gui_modules import vclean
 from gui_modules import nviz_tools
-from gui_modules.debug import Debug
-from gui_modules.ghelp import MenuTreeWindow, AboutWindow, InstallExtensionWindow
+from gui_modules.debug    import Debug
+from gui_modules.ghelp    import MenuTreeWindow, AboutWindow, InstallExtensionWindow
 from gui_modules.toolbars import LayerManagerToolbar, ToolsToolbar
-from icons.icon import Icons
+from gui_modules.gpyshell import PyShellWindow
+from icons.icon           import Icons
 
 UserSettings = preferences.globalSettings
 
@@ -220,7 +221,7 @@
             self.notebook = FN.FlatNotebook(parent = self, id = wx.ID_ANY, agwStyle = globalvar.FNPageDStyle)
         else:
             self.notebook = FN.FlatNotebook(parent = self, id = wx.ID_ANY, style = globalvar.FNPageDStyle)
-
+        
         # create displays notebook widget and add it to main notebook page
         cbStyle = globalvar.FNPageStyle
         if globalvar.hasAgw:
@@ -230,7 +231,7 @@
         self.gm_cb.SetTabAreaColour(globalvar.FNPageColor)
         self.notebook.AddPage(self.gm_cb, text = _("Map layers"))
         
-        # create command output text area and add it to main notebook page
+        # create 'command output' text area
         self.goutput = goutput.GMConsole(self, pageid = 1)
         self.notebook.AddPage(self.goutput, text = _("Command console"))
         
@@ -238,10 +239,14 @@
         self.search = MenuTreeWindow(parent = self)
         self.notebook.AddPage(self.search, text = _("Search module"))
         
+        # create 'python shell' notebook page
+        self.pyshell = PyShellWindow(parent = self)
+        self.notebook.AddPage(self.pyshell, text = _("Python shell"))
+        
         # bindings
-        self.gm_cb.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnCBPageChanged)
+        self.gm_cb.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED,    self.OnCBPageChanged)
         self.notebook.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
-        self.gm_cb.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnCBPageClosed)
+        self.gm_cb.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CLOSING,    self.OnCBPageClosed)
         
         return self.notebook
 



More information about the grass-commit mailing list