Exemplo n.º 1
0
 def test_text(self):
     t = Text()
     t = Text('abc')
     style = StyleSheet()
     normalText = TextStyle(TextPropertySet(style.Fonts.Arial, 22))
     blue = TextPropertySet(colour=style.Colours.Blue)
     shading = ShadingPropertySet()
     t = Text(normalText, blue, shading, 'abc')
Exemplo n.º 2
0
 def make_charColours():
     doc, section, styles = RTFTestCase.initializeDoc()
     section.append('This example test changing the colour of fonts.')
     # Text properties can be specified in two ways, either a text object
     # can have its text properties specified via the TextPropertySet
     # object, or by passing the colour parameter as a style.
     red = TextPropertySet(colour=styles.Colours.Red)
     green = TextPropertySet(colour=styles.Colours.Green)
     blue = TextPropertySet(colour=styles.Colours.Blue)
     yellow = TextPropertySet(colour=styles.Colours.Yellow)
     p = Paragraph()
     p.append('This next word should be in ')
     p.append(Text('red', red))
     p.append(', while the following should be in their respective ')
     p.append('colours: ', Text('blue ', blue), Text('green ', green))
     p.append('and ', TEXT('yellow', colour=styles.Colours.Yellow), '.')
     # When specifying colours it is important to use the colours from the
     # style sheet supplied with the document and not the StandardColours
     # object each document get its own copy of the stylesheet so that
     # changes can be made on a document by document basis without mucking
     # up other documents that might be based on the same basic stylesheet.
     section.append(p)
     return doc
Exemplo n.º 3
0
    def append(self, *values):
        self._text_elements = list()
        from PyRTF.document.character import Text

        _idx = 0
        for value in values:
            if value is not None:
                a_text = _text_strip(value['value'])
                a_style = value.get('style', self._style)
                new_item = Text()
                if isinstance(a_style, type(self._style)):
                    new_item.Style = a_style.TextStyle
                else:
                    #from PyRTF.Styles import ParagraphStyle
                    #from PyRTF.PropertySets import ParagraphPropertySet
                    # TODO: parse and get the actual text_style here, wrapped with ParagraphStyle object;
                    pass
                if _idx > 0:
                    new_item.SetData(unicode(self.DELIMITER_INLINE))
                new_item.SetData(a_text)
                self._text_elements.append(new_item)
            _idx += 1
Exemplo n.º 4
0
def basic_table_with_input(dependent_variable_name,
                           rows_statistical_significance,
                           number_of_observations, r_squared):
    #from PyRTF.Elements import Document, Section, BorderPropertySet, FramePropertySet, Table
    from PyRTF.utils import RTFTestCase
    from PyRTF.Elements import Document
    from PyRTF.document.section import Section
    from PyRTF.document.paragraph import Cell, Paragraph, Table
    #from PyRTF.Styles import TextStyle, ParagraphStyle
    from PyRTF.document.character import Text
    from PyRTF.PropertySets import BorderPropertySet, FramePropertySet, MarginsPropertySet, ParagraphPropertySet, TabPropertySet, TextPropertySet
    #
    doc = Document()
    ss = doc.StyleSheet
    section = Section()
    doc.Sections.append(section)
    #
    thin_edge = BorderPropertySet(width=20,
                                  style=BorderPropertySet.SINGLE,
                                  colour=ss.Colours.Black)
    thick_edge = BorderPropertySet(width=80, style=BorderPropertySet.SINGLE)
    zero_edge_thin = BorderPropertySet(width=20,
                                       style=BorderPropertySet.SINGLE,
                                       colour=ss.Colours.White)
    #
    thin_frame = FramePropertySet(thin_edge, thin_edge, thin_edge, thin_edge)
    thick_frame = FramePropertySet(thick_edge, thick_edge, thick_edge,
                                   thick_edge)
    thin_frame_top_only = FramePropertySet(top=thin_edge,
                                           left=None,
                                           bottom=None,
                                           right=None)
    thin_frame_bottom_only = FramePropertySet(top=None,
                                              left=None,
                                              bottom=thin_edge,
                                              right=None)
    thin_frame_top_and_bottom_only = FramePropertySet(top=thin_edge,
                                                      left=None,
                                                      bottom=thin_edge,
                                                      right=None)
    zero_frame = FramePropertySet(top=None, left=None, bottom=None, right=None)
    #
    table = Table(TabPropertySet.DEFAULT_WIDTH * 5,
                  TabPropertySet.DEFAULT_WIDTH * 3,
                  TabPropertySet.DEFAULT_WIDTH * 3)
    #
    c1 = Cell(Paragraph(''), thin_frame_top_and_bottom_only)
    c2 = Cell(Paragraph(dependent_variable_name + ' - coeff'),
              thin_frame_top_and_bottom_only)
    c3 = Cell(Paragraph(dependent_variable_name + ' - Std error'),
              thin_frame_top_and_bottom_only)
    table.AddRow(c1, c2, c3)
    #
    for row in rows_statistical_significance:
        c1 = Cell(Paragraph(row[0]), zero_frame)
        c2 = Cell(Paragraph(row[1]), zero_frame)
        c3 = Cell(Paragraph(row[2]), zero_frame)
        table.AddRow(c1, c2, c3)
    #
    #c1 = Cell(Paragraph(''), thin_frame_bottom_only)
    #c2 = Cell(Paragraph('(.013)'), thin_frame_bottom_only)
    #c3 = Cell(Paragraph('tbd'), thin_frame_bottom_only)
    #table.AddRow(c1, c2)
    #
    c1 = Cell(Paragraph('Observations'), thin_frame_top_only)
    c2 = Cell(Paragraph(number_of_observations), thin_frame_top_only)
    c3 = Cell(Paragraph(''), thin_frame_top_only)
    table.AddRow(c1, c2, c3)
    #
    tps = TextPropertySet(italic=True)
    text = Text('R^2', tps)
    #
    #c1 = Cell(Paragraph('R^2', text), thin_frame_bottom_only)
    c1 = Cell(Paragraph(text), thin_frame_bottom_only)
    c2 = Cell(Paragraph(r_squared), thin_frame_bottom_only)
    c3 = Cell(Paragraph(''), thin_frame_bottom_only)
    table.AddRow(c1, c2, c3)
    #
    section.append(table)
    #
    section.append('Standard errors in parentheses')
    section.append('* p<0.1, ** p<0.05, *** p<0.01')
    #
    return doc
