Exemple #1
0
    def get_packaging_table_as_tabularx(self):
        table = Tabularx("|X|X|X|", row_height=1.25)
        table.add_hline()
        table.add_row(bold("Type"), bold("Størrelse"), bold("Antall"))
        for child_id in self.packaging_table.get_children():
            child = self.packaging_table.item(child_id)
            if (text := child["text"]):
                table.add_hline()

            table.add_row(text, child["values"][0], child["values"][1])
Exemple #2
0
    def get_general_info_as_tabularx(self):
        table = Tabularx("|X|X|X|X|", row_height=1.25)
        table.add_hline()
        table.add_row(bold("Kundenavn"), self.customer_name.get(),
                      bold("Ordrenummer"), self.order_number.get())

        table.add_hline()
        total_lengde = str(self.get_total_length_l())
        if (total_length_r := self.get_total_length_r()):
            total_lengde += f" x {total_length_r}"
    def _write_tables(self, tables: List[FeSummaryTable], model_ids: Set[FEID],
                      datasets: Dict[FEID, Tuple[Set[str], Any]]) -> None:
        """Insert a LaTeX representation of a list of tables into the current doc.

        Args:
            tables: The tables to write into the doc.
            model_ids: The ids of any known models.
            datasets: A mapping like {ID: ({modes}, dataset)}. Useful for augmenting the displayed information.
        """
        for tbl in tables:
            name_override = None
            toc_ref = None
            extra_rows = None
            if tbl.fe_id in model_ids:
                # Link to a later detailed model description
                name_override = Hyperref(Marker(name=str(tbl.name),
                                                prefix="subsec"),
                                         text=NoEscape(r'\textcolor{blue}{') +
                                         bold(tbl.name) + NoEscape('}'))
            if tbl.fe_id in datasets:
                modes, dataset = datasets[tbl.fe_id]
                title = ", ".join([s.capitalize() for s in modes])
                name_override = bold(f'{tbl.name} ({title})')
                # Enhance the dataset summary
                if isinstance(dataset, FEDataset):
                    extra_rows = list(dataset.summary().__getstate__().items())
                    for idx, (key, val) in enumerate(extra_rows):
                        key = f"{prettify_metric_name(key)}:"
                        if isinstance(val, dict) and val:
                            if isinstance(
                                    list(val.values())[0],
                                (int, float, str, bool, type(None))):
                                val = jsonpickle.dumps(val, unpicklable=False)
                            else:
                                subtable = Tabularx(
                                    'l|X',
                                    width_argument=NoEscape(r'\linewidth'))
                                for k, v in val.items():
                                    if hasattr(v, '__getstate__'):
                                        v = jsonpickle.dumps(v,
                                                             unpicklable=False)
                                    subtable.add_row((k, v))
                                # To nest TabularX, have to wrap it in brackets
                                subtable = ContainerList(data=[
                                    NoEscape("{"), subtable,
                                    NoEscape("}")
                                ])
                                val = subtable
                        extra_rows[idx] = (key, val)
            tbl.render_table(self.doc,
                             name_override=name_override,
                             toc_ref=toc_ref,
                             extra_rows=extra_rows)
Exemple #4
0
    def cria_primeira_secao(self, cabecalho):
        colunas_section_1 = Tabularx('c c c')
        colunas_section_1.add_row([MultiColumn(3, align='c')])

        info_aluno = MiniPage(width=NoEscape(r'0.25\textwidth'),
                              pos='b',
                              align='l')
        graf_media = StandAloneGraphic(filename=self.path_graf_medias,
                                       image_options='width = 180 px')
        box_medias_aluno = MiniPage(width=NoEscape(r'0.23\textwidth'),
                                    pos='b',
                                    align='l')

        info_aluno.append(f'Nome: {self.resumo[1]} {self.resumo[2]}')
        info_aluno.append(NewLine())
        info_aluno.append(f'Número: {self.resumo[5]}')
        info_aluno.append(NewLine())
        info_aluno.append(f'Série: {self.resumo[4]}º ano')
        info_aluno.append(NewLine())
        info_aluno.append(f'Turma: {self.resumo[3]}')
        info_aluno.append(NewLine())
        info_aluno.append(NewLine())
        if self.resumo[9] >= 45:
            info_aluno.append(LargeText(f'Aprovado'))
        else:
            info_aluno.append(LargeText(f'Reprovado'))

        for i in range(3):
            info_aluno.append(NewLine())

        media_final = LargeText(f'Média final: {self.resumo[9]}')
        info_aluno_medias = Tabular('c | c | c', pos='b')
        info_aluno_medias.add_row(cabecalho, mapper=[bold])
        info_aluno_medias.add_hline()
        info_aluno_medias.add_empty_row()
        info_aluno_medias.add_row(
            [self.resumo[6], self.resumo[7], self.resumo[8]])

        box_medias_aluno.append(media_final)
        for i in range(3):
            box_medias_aluno.append(NewLine())

        box_medias_aluno.append(info_aluno_medias)
        for i in range(3):
            box_medias_aluno.append(NewLine())

        colunas_section_1.add_row([info_aluno, graf_media, box_medias_aluno])

        return colunas_section_1
