1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  """The base class for all the user function classes.""" 
 24   
 25   
 26  from textwrap import wrap 
 27   
 28   
 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   
 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       
 46      new_text = '' 
 47   
 48       
 49      for i in range(len(text)): 
 50          new_text += "%s\b%s" % (text[i], text[i]) 
 51   
 52       
 53      return new_text 
  54   
 55   
 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       
 70      if start_nl: 
 71          new = "\n" 
 72      else: 
 73          new = "" 
 74   
 75       
 76      if bold: 
 77          new += "%s\n\n" % bold_text(text) 
 78   
 79       
 80      else: 
 81          new += "%s\n%s\n\n" % (text, "~"*len(text)) 
 82   
 83       
 84      return new 
  85   
 86   
 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       
 97      table = uf_tables.get_table(label) 
 98   
 99       
100      text = '' 
101      num_rows = len(table.cells) 
102      num_cols = len(table.headings) 
103   
104       
105      return format_table(headings=[table.headings], contents=table.cells, max_width=status.text_width, spacing=table.spacing, debug=status.debug) 
 106   
107   
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       
118      new_text = "" 
119   
120       
121      for wrapped_line in wrap(text, status.text_width): 
122          new_text += wrapped_line + "\n" 
123   
124       
125      return new_text 
 126