當前位置: 首頁>>代碼示例>>Python>>正文


Python RTFTestCase.initializeDoc方法代碼示例

本文整理匯總了Python中rtfng.utils.RTFTestCase.initializeDoc方法的典型用法代碼示例。如果您正苦於以下問題:Python RTFTestCase.initializeDoc方法的具體用法?Python RTFTestCase.initializeDoc怎麽用?Python RTFTestCase.initializeDoc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rtfng.utils.RTFTestCase的用法示例。


在下文中一共展示了RTFTestCase.initializeDoc方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_paraTabs

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 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,代碼行數:36,代碼來源:test_paragraphs.py

示例2: make_docCopy

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 def make_docCopy():
     doc, section, styles = RTFTestCase.initializeDoc()
     section.append('First section')
     secondSection = doc.NewSection()
     secondSection.append('Second section.')
     copyDoc = doc.Copy()
     return doc
開發者ID:oubiwann-unsupported,項目名稱:pyrtf,代碼行數:9,代碼來源:test_sections.py

示例3: test_CustomElementInsidePara

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    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,代碼行數:27,代碼來源:test_characters.py

示例4: make_pictures

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    def make_pictures():
        doc, section, styles = RTFTestCase.initializeDoc()

        # text can be added directly to the section a paragraph object is create as needed
        section.append( 'Image Example 1' )

        section.append( 'You can add images in one of two ways, either converting the '
                        'image each and every time like;' )

        image = Image( 'examples/image.jpg' )
        section.append( Paragraph( image ) )

        section.append( 'Or you can use the image object to convert the image and then '
                        'save it to a raw code element that can be included later.' )

        # Test RawCode -- split into separate test?
        rawCodeDecl = image.ToRawCode('TEST_IMAGE')
        assert rawCodeDecl.startswith('TEST_IMAGE = RawCode( """')
        assert rawCodeDecl.endswith('""" )')
        
        rawCode = RawCode(image.Data)
        section.append(rawCode)
        section.append('The above picture was displayed from a RawCode object without a Paragraph wrapper.')

        section.append( 'Here are some png files' )
        for f in [ 'examples/img1.png',
                   'examples/img2.png',
                   'examples/img3.png',
                   'examples/img4.png' ] :
            section.append( Paragraph( Image( f ) ) )

        return doc
開發者ID:brew,項目名稱:pyrtf-ng,代碼行數:34,代碼來源:test_pictures.py

示例5: make_charFrame

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 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,代碼行數:10,代碼來源:test_characters.py

示例6: make_charTab

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 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,代碼行數:10,代碼來源:test_characters.py

示例7: make_sectionWithParas

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 def make_sectionWithParas():
     doc, section, styles = RTFTestCase.initializeDoc()
     section.append('Small paragraph.')
     section.append('')
     # a lot of useful documents can be created with little more than this
     section.append(
         'A lot of useful documents can be created in this way. More '
         'advanced formatting is available, but a lot of users just want '
         'to see their data in something other than a text file.')
     return doc
開發者ID:oubiwann-unsupported,項目名稱:pyrtf,代碼行數:12,代碼來源:test_sections.py

示例8: make_paraNormal

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 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,代碼行數:14,代碼來源:test_paragraphs.py

示例9: make_hyperlinks

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 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,代碼行數:14,代碼來源:test_characters.py

示例10: make_tableHorizontalCellMerge

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    def make_tableHorizontalCellMerge():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append( 'Table with Horizontal Cells Merged' )

        table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two'                   ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two', span=2 ) )
        table.AddRow( Cell( 'A-one', span=3 ) )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two'                   ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one', span=2 ), Cell( 'A-two' ) )
        section.append( table )
        return doc
開發者ID:brew,項目名稱:pyrtf-ng,代碼行數:14,代碼來源:test_tables.py

示例11: test_documentWrite

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    def test_documentWrite(self):
        doc, section, styles = RTFTestCase.initializeDoc()
        
        fd, filename = tempfile.mkstemp(prefix='test-pyrtf', suffix='.rtf')
        os.close(fd)
        doc.write(filename)
        
        result = StringIO.StringIO()
        doc.write(result)

        assert open(filename, 'r').read() == result.getvalue()
        os.remove(filename)
開發者ID:oubiwann-unsupported,項目名稱:pyrtf,代碼行數:14,代碼來源:test_document.py

示例12: test_ExceptionOnUnknownElement

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    def test_ExceptionOnUnknownElement(self):

        # Create document with unknown element type.
        doc, section, styles = RTFTestCase.initializeDoc()
        class CustomClass(object):
            pass
        section.append(CustomClass())
        
        # Try to render.
        r = Renderer()
        result = StringIO()
        self.assertRaises(Exception, r.Write, doc, result)
開發者ID:oubiwann-unsupported,項目名稱:pyrtf,代碼行數:14,代碼來源:test_characters.py

示例13: make_tableFlowRightToLeft

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    def make_tableFlowRightToLeft():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append( 'Table with content flowing right to left' )
        table = Table( TableTestCase.col4, TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
        table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ),
                      Cell( 'This is pretty amazing', flow=Cell.FLOW_RL_TB, start_vertical_merge=True ) )

        for i in range( 10 ) :	
            table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ),
                          Cell( vertical_merge=True ))
        section.append( table )
        return doc
開發者ID:brew,項目名稱:pyrtf-ng,代碼行數:14,代碼來源:test_tables.py

示例14: make_charStyleOverride

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
 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,代碼行數:15,代碼來源:test_characters.py

示例15: make_paraIndents

# 需要導入模塊: from rtfng.utils import RTFTestCase [as 別名]
# 或者: from rtfng.utils.RTFTestCase import initializeDoc [as 別名]
    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,代碼行數:53,代碼來源:test_paragraphs.py


注:本文中的rtfng.utils.RTFTestCase.initializeDoc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。