from rtfng.utils import RTFTestCase
from rtfng.Elements import Document, Image

from rtfng.document.paragraph import Paragraph
from rtfng.document.section import Section

def initializeDoc():
    doc = Document()
    section = Section()
    doc.Sections.append(section)
    return (doc, section, doc.StyleSheet)

class PictureTestCase(RTFTestCase):
    
    def make_pictures():
        doc     = Document()
        ss      = doc.StyleSheet
        section = Section()
        doc.Sections.append( section )

        # 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.' )

        fout = file( 'image_tmp.py', 'w' )
        print >> fout, 'from rtfng.document.base import RawCode'
        print >> fout
        fout.write( image.ToRawCode( 'TEST_IMAGE' ) )
        fout.close()

        import image_tmp
        section.append( Paragraph( image_tmp.TEST_IMAGE ) )
        section.append( 'Have a look in image_tmp.py for the converted RawCode.' )

        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
    
    make_pictures = staticmethod(make_pictures)

    def test_pictures(self):
        self.doTest()




from rtfng.utils import RTFTestCase
from rtfng.Elements import Document, Image

from rtfng.document.paragraph import Paragraph
from rtfng.document.section import Section

def initializeDoc():
    doc = Document()
    section = Section()
    doc.Sections.append(section)
    return (doc, section, doc.StyleSheet)

class PictureTestCase(RTFTestCase):
    
    def make_pictures():
        doc, section, styles = 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.' )

        fout = file( 'image_tmp.py', 'w' )
        print >> fout, 'from rtfng.document.base import RawCode'
        print >> fout
        fout.write( image.ToRawCode( 'TEST_IMAGE' ) )
        fout.close()

        import image_tmp
        section.append( Paragraph( image_tmp.TEST_IMAGE ) )
        section.append( 'Have a look in image_tmp.py for the converted RawCode.' )

        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
    
    make_pictures = staticmethod(make_pictures)

    def test_pictures(self):
        self.doTest()




remove duplicate code in test_pictures