def test_insert_frame(self):
     body = self.body.clone()
     frame1 = odf_create_frame(u"frame1", size=('10cm', '10cm'),
                               style='Graphics')
     frame2 = odf_create_frame(u"frame2", size=('10cm', '10cm'),
                               page_number=1, position=('10mm', '10mm'),
                               style='Graphics')
     body.append_element(frame1)
     body.append_element(frame2)
     result = body.get_frame_list(style='Graphics')
     self.assertEqual(len(result), 2)
     element = body.get_frame_by_name(u"frame1")
     self.assertEqual(element.get_tagname(), 'draw:frame')
     element = body.get_frame_by_name(u"frame2")
     self.assertEqual(element.get_tagname(), 'draw:frame')
示例#2
0
 def test_insert_frame(self):
     body = self.body.clone()
     frame1 = odf_create_frame("frame1", size=('10cm', '10cm'),
                               style='Graphics')
     frame2 = odf_create_frame("frame2", size=('10cm', '10cm'),
                               page_number=1, position=('10mm', '10mm'),
                               style='Graphics')
     body.append(frame1)
     body.append(frame2)
     result = body.get_frames(style='Graphics')
     self.assertEqual(len(result), 2)
     element = body.get_frame(name="frame1")
     self.assertEqual(element.get_tag(), 'draw:frame')
     element = body.get_frame(name="frame2")
     self.assertEqual(element.get_tag(), 'draw:frame')
 def test_create_frame(self):
     frame = odf_create_frame(u"A Frame", size=('10cm', '10cm'),
                              style='Graphics')
     expected = ('<draw:frame svg:width="10cm" svg:height="10cm" '
                   'text:anchor-type="paragraph" '
                   'draw:name="A Frame" draw:style-name="Graphics"/>')
     self.assertEqual(frame.serialize(), expected)
示例#4
0
 def setUp(self):
     document = odf_get_document('samples/frame_image.odp')
     self.body = document.get_body()
     self.size = size = ('1cm', '2mm')
     self.position = position = ('3in', '4pt')
     self.frame = odf_create_frame(size=size, position=position,
             anchor_type='paragraph')
示例#5
0
 def setUp(self):
     document = odf_get_document('samples/frame_image.odp')
     self.body = document.get_body()
     self.size = size = ('1cm', '2mm')
     self.position = position = ('3in', '4pt')
     self.frame = odf_create_frame(size=size, position=position,
             anchor_type='paragraph')
示例#6
0
 def test_create_frame(self):
     frame = odf_create_frame("A Frame", size=('10cm', '10cm'),
                              style='Graphics')
     expected = ('<draw:frame svg:width="10cm" svg:height="10cm" '
                   'draw:z-index="0" draw:name="A Frame" '
                   'draw:style-name="Graphics"/>')
     self.assertEqual(frame.serialize(), expected)
 def test_create_frame_page(self):
     frame = odf_create_frame(u"Another Frame", size=('10cm', '10cm'),
                              anchor_type='page', page_number=1,
                              position=('10mm', '10mm'), style='Graphics')
     expected = ('<draw:frame svg:width="10cm" svg:height="10cm" '
                   'text:anchor-type="page" text:anchor-page-number="1" '
                   'draw:name="Another Frame" svg:x="10mm" '
                   'svg:y="10mm" draw:style-name="Graphics"/>')
     self.assertEqual(frame.serialize(), expected)
示例#8
0
 def test_create_frame_page(self):
     frame = odf_create_frame("Another Frame", size=('10cm', '10cm'),
                              anchor_type='page', page_number=1,
                              position=('10mm', '10mm'), style='Graphics')
     expected = ('<draw:frame svg:width="10cm" svg:height="10cm" '
                   'draw:z-index="0" draw:name="Another Frame" '
                   'text:anchor-type="page" text:anchor-page-number="1" '
                   'svg:x="10mm" svg:y="10mm" '
                   'draw:style-name="Graphics"/>')
     self.assertEqual(frame.serialize(), expected)
示例#9
0
 def test_insert_image(self):
     body = self.body.clone()
     path = 'a/path'
     image = odf_create_image(path)
     frame = odf_create_frame(u"Image Frame", size=('0cm', '0cm'),
                              style='Graphics')
     frame.append(image)
     body.get_frame().insert(frame, NEXT_SIBLING)
     element = body.get_image(name=u"Image Frame")
     self.assertEqual(element.get_attribute('xlink:href'), path)
     element = body.get_image(position=1)
     self.assertEqual(element.get_attribute('xlink:href'), path)
示例#10
0
 def test_insert_image(self):
     body = self.body.clone()
     path = 'a/path'
     image = odf_create_image(path)
     frame = odf_create_frame(u"Image Frame",
                              size=('0cm', '0cm'),
                              style='Graphics')
     frame.append(image)
     body.get_frame().insert(frame, NEXT_SIBLING)
     element = body.get_image(name=u"Image Frame")
     self.assertEqual(element.get_attribute('xlink:href'), path)
     element = body.get_image(position=1)
     self.assertEqual(element.get_attribute('xlink:href'), path)