Exemplo n.º 5
0
def basic_table():
    #from PyRTF.Elements import Document, Section, BorderPropertySet, FramePropertySet, Table
    from PyRTF.utils import RTFTestCase
    from PyRTF.Elements import Document
    from PyRTF.document.section import Section
    from PyRTF.document.paragraph import Cell, Paragraph, Table
    #from PyRTF.Styles import TextStyle, ParagraphStyle
    from PyRTF.document.character import Text
    from PyRTF.PropertySets import BorderPropertySet, FramePropertySet, MarginsPropertySet, ParagraphPropertySet, TabPropertySet, TextPropertySet
    #
    doc = Document()
    ss = doc.StyleSheet
    section = Section()
    doc.Sections.append(section)
    #
    thin_edge = BorderPropertySet(width=20,
                                  style=BorderPropertySet.SINGLE,
                                  colour=ss.Colours.Black)
    thick_edge = BorderPropertySet(width=80, style=BorderPropertySet.SINGLE)
    zero_edge_thin = BorderPropertySet(width=20,
                                       style=BorderPropertySet.SINGLE,
                                       colour=ss.Colours.White)
    #
    thin_frame = FramePropertySet(thin_edge, thin_edge, thin_edge, thin_edge)
    thick_frame = FramePropertySet(thick_edge, thick_edge, thick_edge,
                                   thick_edge)
    thin_frame_top_only = FramePropertySet(top=thin_edge,
                                           left=None,
                                           bottom=None,
                                           right=None)
    thin_frame_bottom_only = FramePropertySet(top=None,
                                              left=None,
                                              bottom=thin_edge,
                                              right=None)
    thin_frame_top_and_bottom_only = FramePropertySet(top=thin_edge,
                                                      left=None,
                                                      bottom=thin_edge,
                                                      right=None)
    #
    table = Table(TabPropertySet.DEFAULT_WIDTH * 5,
                  TabPropertySet.DEFAULT_WIDTH * 3)
    #
    c1 = Cell(Paragraph(''), thin_frame_top_and_bottom_only)
    c2 = Cell(Paragraph('Recommends AI'), thin_frame_top_and_bottom_only)
    #c3 = Cell(Paragraph('tbd'), thin_frame_top_and_bottom_only)
    table.AddRow(c1, c2)
    #
    c1 = Cell(Paragraph('Read ethics article'), thin_frame_top_only)
    c2 = Cell(Paragraph('-.38***'), thin_frame_top_only)
    #c3 = Cell(Paragraph('tbd'), thin_frame_top_only)
    table.AddRow(c1, c2)
    #
    c1 = Cell(Paragraph(''), thin_frame_bottom_only)
    c2 = Cell(Paragraph('(.013)'), thin_frame_bottom_only)
    #c3 = Cell(Paragraph('tbd'), thin_frame_bottom_only)
    table.AddRow(c1, c2)
    #
    c1 = Cell(Paragraph('Observations'), thin_frame_top_only)
    c2 = Cell(Paragraph('5000'), thin_frame_top_only)
    #c3 = Cell(Paragraph('tbd'), thin_frame_top_and_bottom_only)
    table.AddRow(c1, c2)
    #
    tps = TextPropertySet(italic=True)
    text = Text('R^2', tps)
    #
    #c1 = Cell(Paragraph('R^2', text), thin_frame_bottom_only)
    c1 = Cell(Paragraph(text), thin_frame_bottom_only)
    c2 = Cell(Paragraph('0.147'), thin_frame_bottom_only)
    #c3 = Cell(Paragraph('tbd'), thin_frame_bottom_only)
    table.AddRow(c1, c2)
    #
    section.append(table)
    #
    section.append('Standard errors in parentheses')
    section.append('* p<0.1, ** p<0.05, *** p<0.01')
    #
    return doc