Beispiel #1
0
 def test_odf_create_table_cell_style_top(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border_top=border)
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border-top="0.06pt solid #000000" fo:border-left="none" '
         'fo:border-right="none" fo:border-bottom="none"/></style:style>'))
Beispiel #2
0
 def test_odf_create_table_cell_style_padding(self):
     style = odf_create_table_cell_style(padding='0.5mm')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="none" fo:padding="0.5mm"/>'
          '</style:style>'))
Beispiel #3
0
 def test_odf_create_table_cell_style(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border=border)
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #000000"/></style:style>'))
Beispiel #4
0
 def test_odf_create_table_cell_style_none_border(self):
     style = odf_create_table_cell_style()
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="none"/>'
          '</style:style>'))
Beispiel #5
0
 def test_odf_create_table_cell_style_default_border(self):
     style = odf_create_table_cell_style(border='default')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #000000"/>'
          '</style:style>'))
Beispiel #6
0
 def test_odf_create_table_cell_style_padding_some(self):
     style = odf_create_table_cell_style(padding_top='0.6mm',
                                         padding_bottom='0.7mm')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:padding-top="0.6mm" fo:padding-left="none" fo:border="none" '
         'fo:padding-right="none" fo:padding-bottom="0.7mm"/>'
         '</style:style>'))
Beispiel #7
0
 def test_odf_create_table_cell_style_color(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(border=border, color='yellow')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #0000FF"/><style:text-properties '
          'fo:color="#FFFF00"/></style:style>'))
Beispiel #8
0
 def test_odf_create_table_cell_style_top(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border_top=border)
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border-top="0.06pt solid #000000" fo:border-left="none" '
          'fo:border-right="none" fo:border-bottom="none"/></style:style>'))
Beispiel #9
0
 def test_odf_create_table_cell_style_bg(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(
                             border=border,
                             background_color='green')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #0000FF" fo:background-color="#008000"/>'
         '</style:style>'))
Beispiel #10
0
 def test_odf_create_table_cell_style_color(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(
                             border=border,
                             color='yellow')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #0000FF"/><style:text-properties '
         'fo:color="#FFFF00"/></style:style>'))
Beispiel #11
0
def setup_document_styles(document):
    """ Setup all styles used in the document, after the setup
    the style can be used by its 'name' as X.set_style(stylename)

    example: cell.set_style(STYLE[TABLE_CELL_BASE])
    """

    doc_title_style = odf_create_style('paragraph', size='18', bold=True)
    STYLES[DOCUMENT_TITLE] = document.insert_style(style=doc_title_style,
                                                   default=True)

    # Setup base cell style
    border = make_table_cell_border_string(
        thick='0.03cm', color='black'
    )
    style = {
        'color': 'black',
        'background_color': (255, 255, 255),
        'border_right': border,
        'border_left': border,
        'border_bottom': border,
        'border_top': border
    }

    base_style = odf_create_table_cell_style(**style)
    STYLES[TABLE_CELL_BASE] = document.insert_style(
        style=base_style, automatic=True
    )

    # Setup colored cell styles (based on score)
    for color_val, color_rgb in COLORS.items():
        style['background_color'] = color_rgb

        _style = odf_create_table_cell_style(**style)
        _stylename = "{}{}".format(TABLE_CELL_AS_VALUE, color_val)
        STYLES[_stylename] = document.insert_style(
            style=_style,
            automatic=True
        )

    col_style = odf_create_style('table-column', width='3cm')
    STYLES[DESCR_COLUMN_WIDTH] = document.insert_style(
        style=col_style, automatic=True
    )
Beispiel #12
0
 def test_odf_create_table_cell_style_bg(self):
     border = make_table_cell_border_string(color='blue')
     style = odf_create_table_cell_style(border=border,
                                         background_color='green')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border="0.06pt solid #0000FF" fo:background-color="#008000"/>'
          '</style:style>'))
Beispiel #13
0
 def test_odf_create_table_cell_style_padding_some(self):
     style = odf_create_table_cell_style(padding_top='0.6mm',
                                         padding_bottom='0.7mm')
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:padding-top="0.6mm" fo:padding-left="none" fo:border="none" '
          'fo:padding-right="none" fo:padding-bottom="0.7mm"/>'
          '</style:style>'))
Beispiel #14
0
 def test_odf_create_table_cell_style_all(self):
     border_left = make_table_cell_border_string(color='blue')
     border_right = make_table_cell_border_string(thick=60)
     style = odf_create_table_cell_style(
                             background_color='yellow',
                             color=(128,64,32),
                             border_left=border_left,
                             border_right=border_right)
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border-top="none" fo:border-left="0.06pt solid #0000FF" '
         'fo:background-color="#FFFF00" '
         'fo:border-right="0.60pt solid #000000" fo:border-bottom="none"/>'
         '<style:text-properties fo:color="#804020"/></style:style>'))