示例#11
0
def attach_chart_to_cell(name_obj, cell):
    """
    create a frame in 'cell' in order to display the chart 'name_obj'
    name_obj - str
    cell - odf_cell
    """
    #We need a frame
    frame = odf_create_frame(size=("10cm", "10cm"))

    #We need a draw:object element
    element = odf_create_element("draw:object")
    element.set_attribute("xlink:href", "./"+name_obj)
    element.set_attribute("xlink:type", "simple")
    element.set_attribute("xlink:show", "embed")
    element.set_attribute("xlink:actuate", "onLoad")
                     
    frame.append(element)
    cell.append(frame)

    return cell
示例#12
0
def attach_chart_to_cell(name_obj, cell):
    """
    create a frame in 'cell' in order to display the chart 'name_obj'
    name_obj - str
    cell - odf_cell
    """
    #We need a frame
    frame = odf_create_frame(size=("10cm", "10cm"))

    #We need a draw:object element
    element = odf_create_element("draw:object")
    element.set_attribute("xlink:href", "./" + name_obj)
    element.set_attribute("xlink:type", "simple")
    element.set_attribute("xlink:show", "embed")
    element.set_attribute("xlink:actuate", "onLoad")

    frame.append(element)
    cell.append(frame)

    return cell
示例#13
0
print ' Installation path : %s' % __installation_path__
print
print 'Generating test_output/use_case2.odt ...'

# Go
document = odf_new_document('text')
body = document.get_body()

# 1- The image
# ------------
image = Image.open('samples/image.png')
width, height = image.size
paragraph = odf_create_paragraph(style=u"Standard")
# 72 ppp
frame = odf_create_frame('frame1', 'Graphics',
                         str(width / 72.0) + 'in',
                         str(height / 72.0) + 'in')
internal_name = 'Pictures/image.png'
image = odf_create_image(internal_name)
frame.append(image)
paragraph.append(frame)
body.append(paragraph)

# And store the data
container = document.container
container.set_part(internal_name, open('samples/image.png').read())

# 2- Congratulations (=> style on paragraph)
# ------------------------------------------
heading = odf_create_heading(1, text=u'Congratulations !')
body.append(heading)
示例#14
0
def get_frame(presentation_class, position, size, master_page):
    return odf_create_frame(position=position,
                            size=size,
                            presentation_class=presentation_class,
                            layer="layout")
示例#15
0
print ' Installation path : %s' % __installation_path__
print
print 'Generating test_output/use_case2.odt ...'

# Go
document = odf_new_document('text')
body = document.get_body()

# 0- The image
# ------------
image = Image.open('samples/image.png')
width, height = image.size
paragraph = odf_create_paragraph(style=u"Standard")
# 72 ppp
frame = odf_create_frame('frame1', 'Graphics',
                         str(width / 72.0) + 'in',
                         str(height / 72.0) + 'in')
internal_name = 'Pictures/image.png'
image = odf_create_image(internal_name)
frame.append(image)
paragraph.append(frame)
body.append(paragraph)

# And store the data
container = document.container
container.set_part(internal_name, open('samples/image.png').read())


# 1- Congratulations (=> style on paragraph)
# ------------------------------------------
heading = odf_create_heading(1, text=u'Congratulations !')
示例#16
0
def get_frame(presentation_class, position, size,
        master_page):
    return odf_create_frame(position=position, size=size,
            presentation_class=presentation_class, layer="layout")
示例#17
0
samples = vfs.open('samples')
for numero, filename in enumerate(samples.get_names()):
    # Heading
    heading = odf_create_heading(2, text=unicode(filename, 'utf-8'))
    body.append_element(heading)

    uri = samples.get_uri(filename)
    handler = get_handler(uri)
    if isinstance(handler, Image):
        # Add the image
        internal_name = 'Pictures/' + filename
        width, height = handler.get_size()
        paragraph = odf_create_paragraph('Standard')
        # 72 ppp
        frame = odf_create_frame('frame_%d' % numero, 'Graphics',
                                 str(width / 72.0) + 'in',
                                 str(height / 72.0) + 'in')
        image = odf_create_image(internal_name)
        frame.append_element(image)
        paragraph.append_element(frame)
        body.append_element(paragraph)

        # And store the data
        container = document.container
        container.set_part(internal_name,
                           samples.open(filename).read())
    elif isinstance(handler, CSVFile):
        table = odf_create_table(u"table %d" % numero, style=u"Standard")
        for csv_row in handler.get_rows():
            size = len(csv_row)
            row = odf_create_row()
示例#18
0
    # Heading
    heading = odf_create_heading(1, text=unicode(filename, 'utf-8'))
    body.append(heading)
    path = join('samples', filename)
    mimetype, _ = guess_type(path)
    if mimetype is None:
        mimetype = 'application/octet-stream'
    if mimetype.startswith('image/'):
        # Add the image
        internal_name = 'Pictures/' + filename
        image = Image.open(path)
        width, height = image.size
        paragraph = odf_create_paragraph('Standard')
        # 72 ppp
        frame = odf_create_frame('frame_%d' % numero, 'Graphics',
                                 str(width / 72.0) + 'in',
                                 str(height / 72.0) + 'in')
        image = odf_create_image(internal_name)
        frame.append(image)
        paragraph.append(frame)
        body.append(paragraph)

        # And store the data
        container = document.container
        container.set_part(internal_name, open(path).read())
    elif mimetype in ('text/csv', 'text/comma-separated-values'):
        table = odf_create_table(u"table %d" % numero, style=u"Standard")
        csv = reader(open(path))
        for line in csv:
            size = len(line)
            row = odf_create_row()