当前位置: 首页>>代码示例>>Python>>正文


Python paragraph.Paragraph类代码示例

本文整理汇总了Python中rtfng.document.paragraph.Paragraph的典型用法代码示例。如果您正苦于以下问题:Python Paragraph类的具体用法?Python Paragraph怎么用?Python Paragraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Paragraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_CustomElementInsidePara

    def test_CustomElementInsidePara(self):

        # It's just too hard to write a standard test with a custom renderer.
        doc, section, styles = RTFTestCase.initializeDoc()
        p = Paragraph()
        p.append('This is a standard paragraph with the default style.')
        class CustomClass(object):
            pass
        p.append(CustomClass())
        section.append(p)
        
        # Define renderer with custom element support.
        specialString = "ABC I'm unique"
        def customElementWriter(renderer, element):
            renderer._write(specialString)
        r = Renderer(write_custom_element_callback=customElementWriter)
        
        # Render with custom element.
        result = StringIO()
        r.Write(doc, result)
        testData = result.getvalue()
        result.close()
        
        # Confirm generate result has custom rendering.
        assert specialString in testData
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:25,代码来源:test_characters.py

示例2: make_charFrame

 def make_charFrame():
     doc, section, styles = RTFTestCase.initializeDoc()
     p = Paragraph()
     thinEdge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=styles.Colours.Blue)
     textWithFrame = TextPropertySet(frame=thinEdge)
     p.append(Text('This tests frame drawn around text.', textWithFrame))
     section.append(p)
     return doc
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:8,代码来源:test_characters.py

示例3: addIdentificationResults

    def addIdentificationResults(self, document):
        survey = self.request.survey
        section = createIdentificationReportSection(
            document, self.context, self.request)

        styles = document.StyleSheet.ParagraphStyles
        header_styles = {
            0: styles.Heading2,
            1: styles.Heading3,
            2: styles.Heading4,
            3: styles.Heading5,
            4: styles.Heading6,
        }

        for node in self.getNodes():
            section.append(
                Paragraph(
                    header_styles.get(node.depth, styles.Heading6),
                    u"%s %s" % (node.number, node.title))
            )

            if node.type != "risk":
                continue

            zodb_node = survey.restrictedTraverse(node.zodb_path.split("/"))
            section.append(
                Paragraph(
                    styles.Normal,
                    utils.html_unescape(
                        htmllaundry.StripMarkup(zodb_node.description))
                )
            )

            for i in range(0, 8):
                p = Paragraph(styles.Normal, " ")
                section.append(p)

            tabs = TabPropertySet(
                section.TwipsToRightMargin(),
                alignment=TabPropertySet.RIGHT,
                leader=getattr(TabPropertySet, 'UNDERLINE')
            )
            p = Paragraph(styles.Normal, ParagraphPropertySet(tabs=[tabs]))
            p.append(TAB)
            section.append(p)

            if node.comment and node.comment.strip():
                section.append(Paragraph(styles.Comment, node.comment))
开发者ID:garbas,项目名称:osha.oira,代码行数:48,代码来源:report.py

示例4: make_paraIndents

    def make_paraIndents():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append(
            "The paragraphs below demonstrate the flexibility , the following is all at the "
            "same indent level and the one after it has the first line at a "
            "different indent to the rest. The third has the first line "
            "going in the other direction and is also separated by a page "
            "break. Note that the FirstLineIndent is defined as being the "
            "difference from the LeftIndent."
        )
        creditURL = "http://www.shakespeare-online.com/plots/1kh4ps.html"
        section.append("(Paragraph text from %s.)" % creditURL)

        sampleParagraph = """The play opens one year after the death of Richard
            II, and King Henry is making plans for a crusade to the
            Holy Land to cleanse himself of the guilt he feels over the
            usurpation of Richard's crown. But the crusade must be postponed
            when Henry learns that Welsh rebels, led by Owen Glendower, have
            defeated and captured Mortimer. Although the brave Henry Percy,
            nicknamed Hotspur, has quashed much of the uprising, there is still
            much trouble in Scotland. King Henry has a deep admiration for
            Hotspur and he longs for his own son, Prince Hal, to
            display some of Hotspur's noble qualities. Hal is more comfortable
            in a tavern than on the battlefield, and he spends his days
            carousing with riff-raff in London. But King Henry also has his
            problems with the headstrong Hotspur, who refuses to turn over his
            prisoners to the state as he has been so ordered.
            Westmoreland tells King Henry that Hotspur has many of
            the traits of his uncle, Thomas Percy, the Earl of Worcester, and
            defying authority runs in the family."""
        sampleParagraph = re.sub("\s+", " ", sampleParagraph)
        para_props = ParagraphPropertySet()
        para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3)
        p = Paragraph(styles.ParagraphStyles.Normal, para_props)
        p.append(sampleParagraph)
        section.append(p)

        para_props = ParagraphPropertySet()
        para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH * -2)
        para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3)
        p = Paragraph(styles.ParagraphStyles.Normal, para_props)
        p.append(sampleParagraph)
        section.append(p)

        para_props = ParagraphPropertySet()
        para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH)
        para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH)
        p = Paragraph(styles.ParagraphStyles.Normal, para_props)
        p.append(sampleParagraph)
        section.append(p)
        return doc
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:51,代码来源:test_paragraphs.py

