Package prompt :: Module help
[hide private]
[frames] | no frames]

Source Code for Module prompt.help

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """The prompt UI help system.""" 
 24   
 25  # Python module imports. 
 26  import pydoc 
 27  import sys 
 28  from textwrap import wrap 
 29   
 30  # relax module imports. 
 31  from status import Status; status = Status() 
 32   
 33   
 34  # Generic string printed out for function classes. 
 35  ################################################## 
 36   
 37  relax_class_help = "This is a python class which contains user functions.  To list these functions, either place a period at the end of class name and hit the tab key, or type 'dir(class_name)'." 
 38   
 39   
 40  # Helper classes. 
 41  ################# 
 42   
43 -class _Helper:
44 text = """\ 45 For assistance in using a function, simply type 'help(function)'. All functions can be viewed by hitting the [TAB] key. In addition to functions, if 'help(object)' is typed, the help for the python object is returned. This system is similar to the help function built into the python interpreter, which has been renamed to help_python, with the interactive component removed. For the interactive python help system, type 'help_python()'. 46 """ 47
48 - def __repr__(self):
49 """String representation of the object. 50 51 @return: The help description. 52 @rtype: str 53 """ 54 55 # Wrap the text. 56 string = '' 57 for line in wrap(self.text, status.text_width): 58 string += line + '\n' 59 60 # Return the wrapped text. 61 return string
62 63
64 - def __call__(self, *args, **kwds):
65 """Make the object executable.""" 66 67 # Catch strange callings of the object. 68 if len(args) != 1 or isinstance(args[0], str): 69 print(self.text) 70 return 71 72 # Alias the object. 73 obj = args[0] 74 75 # Automatically create the user function docstring help text, storing it so it only needs to be built once. 76 if not hasattr(obj, '__relax_help__') and hasattr(obj, '_build_doc'): 77 obj.__relax_help__ = obj._build_doc() 78 79 # The relax help system. 80 if hasattr(obj, '__relax_help__'): 81 pydoc.pager(obj.__relax_help__) 82 return 83 84 # Default to the normal Python help system. 85 return pydoc.help(*args, **kwds)
86 87
88 -class _Helper_python:
89 text = """\ 90 For the interactive python help system, type 'help_python()'. The help_python function is identical 91 to the help function built into the normal python interpreter. 92 """ 93 94
95 - def __repr__(self):
96 return self.text
97 98
99 - def __call__(self, *args, **kwds):
100 return pydoc.help(*args, **kwds)
101