mailr16568 - in /branches/uf_redesign/prompt: uf_docstring.py uf_objects.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 31, 2012 - 17:44:
Author: bugman
Date: Thu May 31 17:44:21 2012
New Revision: 16568

URL: http://svn.gna.org/viewcvs/relax?rev=16568&view=rev
Log:
Tables in the user function descriptions are now formatted for the prompt 
help strings.

This is for the Desc_container objects.  The list of lists are now converted 
to the text format
originally used for the user function docstrings such as:

__________________________________________________________________________
|                        |                                               |
| Minimisation algorithm | Patterns                                      |
|________________________|_______________________________________________|
|                        |                                               |
| Simplex                | '^[Ss]implex$'                                |
|                        |                                               |
| Levenberg-Marquardt    | '^[Ll][Mm]$' or '^[Ll]evenburg-[Mm]arquardt$' |
|________________________|_______________________________________________|


Modified:
    branches/uf_redesign/prompt/uf_docstring.py
    branches/uf_redesign/prompt/uf_objects.py

Modified: branches/uf_redesign/prompt/uf_docstring.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/prompt/uf_docstring.py?rev=16568&r1=16567&r2=16568&view=diff
==============================================================================
--- branches/uf_redesign/prompt/uf_docstring.py (original)
+++ branches/uf_redesign/prompt/uf_docstring.py Thu May 31 17:44:21 2012
@@ -79,6 +79,59 @@
     return new
 
 
+def create_table(table):
+    """Format and return the table as text.
+
+    @param table:   The table data.
+    @type table:    list of lists of str
+    @return:        The formatted table.
+    @rtype:         str
+    """
+
+    # Initialise some variables.
+    text = ''
+    num_rows = len(table)
+    num_cols = len(table[0])
+
+    # The column widths.
+    widths = [0] * num_cols
+    for i in range(len(table)):
+        for j in range(num_cols):
+            # The element is larger than the previous.
+            if len(table[i][j]) > widths[j]:
+                widths[j] = len(table[i][j])
+
+    # The free space for the text.
+    used = 0
+    used += 2    # Start of the table '| '.
+    used += 2    # End of the table ' |'.
+    used += 3 * (num_cols - 1)   # Middle of the table ' | '.
+    free_space = status.text_width - used
+
+    # The total table width.
+    total_width = sum(widths)
+
+    # The header.
+    text += "_" * (total_width+used) + "\n"    # Top rule.
+    text += table_line(widths=widths)    # Blank line.
+    text += table_line(text=table[0], widths=widths)    # The headers.
+    text += table_line(widths=widths, bottom=True)    # Middle rule.
+
+    # The table contents.
+    for i in range(1, num_rows):
+        text += table_line(widths=widths)    # Blank line.
+        text += table_line(text=table[i], widths=widths)    # The contents.
+
+    # The bottom.
+    text += table_line(widths=widths, bottom=True)    # Bottom rule.
+
+    # Add a newline.
+    text += '\n'
+
+    # Return the table text.
+    return text
+
+
 def format_text(text):
     """Format the line of text by wrapping.
 
@@ -97,3 +150,54 @@
 
     # Return the formatted text.
     return new_text
+
+
+def table_line(text=None, widths=None, bottom=False):
+    """Format a line of a table.
+
+    @keyword text:      The list of table elements.  If not given, an empty 
line will be be produced.
+    @type text:         list of str or None
+    @keyword widths:    The list of column widths for the table.
+    @type widths:       list of int
+    @keyword botton:    A flag which if True will cause a table bottom line 
to be produced.
+    @type bottom:       bool
+    @return:            The table line.
+    @rtype:             str
+    """
+
+    # Initialise.
+    if bottom:
+        line = "|_"
+    else:
+        line = "| "
+
+    # Loop over the columns.
+    for i in range(len(widths)):
+        # The column separator.
+        if i > 0:
+            if bottom:
+                line += "_|_"
+            else:
+                line += " | "
+
+        # A bottom line.
+        if bottom:
+            line += "_" * widths[i]
+
+        # Empty line.
+        elif text == None:
+            line += " " * widths[i]
+
+        # The text.
+        else:
+            line += text[i]
+            line += " " * (widths[i] - len(text[i]))
+
+    # Close the line.
+    if bottom:
+        line += "_|\n"
+    else:
+        line += " |\n"
+
+    # Return the text.
+    return line

Modified: branches/uf_redesign/prompt/uf_objects.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/prompt/uf_objects.py?rev=16568&r1=16567&r2=16568&view=diff
==============================================================================
--- branches/uf_redesign/prompt/uf_objects.py (original)
+++ branches/uf_redesign/prompt/uf_objects.py Thu May 31 17:44:21 2012
@@ -25,7 +25,7 @@
 
 # relax module imports.
 import arg_check
-from prompt.uf_docstring import bold_text, build_subtitle, format_text
+from prompt.uf_docstring import bold_text, build_subtitle, create_table, 
format_text
 from prompt.help import relax_class_help
 from relax_errors import RelaxError
 from relax_string import strip_lead




Related Messages


Powered by MHonArc, Updated Fri Jun 01 00:00:02 2012