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

Source Code for Module prompt.uf_docstring

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-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 base class for all the user function classes.""" 
 24   
 25  # Python module imports. 
 26  from textwrap import wrap 
 27   
 28  # relax module imports. 
 29  from lib.text.table import format_table 
 30  from status import Status; status = Status() 
 31  from user_functions.data import Uf_tables; uf_tables = Uf_tables() 
 32   
 33   
34 -def bold_text(text):
35 """Convert the text to bold. 36 37 This is for use in the help system. 38 39 @param text: The text to make bold. 40 @type text: str 41 @return: The bold text. 42 @rtype: str 43 """ 44 45 # Init. 46 new_text = '' 47 48 # Add the bold character to all characters. 49 for i in range(len(text)): 50 new_text += "%s\b%s" % (text[i], text[i]) 51 52 # Return the text. 53 return new_text
54 55
56 -def build_subtitle(text, bold=True, start_nl=True):
57 """Create the formatted subtitle string. 58 59 @param text: The name of the subtitle. 60 @type text: str 61 @keyword bold: A flag which if true will return bold text. Otherwise an underlined title will be returned. 62 @type bold: bool 63 @keyword start_nl: A flag which if True will add a newline to the start of the text. 64 @type start_nl: bool 65 @return: The formatted subtitle. 66 @rtype: str 67 """ 68 69 # Starting newline. 70 if start_nl: 71 new = "\n" 72 else: 73 new = "" 74 75 # Bold. 76 if bold: 77 new += "%s\n\n" % bold_text(text) 78 79 # Underline. 80 else: 81 new += "%s\n%s\n\n" % (text, "~"*len(text)) 82 83 # Return the subtitle. 84 return new
85 86
87 -def create_table(label):
88 """Format and return the table as text. 89 90 @param label: The unique table label. 91 @type label: str 92 @return: The formatted table. 93 @rtype: str 94 """ 95 96 # Get the table. 97 table = uf_tables.get_table(label) 98 99 # Initialise some variables. 100 text = '' 101 num_rows = len(table.cells) 102 num_cols = len(table.headings) 103 104 # Generate and return the table. 105 return format_table(headings=[table.headings], contents=table.cells, max_width=status.text_width, spacing=table.spacing, debug=status.debug)
106 107
108 -def format_text(text):
109 """Format the line of text by wrapping. 110 111 @param text: The line of text to wrap. 112 @type text: str 113 @return: The wrapped text. 114 @rtype: str 115 """ 116 117 # Then wrap each line. 118 new_text = "" 119 120 # Wrap the line. 121 for wrapped_line in wrap(text, status.text_width): 122 new_text += wrapped_line + "\n" 123 124 # Return the formatted text. 125 return new_text
126