mailr18910 - in /trunk/lib/text: __init__.py sectioning.py


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

Header


Content

Posted by edward on March 20, 2013 - 14:13:
Author: bugman
Date: Wed Mar 20 14:13:27 2013
New Revision: 18910

URL: http://svn.gna.org/viewcvs/relax?rev=18910&view=rev
Log:
Created the new lib.text.sectioning module for formatting titles, subtitles 
and other sectioning text.

The two functions title() and subtitle() have been implemented.


Added:
    trunk/lib/text/sectioning.py
Modified:
    trunk/lib/text/__init__.py

Modified: trunk/lib/text/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/text/__init__.py?rev=18910&r1=18909&r2=18910&view=diff
==============================================================================
--- trunk/lib/text/__init__.py (original)
+++ trunk/lib/text/__init__.py Wed Mar 20 14:13:27 2013
@@ -23,5 +23,6 @@
 """The relax-lib text package - a library of functions for text 
manipulation."""
 
 __all__ = [
+    'sectioning',
     'table'
 ]

Added: trunk/lib/text/sectioning.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/text/sectioning.py?rev=18910&view=auto
==============================================================================
--- trunk/lib/text/sectioning.py (added)
+++ trunk/lib/text/sectioning.py Wed Mar 20 14:13:27 2013
@@ -1,0 +1,72 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2013 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# This program is distributed in the hope that it will be useful,            
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""Functions for the formatting of titles, subtitles and other sectioning."""
+
+
+def subtitle(file=None, text=None):
+    """Format and write out a subtitle to the given file.
+
+    @keyword file:      The file object to write to.
+    @type file:         file object
+    @keyword text:      The subtitle.
+    @type text:         str
+    """
+
+    # The length and hline text.
+    length = len(text) + 2
+    hline = '#' * length
+
+    # First the spacing above the section.
+    file.write("\n")
+
+    # The text.
+    file.write("# %s\n" % text)
+    file.write("%s\n" % hline)
+
+    # Final spacing.
+    file.write("\n")
+
+
+def title(file=None, text=None):
+    """Format and write out a title to the given file.
+
+    @keyword file:      The file object to write to.
+    @type file:         file object
+    @keyword text:      The title.
+    @type text:         str
+    """
+
+    # The length and hline text.
+    length = len(text) + 4
+    hline = '#' * length
+
+    # First the spacing above the section.
+    file.write("\n\n")
+
+    # The text.
+    file.write("%s\n" % hline)
+    file.write("# %s #\n" % text)
+    file.write("%s\n" % hline)
+
+    # Final spacing.
+    file.write("\n")




Related Messages


Powered by MHonArc, Updated Wed Mar 20 14:20:02 2013