示例5: make_charTab

 def make_charTab():
     doc, section, styles = RTFTestCase.initializeDoc()
     p = Paragraph()
     p.append('Before tab')
     p.append(Text(TAB))
     p.append('After tab')
     section.append(p)
     return doc
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:8,代码来源:test_characters.py

示例6: export

    def export(self, tempdir):
        self.outpath = os.path.join(tempdir, 'export.rtf')
        self.imgnum = 1

        doc = Document()
        self.ss = doc.StyleSheet

        export_title = u'Export (%d records)' % len(self.objs)

        on_empty_page = True

        if self.custom_order:
            emitter = self.custom_emit_fields
        else:
            emitter = self.record_emit_fields

        count = 0
        size = len(self.objs)
        while len(self.objs) > 0:
            count += 1
            yield "Formatting record %d of %d" % (count, size)
            r = self.objs.pop(0)

            if on_empty_page:
                section = Section()
            else:
                section = Section(break_type=Section.PAGE)
            on_empty_page = False

            p = Paragraph(self.ss.ParagraphStyles.Heading1)
            p.append(r.title)
            section.append(p)

            for p in self.emit_paragraphs(r, emitter(r)):
                section.append(p)

            if len(section) > 0:
                doc.Sections.append(section)

        fd = open(self.outpath, "wb")
        doc.write(fd)
        fd.close()
开发者ID:exploratour,项目名称:exploratour,代码行数:42,代码来源:rtf_exporter.py

示例7: make_paraTabs

 def make_paraTabs():
     doc, section, styles = RTFTestCase.initializeDoc()
     p = Paragraph()
     p.append(
         "The paragraph itself can also be overridden in lots of ways: "
         "tabs, borders, alignment, etc., can all be modified either in "
         "the style or as an override during the creation of the "
         "paragraph. This is demonstrated below with custom tab widths "
         "and embedded carriage returns (i.e., new line markers that do "
         "not cause a paragraph break)."
     )
     section.append(p)
     tabs = [
         TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH),
         TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH * 2),
         TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH),
     ]
     para_props = ParagraphPropertySet(tabs=tabs)
     p = Paragraph(styles.ParagraphStyles.Normal, para_props)
     p.append(
         "Phrase at Left Tab",
         TAB,
         "Middle Phrase One",
         TAB,
         "Right Phrase",
         LINE,
         "Second Left Phrase",
         TAB,
         "Middle Phrase Two",
         TAB,
         "Another Right Phrase",
     )
     section.append(p)
     return doc
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:34,代码来源:test_paragraphs.py

示例8: make_headerFooterDiffPages

    def make_headerFooterDiffPages():
        doc     = Document()
        ss      = doc.StyleSheet
        section = Section()
        doc.Sections.append( section )

        section.FirstHeader.append( 'This is the header for the first page.' )
        section.FirstFooter.append( 'This is the footer for the first page.' )

        section.Header.append( 'This is the header that will appear on subsequent pages.' )
        section.Footer.append( 'This is the footer that will appear on subsequent pages.' )

        p = Paragraph( ss.ParagraphStyles.Heading1 )
        p.append( 'Example 6' )
        section.append( p )

        #    blank paragraphs are just empty strings
        section.append( '' )

        p = Paragraph( ss.ParagraphStyles.Normal )
        p.append( 'This document has different headers and footers for the first and then subsequent pages. '
                  'If you insert a page break you should see a different header and footer.' )
        section.append( p )

        return doc
开发者ID:brew,项目名称:pyrtf-ng,代码行数:25,代码来源:test_headerfooter.py

示例9: make_paraDefaultPreviousStyle

 def make_paraDefaultPreviousStyle():
     doc, section, styles = RTFTestCase.initializeDoc()
     p1 = Paragraph(styles.ParagraphStyles.Heading1)
     p1.append('Heading 1')
     section.append(p1)
     p2 = Paragraph(styles.ParagraphStyles.Normal)
     p2.append(
         'In this case we have used two styles. The first paragraph is '
         'marked with the Heading1 style, and this one is marked with the '
         'Normal style.')
     section.append(p2)
     p3 = Paragraph()
     p3.append(
         'Notice that after changing the style of the paragraph to Normal '
         '(in the previous paragraph), all subsequent paragraphs have '
         'that style automatically. This saves typing and is actually the '
         'default native behaviour for RTF documents.')
     section.append(p3)
     return doc
