Below is an alternative version of my PyHelp.py file. You might give it a key-binding such as:
{ "keys": "shift+f1"], "command": "py_help" }
Click into a (standard) Python function-name, method or attribute and press Shift+F1. An output panel will open with the help text extracted from the Python version you are using, or the status bar will advise that no help is available. (I was using the status-bar previously, but the output panel will show the full help text.)
Thereâs a comment towards the bottom of the file which would hide the output panel after 5 seconds - uncomment this if you like.
I was examining the possibility of also extracting help text from any library that you may have imported. However, it doesnât seem that there is much help (via doc) in the standard (or sublime) libraries
[code]import sublime, sublime_plugin
class PyHelpCommand(sublime_plugin.TextCommand):
py_types = (âbufferâ, âbytearrayâ, âcomplexâ, âdictâ, âfileâ, âfloatâ, âfrozensetâ, âintâ,
âlistâ, âlongâ, âmemoryviewâ, âsetâ, âstrâ, âtupleâ, âunicodeâ, âxrangeâ)
def run(self, edit):
curr_view = self.view
if not curr_view.match_selector(0, âsource.pythonâ): return
word = curr_view.substr(curr_view.word(curr_view.sel()[0].end())).lower()
if word is None or len(word) <= 1:
sublime.status_message(âNo word selectedâ)
return
try:
help_text = eval(word + â.docâ)
if help_text is not None:
self.display_help(help_text)
return
except:
pass
for obj in PyHelpCommand.py_types:
try:
help_text = eval(obj + â.â + word + â.docâ)
if help_text is not None:
self.display_help(help_text)
return
except:
pass
else:
sublime.status_message(âNo help availableâ)
def display_help(self, help_text):
win = sublime.active_window()
the_output = win.get_output_panel('help_panel')
win.run_command("show_panel", {"panel": "output." + "help_panel"})
the_output.set_read_only(False)
edit = the_output.begin_edit()
the_output.insert(edit, the_output.size(), help_text)
the_output.end_edit(edit)
the_output.set_read_only(True)
# sublime.set_timeout(self.hide_help, 5000)
def hide_help(self):
sublime.active_window().run_command("hide_panel", {"panel": "output." + "help_panel"})[/code]