Exemple #5
0
def test_table():
    # Tabular
    t = Tabular(table_spec='|c|c|', data=None, pos=None, width=2)

    t.add_hline(start=None, end=None)

    t.add_row((1, 2), escape=False, strict=True, mapper=[bold])
    t.add_row(1, 2, escape=False, strict=True, mapper=[bold])

    # MultiColumn/MultiRow.
    t.add_row((MultiColumn(size=2, align='|c|', data='MultiColumn'), ),
              strict=True)

    # One multiRow-cell in that table would not be proper LaTeX,
    # so strict is set to False
    t.add_row((MultiRow(size=2, width='*', data='MultiRow'), ), strict=False)

    repr(t)

    # TabularX
    tabularx = Tabularx(table_spec='X X X',
                        width_argument=NoEscape(r"\textwidth"))
    tabularx.add_row(["test1", "test2", "test3"])

    # Long Table
    longtable = LongTable(table_spec='c c c')
    longtable.add_row(["test", "test2", "test3"])
    longtable.end_table_header()

    # Colored Tabu
    coloredtable = Tabu(table_spec='X[c] X[c]')
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Colored Tabu with 'spread'
    coloredtable = Tabu(table_spec='X[c] X[c]', spread="1in")
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Colored Tabu with 'to'
    coloredtable = Tabu(table_spec='X[c] X[c]', to="5in")
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Colored Tabularx
    coloredtable = Tabularx(table_spec='X[c] X[c]')
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Column
    column = ColumnType("R", "X", r"\raggedleft", parameters=2)
    repr(column)
Exemple #6
0
def test_table():
    # Tabular
    t = Tabular(table_spec='|c|c|', data=None, pos=None, width=2)

    t.add_hline(start=None, end=None)

    t.add_row((1, 2), escape=False, strict=True, mapper=[bold])
    t.add_row(1, 2, escape=False, strict=True, mapper=[bold])

    # MultiColumn/MultiRow.
    t.add_row((MultiColumn(size=2, align='|c|', data='MultiColumn'),),
              strict=True)

    # One multiRow-cell in that table would not be proper LaTeX,
    # so strict is set to False
    t.add_row((MultiRow(size=2, width='*', data='MultiRow'),), strict=False)

    repr(t)

    # TabularX
    tabularx = Tabularx(table_spec='X X X',
                        width_argument=NoEscape(r"\textwidth"))
    tabularx.add_row(["test1", "test2", "test3"])

    # Long Table
    longtable = LongTable(table_spec='c c c')
    longtable.add_row(["test", "test2", "test3"])
    longtable.end_table_header()

    # Colored Tabu
    coloredtable = Tabu(table_spec='X[c] X[c]')
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Colored Tabu with 'spread'
    coloredtable = Tabu(table_spec='X[c] X[c]', spread="1in")
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Colored Tabu with 'to'
    coloredtable = Tabu(table_spec='X[c] X[c]', to="5in")
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Colored Tabularx
    coloredtable = Tabularx(table_spec='X[c] X[c]')
    coloredtable.add_row(["test", "test2"], color="gray", mapper=bold)

    # Column
    column = ColumnType("R", "X", r"\raggedleft", parameters=2)
    repr(column)