Author: bugman Date: Fri Jul 1 15:48:29 2011 New Revision: 13365 URL: http://svn.gna.org/viewcvs/relax?rev=13365&view=rev Log: Created the _build_doc() and _build_subtitle() base class methods for constructing docstrings. These base class methods take private variables to construct the docstrings, and will allow this text to be shared across UIs. Modified: branches/gui_testing/prompt/base_class.py Modified: branches/gui_testing/prompt/base_class.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/prompt/base_class.py?rev=13365&r1=13364&r2=13365&view=diff ============================================================================== --- branches/gui_testing/prompt/base_class.py (original) +++ branches/gui_testing/prompt/base_class.py Fri Jul 1 15:48:29 2011 @@ -23,10 +23,13 @@ # Module docstring. """The base class for all the user function classes.""" +# Python module imports. +import platform +from textwrap import wrap + # relax module imports. import help from string import split, strip - class Basic_class: @@ -124,3 +127,53 @@ # Return the new text. return new_text + + + def _build_doc(self, fn): + """Build the fn.__doc__ docstring. + + @param fn: The user function to build the docstring for. + @type fn: method + """ + + # Initialise. + doc = "" + + # Add the title. + doc = "%s%s\n\n" % (doc, fn._doc_title) + + # Add the keyword args. + doc = doc + self._build_subtitle("Keyword Arguments") + for arg, desc in fn._doc_args: + doc = "%s%s: %s\n\n" % (doc, arg, desc) + + # Add the description. + doc = doc + self._build_subtitle("Description") + doc = doc + fn._doc_desc + + # Add the examples. + doc = doc + self._build_subtitle("Examples") + doc = doc + fn._doc_examples + + # The width of the document text. + if platform.uname()[0] in ['Windows', 'Microsoft']: + width = 80 + else: + width = 100 + + # Create and wrap the docstring. + fn.__doc__ = "" + for line in wrap(doc, width): + fn.__doc__ = fn.__doc__ + line + "\n" + + + def _build_subtitle(self, text): + """Create the formatted subtitle string. + @param text: The name of the subtitle. + @type text: str + @return: The formatted subtitle. + @rtype: str + """ + + # Format and return. + return "%s\n%s\n\n" % (text, "~"*len(text))