开发者ID:brew,项目名称:pyrtf-ng,代码行数:19,代码来源:test_paragraphs.py

示例10: test_paraAsList

    def test_paraAsList(self):
        text1 = "First line"
        text2 = "Second line"
        text3 = "Third line"

        # Build paragraph using constructor.
        p1 = Paragraph(text1, text2, text3)

        # Build paragraph using append.
        p2 = Paragraph()
        p2.append(text1)
        p2.append(text2)
        p2.append(text3)

        # Build paragraph using insert.
        p3 = Paragraph()
        p3.insert(0, text1)
        p3.insert(1, text2)
        p3.insert(2, text3)

        # Confirm contents are same.
        assert p1[0:-1] == p2[0:-1]
        assert p2[0:-1] == p3[0:-1]
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:23,代码来源:test_paragraphs.py

示例11: addConsultationBox

    def addConsultationBox(self, section, document):
        """ Add the consultation box that needs to be signed by the employer
            and workers.
        """
        ss = document.StyleSheet
        styles = document.StyleSheet.ParagraphStyles
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])

        table = Table(9500)
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        no_edge = BorderPropertySet(width=0, colour=ss.Colours.White)
        p = Paragraph(
            styles.Heading3,
            ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER),
            t(_("header_oira_report_consultation",
                default="Consultation of workers"))
        )
        c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        p = Paragraph(
            styles.Normal,
            ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT),
            t(_("paragraph_oira_consultation_of_workers",
                default="The undersigned hereby declare that the workers "
                        "have been consulted on the content of this "
                        "document.")),
            LINE
        )
        c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        p = Paragraph(
            styles.Normal,
            ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT),
        )
        employer = t(_("oira_consultation_employer",
                       default="On behalf of the employer:"))
        workers = t(_("oira_consultation_workers",
                    default="On behalf of the workers:"))

        p.append(employer, TAB, TAB, TAB, TAB, workers, LINE, LINE)
        c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        p = Paragraph(
            ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT),
            t(_("oira_survey_date", default="Date:")),
            LINE, LINE
        )
        c = Cell(p, FramePropertySet(no_edge, thin_edge, thin_edge, thin_edge))
        table.AddRow(c)
        section.append(table)
开发者ID:euphorie,项目名称:osha.oira,代码行数:56,代码来源:report.py

示例12: make_hyperlinks

 def make_hyperlinks():
     doc, section, styles = RTFTestCase.initializeDoc()
     p = Paragraph()
     p.append('This is a standard paragraph with the default style.')
     p = Paragraph()
     p.append('This is also a standard paragraph. ',
               'But lets add a ',
               TEXT('Washington Post', hyperlink='https://washingtonpost.com'),
               ' hyperlink to this paragraph. ',
               )
     section.append(p)
     return doc
开发者ID:tbrick855,项目名称:pyrtf-ng,代码行数:12,代码来源:test_characters.py

示例13: make_paraNormal

 def make_paraNormal():
     doc, section, styles = RTFTestCase.initializeDoc()
     p1 = Paragraph(styles.ParagraphStyles.Heading1)
     p1.append('Heading 1')
     section.append(p1)
     p2 = Paragraph(styles.ParagraphStyles.Normal)
     p2.append(
         'In this case we have used two styles. The first paragraph is '
         'marked with the Heading1 style, and this one is marked with the '
         'Normal style.')
     section.append(p2)
     return doc
开发者ID:brew,项目名称:pyrtf-ng,代码行数:12,代码来源:test_paragraphs.py

示例14: make_charStyleOverride

 def make_charStyleOverride():
     doc, section, styles = RTFTestCase.initializeDoc()
     p = Paragraph()
     p.append('This is a standard paragraph with the default style.')
     p = Paragraph()
     p.append('It is also possible to manully override a style. ',
               'This is a change of just the font ',
               TEXT('size', size=48),
               ' an this is for just the font ',
               TEXT('typeface', font=styles.Fonts.Impact) ,
               '.')
     section.append(p)
     return doc
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:13,代码来源:test_characters.py

示例15: make_charUnicode

    def make_charUnicode():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append('This tests unicode.')
        
        p = Paragraph()
        p.append(u'32\u00B0 Fahrenheit is 0\u00B0 Celsuis')
        section.append(p)
        
        p = Paragraph()
        p.append(u'Henry \u2163 is Henry IV in unicode.')
        section.append(p)
        

        return doc
开发者ID:oubiwann-unsupported,项目名称:pyrtf,代码行数:14,代码来源:test_characters.py


注:本文中的rtfng.document.paragraph.Paragraph类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。