Преглед изворни кода

wxGUI/lmgr: fix Python Shell 'help()' function and intro text (#1894)

Tomas Zigo пре 3 година
родитељ
комит
3a2fc82c03
1 измењених фајлова са 23 додато и 4 уклоњено
  1. 23 4
      gui/wxpython/lmgr/pyshell.py

+ 23 - 4
gui/wxpython/lmgr/pyshell.py

@@ -20,6 +20,8 @@ This program is free software under the GNU General Public License
 
 from __future__ import print_function
 
+import io
+from contextlib import redirect_stdout
 import sys
 
 import wx
@@ -42,15 +44,21 @@ class PyShellWindow(wx.Panel):
 
         wx.Panel.__init__(self, parent=parent, id=id, **kwargs)
 
-        self.intro = _("Welcome to wxGUI Interactive Python Shell %s") % VERSION + "\n\n" + \
-            _("Type %s for more GRASS scripting related information.") % "\"help(grass)\"" + "\n" + \
-            _("Type %s to add raster or vector to the layer tree.") % "\"AddLayer()\"" + "\n\n"
+        self.intro = (
+            _("Welcome to wxGUI Interactive Python Shell %s") % VERSION
+            + "\n\n"
+            + _("Type %s for more GRASS scripting related information.") % '"help(gs)"'
+            + "\n"
+            + _("Type %s to add raster or vector to the layer tree.")
+            % "\"AddLayer('map_name')\""
+            + "\n\n"
+        )
 
         shellargs = dict(
             parent=self,
             id=wx.ID_ANY,
             introText=self.intro,
-            locals={"grass": grass, "AddLayer": self.AddLayer},
+            locals={"gs": grass, "AddLayer": self.AddLayer, "help": self.Help},
         )
         # useStockId (available since wxPython 4.0.2) should be False on macOS
         if sys.platform == "darwin" and CheckWxVersion([4, 0, 2]):
@@ -134,6 +142,17 @@ class PyShellWindow(wx.Panel):
 
         return _('Vector map <%s> added') % fname
 
+    def Help(self, obj):
+        """Override help() function
+
+        :param obj object/str: generate the help of the given object
+
+        return str: help str of the given object
+        """
+        with redirect_stdout(io.StringIO()) as f:
+            help(obj)
+        return f.getvalue()
+
     def OnClear(self, event):
         """Delete all text from the shell
         """