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

Source Code for Module prompt.help

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2013 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  from textwrap import wrap 
 28   
 29  # relax module imports. 
 30  from status import Status; status = Status() 
 31   
 32   
 33  # Generic string printed out for function classes. 
 34  ################################################## 
 35   
 36  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)'." 
 37   
 38   
 39  # Helper classes. 
 40  ################# 
 41   
42 -class _Helper:
43 text = """\ 44 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()'. 45 """ 46
47 - def __repr__(self):
48 """String representation of the object. 49 50 @return: The help description. 51 @rtype: str 52 """ 53 54 # Wrap the text. 55 string = '' 56 for line in wrap(self.text, status.text_width): 57 string += line + '\n' 58 59 # Return the wrapped text. 60 return string
61 62
63 - def __call__(self, *args, **kwds):
64 """Make the object executable.""" 65 66 # Catch strange callings of the object. 67 if len(args) != 1 or isinstance(args[0], str): 68 print(self.text) 69 return 70 71 # Alias the object. 72 obj = args[0] 73 74 # Automatically create the user function docstring help text, storing it so it only needs to be built once. 75 if not hasattr(obj, '__relax_help__') and hasattr(obj, '_build_doc'): 76 obj.__relax_help__ = obj._build_doc() 77 78 # The relax help system. 79 if hasattr(obj, '__relax_help__'): 80 pydoc.pager(obj.__relax_help__) 81 return 82 83 # Default to the normal Python help system. 84 return pydoc.help(*args, **kwds)
85 86
87 -class _Helper_python:
88 text = """\ 89 For the interactive python help system, type 'help_python()'. The help_python function is identical 90 to the help function built into the normal python interpreter. 91 """ 92 93
94 - def __repr__(self):
95 return self.text
96 97
98 - def __call__(self, *args, **kwds):
99 return pydoc.help(*args, **kwds)
100