Beispiel #15
0
 def test_odf_create_table_cell_style_all(self):
     border_left = make_table_cell_border_string(color='blue')
     border_right = make_table_cell_border_string(thick=60)
     style = odf_create_table_cell_style(background_color='yellow',
                                         color=(128, 64, 32),
                                         border_left=border_left,
                                         border_right=border_right)
     self.assertEqual(
         style.serialize(),
         ('<style:style '
          'style:family="table-cell"><style:table-cell-properties '
          'fo:border-top="none" fo:border-left="0.06pt solid #0000FF" '
          'fo:background-color="#FFFF00" '
          'fo:border-right="0.60pt solid #000000" fo:border-bottom="none"/>'
          '<style:text-properties fo:color="#804020"/></style:style>'))
                                currency = u"EUR", cell_type="float")
    row.set_cell(column, cell)
    row_number += 1
    table.set_row(row_number, row)
    # let merge some cells
    table.set_span((column -3, row_number, column -1, row_number), merge = True)

    # Let's add some style on first row
    border = make_table_cell_border_string(
                                thick = '0.03cm',
                                color = 'black'
                                )
    cell_style = odf_create_table_cell_style(
                                color = 'black',
                                background_color = (210, 210, 210),
                                border_right = border,
                                border_left = border,
                                border_bottom = border,
                                border_top = border,
                                )
    style_name = commercial.insert_style(style=cell_style, automatic=True)

    row = table.get_row(0)
    #for cell in row.get_cells(): #possible, but .traverse() is better
    for cell in row.traverse():
        cell.set_style(style_name)
        row.set_cell(x=cell.x, cell=cell)
    table.set_row(row.y, row)

    if not os.path.exists('test_output'):
        os.mkdir('test_output')
Beispiel #17
0
 def test_odf_create_table_cell_style_padding(self):
     style = odf_create_table_cell_style(padding='0.5mm')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="none" fo:padding="0.5mm"/>'
         '</style:style>'))
Beispiel #18
0
 def test_odf_create_table_cell_style_none_border(self):
     style = odf_create_table_cell_style()
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="none"/>'
         '</style:style>'))
Beispiel #19
0
 def test_odf_create_table_cell_style_default_border(self):
     style = odf_create_table_cell_style(border='default')
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #000000"/>'
         '</style:style>'))
Beispiel #20
0
 def test_odf_create_table_cell_style(self):
     border = make_table_cell_border_string()
     style = odf_create_table_cell_style(border=border)
     self.assertEqual(style.serialize(), ('<style:style '
         'style:family="table-cell"><style:table-cell-properties '
         'fo:border="0.06pt solid #000000"/></style:style>'))
table = odf_create_table(u'chart')

for y in xrange(0, 256, 8):
    row = odf_create_row()
    for x in xrange(0, 256, 32):
        cell_value = (x, y, (x + y) % 256)
        border_rl = make_table_cell_border_string(thick='0.20cm',
                                                  color='white')
        border_bt = make_table_cell_border_string(
            thick='0.80cm',
            color='white',
        )
        style = odf_create_table_cell_style(
            color='grey',
            background_color=cell_value,
            border_right=border_rl,
            border_left=border_rl,
            border_bottom=border_bt,
            border_top=border_bt,
        )
        name = document.insert_style(style=style, automatic=True)
        cell = odf_create_cell(value=rgb2hex(cell_value), style=name)
        row.append_cell(cell)
    table.append_row(row)

    row_style = odf_create_style('table-row', height='1.80cm')
    name_style_row = document.insert_style(style=row_style, automatic=True)
    for row in table.get_rows():
        row.set_style(name_style_row)
        table.set_row(row.y, row)

    col_style = odf_create_style('table-column', width='3.6cm')
for y in xrange(0, 256, 8):
    row = odf_create_row()
    for x in xrange(0, 256, 32):
        cell_value = (x, y, (x+y) % 256 )
        border_rl = make_table_cell_border_string(
                                thick = '0.20cm',
                                color = 'white'
                                )
        border_bt = make_table_cell_border_string(
                                thick = '0.80cm',
                                color = 'white',
                                )
        style = odf_create_table_cell_style(
                                color = 'grey' ,
                                background_color = cell_value,
                                border_right = border_rl,
                                border_left = border_rl,
                                border_bottom = border_bt,
                                border_top = border_bt,
                                )
        name = document.insert_style(style=style, automatic=True)
        cell = odf_create_cell(value=rgb2hex(cell_value), style=name)
        row.append_cell(cell)
    table.append_row(row)

    row_style = odf_create_style('table-row', height='1.80cm')
    name_style_row = document.insert_style(style=row_style, automatic=True)
    for row in table.get_rows():
        row.set_style(name_style_row)
        table.set_row(row.y, row)

    col_style = odf_create_style('table-column', width='3.6cm')