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.                                     # 
 6  #                                                                             # 
 7  # relax 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 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax 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 relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Module docstring. 
24  """The prompt UI help system.""" 
25   
26  # Python module imports. 
27  import pydoc 
28  import sys 
29  from textwrap import wrap 
30   
31  # relax module imports. 
32  from status import Status; status = Status() 
33   
34   
35  # Generic string printed out for function classes. 
36  ################################################## 
37   
38  relax_class_help = """ 
39  This is a python class which contains user functions.  To list these functions, either place a 
40  period at the end of class name and hit the tab key, or type 'dir(class_name)'. 
41  """ 
42   
43   
44  # Helper classes. 
45  ################# 
46   
47 -class _Helper:
48 text = """\ 49 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()'. 50 """ 51
52 - def __repr__(self):
53 """String representation of the object. 54 55 @return: The help description. 56 @rtype: str 57 """ 58 59 # Wrap the text. 60 string = '' 61 for line in wrap(self.text, status.text_width): 62 string += line + '\n' 63 64 # Return the wrapped text. 65 return string
66 67
68 - def __call__(self, *args, **kwds):
69 if len(args) != 1 or isinstance(args[0], str): 70 print((self.text)) 71 return 72 if hasattr(args[0], '__relax_help__'): 73 sys.stdout.write(args[0].__relax_help__ + "\n") 74 return 75 return pydoc.help(*args, **kwds)
76 77
78 -class _Helper_python:
79 text = """\ 80 For the interactive python help system, type 'help_python()'. The help_python function is identical 81 to the help function built into the normal python interpreter. 82 """ 83 84
85 - def __repr__(self):
86 return self.text
87 88
89 - def __call__(self, *args, **kwds):
90 return pydoc.help(*args, **kwds)
91