Skip to content

Commit

Permalink
wxGUI/lmgr: fix Python Shell 'help()' function and intro text (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Oct 3, 2021
1 parent d41d074 commit 9188b66
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gui/wxpython/lmgr/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from __future__ import print_function

import io
from contextlib import redirect_stdout
import sys

import wx
Expand Down Expand Up @@ -49,15 +51,16 @@ def __init__(
+ "\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()"'
+ _("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={"gs": 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]):
Expand Down Expand Up @@ -141,6 +144,17 @@ def AddLayer(self, name, ltype="auto"):

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"""
self.shell.clear()
Expand Down

0 comments on commit 9188b66

Please sign in to comment.