home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / t / the_format < prev    next >
Encoding:
Text File  |  1996-11-14  |  7.0 KB  |  133 lines

  1. <TITLE>The Formatter Interface -- Python library reference</TITLE>
  2. Next: <A HREF="../f/formatter_implementations" TYPE="Next">Formatter Implementations</A>  
  3. Prev: <A HREF="../f/formatter" TYPE="Prev">formatter</A>  
  4. Up: <A HREF="../f/formatter" TYPE="Up">formatter</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H2>10.10.1. The Formatter Interface</H2>
  7. Interfaces to create formatters are dependent on the specific
  8. formatter class being instantiated.  The interfaces described below
  9. are the required interfaces which all formatters must support once
  10. initialized.
  11. <P>
  12. One data element is defined at the module level:
  13. <P>
  14. <DL><DT><B>AS_IS</B> -- data of module formatter<DD>
  15. Value which can be used in the font specification passed to the
  16. <CODE>push_font()</CODE> method described below, or as the new value to any
  17. other <CODE>push_<VAR>property</VAR>()</CODE> method.  Pushing the <CODE>AS_IS</CODE>
  18. value allows the corresponding <CODE>pop_<VAR>property</VAR>()</CODE> method to
  19. be called without having to track whether the property was changed.
  20. </DL>
  21. The following attributes are defined for formatter instance objects:
  22. <P>
  23. <DL><DT><B>writer</B> -- data of formatter object data<DD>
  24. The writer instance with which the formatter interacts.
  25. </DL>
  26. <DL><DT><B>end_paragraph</B> (<VAR>blanklines</VAR>) -- Method on formatter object<DD>
  27. Close any open paragraphs and insert at least <CODE>blanklines</CODE>
  28. before the next paragraph.
  29. </DL>
  30. <DL><DT><B>add_line_break</B> () -- Method on formatter object<DD>
  31. Add a hard line break if one does not already exist.  This does not
  32. break the logical paragraph.
  33. </DL>
  34. <DL><DT><B>add_hor_rule</B> (*<VAR>args</VAR>, **<VAR>kw</VAR>) -- Method on formatter object<DD>
  35. Insert a horizontal rule in the output.  A hard break is inserted if
  36. there is data in the current paragraph, but the logical paragraph is
  37. not broken.  The arguments and keywords are passed on to the writer's
  38. <CODE>send_line_break()</CODE> method.
  39. </DL>
  40. <DL><DT><B>add_flowing_data</B> (<VAR>data</VAR>) -- Method on formatter object<DD>
  41. Provide data which should be formatted with collapsed whitespaces.
  42. Whitespace from preceeding and successive calls to
  43. <CODE>add_flowing_data()</CODE> is considered as well when the whitespace
  44. collapse is performed.  The data which is passed to this method is
  45. expected to be word-wrapped by the output device.  Note that any
  46. word-wrapping still must be performed by the writer object due to the
  47. need to rely on device and font information.
  48. </DL>
  49. <DL><DT><B>add_literal_data</B> (<VAR>data</VAR>) -- Method on formatter object<DD>
  50. Provide data which should be passed to the writer unchanged.
  51. Whitespace, including newline and tab characters, are considered legal
  52. in the value of <CODE>data</CODE>.  
  53. </DL>
  54. <DL><DT><B>add_label_data</B> (<VAR>format</VAR>, <VAR>counter</VAR>) -- Method on formatter object<DD>
  55. Insert a label which should be placed to the left of the current left
  56. margin.  This should be used for constructing bulleted or numbered
  57. lists.  If the <CODE>format</CODE> value is a string, it is interpreted as a
  58. format specification for <CODE>counter</CODE>, which should be an integer.
  59. The result of this formatting becomes the value of the label; if
  60. <CODE>format</CODE> is not a string it is used as the label value directly.
  61. The label value is passed as the only argument to the writer's
  62. <CODE>send_label_data()</CODE> method.  Interpretation of non-string label
  63. values is dependent on the associated writer.
  64. <P>
  65. Format specifications are strings which, in combination with a counter
  66. value, are used to compute label values.  Each character in the format
  67. string is copied to the label value, with some characters recognized
  68. to indicate a transform on the counter value.  Specifically, the
  69. character ``<CODE>1</CODE>'' represents the counter value formatter as an
  70. arabic number, the characters ``<CODE>A</CODE>'' and ``<CODE>a</CODE>'' represent
  71. alphabetic representations of the counter value in upper and lower
  72. case, respectively, and ``<CODE>I</CODE>'' and ``<CODE>i</CODE>'' represent the
  73. counter value in Roman numerals, in upper and lower case.  Note that
  74. the alphabetic and roman transforms require that the counter value be
  75. greater than zero.
  76. </DL>
  77. <DL><DT><B>flush_softspace</B> () -- Method on formatter object<DD>
  78. Send any pending whitespace buffered from a previous call to
  79. <CODE>add_flowing_data()</CODE> to the associated writer object.  This
  80. should be called before any direct manipulation of the writer object.
  81. </DL>
  82. <DL><DT><B>push_alignment</B> (<VAR>align</VAR>) -- Method on formatter object<DD>
  83. Push a new alignment setting onto the alignment stack.  This may be
  84. <CODE>AS_IS</CODE> if no change is desired.  If the alignment value is
  85. changed from the previous setting, the writer's <CODE>new_alignment()</CODE>
  86. method is called with the <CODE>align</CODE> value.
  87. </DL>
  88. <DL><DT><B>pop_alignment</B> () -- Method on formatter object<DD>
  89. Restore the previous alignment.
  90. </DL>
  91. <DL><DT><B>push_font</B> ((<VAR>size</VAR>, <VAR>italic</VAR>, <VAR>bold</VAR>, <VAR>teletype</VAR>)) -- Method on formatter object<DD>
  92. Change some or all font properties of the writer object.  Properties
  93. which are not set to <CODE>AS_IS</CODE> are set to the values passed in
  94. while others are maintained at their current settings.  The writer's
  95. <CODE>new_font()</CODE> method is called with the fully resolved font
  96. specification.
  97. </DL>
  98. <DL><DT><B>pop_font</B> () -- Method on formatter object<DD>
  99. Restore the previous font.
  100. </DL>
  101. <DL><DT><B>push_margin</B> (<VAR>margin</VAR>) -- Method on formatter object<DD>
  102. Increase the number of left margin indentations by one, associating
  103. the logical tag <CODE>margin</CODE> with the new indentation.  The initial
  104. margin level is <CODE>0</CODE>.  Changed values of the logical tag must be
  105. true values; false values other than <CODE>AS_IS</CODE> are not sufficient
  106. to change the margin.
  107. </DL>
  108. <DL><DT><B>pop_margin</B> () -- Method on formatter object<DD>
  109. Restore the previous margin.
  110. </DL>
  111. <DL><DT><B>push_style</B> (*<VAR>styles</VAR>) -- Method on formatter object<DD>
  112. Push any number of arbitrary style specifications.  All styles are
  113. pushed onto the styles stack in order.  A tuple representing the
  114. entire stack, including <CODE>AS_IS</CODE> values, is passed to the writer's
  115. <CODE>new_styles()</CODE> method.
  116. </DL>
  117. <DL><DT><B>pop_style</B> ([<VAR>n</VAR>@varcode = 1]) -- Method on formatter object<DD>
  118. Pop the last <CODE>n</CODE> style specifications passed to
  119. <CODE>push_style()</CODE>.  A tuple representing the revised stack,
  120. including <CODE>AS_IS</CODE> values, is passed to the writer's
  121. <CODE>new_styles()</CODE> method.
  122. </DL>
  123. <DL><DT><B>set_spacing</B> (<VAR>spacing</VAR>) -- Method on formatter object<DD>
  124. Set the spacing style for the writer.
  125. </DL>
  126. <DL><DT><B>assert_line_data</B> ([<VAR>flag</VAR>@varcode = 1]) -- Method on formatter object<DD>
  127. Inform the formatter that data has been added to the current paragraph
  128. out-of-band.  This should be used when the writer has been manipulated
  129. directly.  The optional <CODE>flag</CODE> argument can be set to false if
  130. the writer manipulations produced a hard line break at the end of the
  131. output.
  132. </DL>
  133.