Python docutils.nodes.tgroup() Examples
The following are 30
code examples of docutils.nodes.tgroup().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.nodes
, or try the search function
.
Example #1
Source File: states.py From aws-builders-fair-projects with Apache License 2.0 | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #2
Source File: states.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #3
Source File: states.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #4
Source File: states.py From blackmamba with MIT License | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #5
Source File: states.py From bash-lambda-layer with MIT License | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #6
Source File: states.py From aws-extender with MIT License | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #7
Source File: swaggerv2_doc.py From sphinx-swaggerdoc with MIT License | 6 votes |
def create_table(self, head, body, colspec=None): table = nodes.table() tgroup = nodes.tgroup() table.append(tgroup) # Create a colspec for each column if colspec is None: colspec = [1 for n in range(len(head))] for width in colspec: tgroup.append(nodes.colspec(colwidth=width)) # Create the table headers thead = nodes.thead() thead.append(self.row(head)) tgroup.append(thead) # Create the table body tbody = nodes.tbody() tbody.extend([self.row(r) for r in body]) tgroup.append(tbody) return table
Example #8
Source File: schematable.py From altair with BSD 3-Clause "New" or "Revised" License | 6 votes |
def prepare_table_header(titles, widths): """Build docutil empty table """ ncols = len(titles) assert len(widths) == ncols tgroup = nodes.tgroup(cols=ncols) for width in widths: tgroup += nodes.colspec(colwidth=width) header = nodes.row() for title in titles: header += nodes.entry("", nodes.paragraph(text=title)) tgroup += nodes.thead("", header) tbody = nodes.tbody() tgroup += tbody return nodes.table("", tgroup), tbody
Example #9
Source File: states.py From deepWordBug with Apache License 2.0 | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths == 'auto': table['classes'] += ['colwidths-auto'] elif widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #10
Source File: states.py From faces with GNU General Public License v2.0 | 6 votes |
def build_table(self, tabledata, tableline, stub_columns=0, widths=None): colwidths, headrows, bodyrows = tabledata table = nodes.table() if widths: table['classes'] += ['colwidths-%s' % widths] tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec if headrows: thead = nodes.thead() tgroup += thead for row in headrows: thead += self.build_table_row(row, tableline) tbody = nodes.tbody() tgroup += tbody for row in bodyrows: tbody += self.build_table_row(row, tableline) return table
Example #11
Source File: speciescatalog.py From stdpopsim with GNU General Public License v3.0 | 6 votes |
def models_table(self, species): table = nodes.table() tgroup = nodes.tgroup(cols=2) for _ in range(2): colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) table += tgroup thead = nodes.thead() tgroup += thead row = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text="ID") row += entry entry = nodes.entry() entry += nodes.paragraph(text="Description") row += entry thead.append(row) rows = [] for model in species.demographic_models: row = nodes.row() rows.append(row) mid = self.get_demographic_model_id(species, model) entry = nodes.entry() para = nodes.paragraph() entry += para para += nodes.reference(internal=True, refid=mid, text=model.id) row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.description) row += entry tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
Example #12
Source File: test_rst_directives.py From seqdiag with Apache License 2.0 | 5 votes |
def test_desctable_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. seqdiag::\n" " :desctable:\n" "\n" " A [description = foo]" " B [description = bar]") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(nodes.table, type(doctree[1])) # tgroup self.assertEqual(4, len(doctree[1][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][1])) self.assertEqual(nodes.thead, type(doctree[1][0][2])) self.assertEqual(nodes.tbody, type(doctree[1][0][3])) # colspec self.assertEqual(50, doctree[1][0][0]['colwidth']) self.assertEqual(50, doctree[1][0][1]['colwidth']) # thead thead = doctree[1][0][2] self.assertEqual(2, len(thead[0])) self.assertEqual('Name', thead[0][0][0][0]) self.assertEqual('Description', thead[0][1][0][0]) # tbody tbody = doctree[1][0][3] self.assertEqual(2, len(tbody)) self.assertEqual('A', tbody[0][0][0][0]) self.assertEqual('foo', tbody[0][1][0][0]) self.assertEqual('B', tbody[1][0][0][0]) self.assertEqual('bar', tbody[1][1][0][0])
Example #13
Source File: tables.py From deepWordBug with Apache License 2.0 | 5 votes |
def run(self): if not self.content: warning = self.state_machine.reporter.warning( 'Content block expected for the "%s" directive; none found.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [warning] title, messages = self.make_title() node = nodes.Element() # anonymous container for parsing self.state.nested_parse(self.content, self.content_offset, node) if len(node) != 1 or not isinstance(node[0], nodes.table): error = self.state_machine.reporter.error( 'Error parsing content block for the "%s" directive: exactly ' 'one table expected.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [error] table_node = node[0] table_node['classes'] += self.options.get('class', []) if 'align' in self.options: table_node['align'] = self.options.get('align') tgroup = table_node[0] if type(self.widths) == list: colspecs = [child for child in tgroup.children if child.tagname == 'colspec'] for colspec, col_width in zip(colspecs, self.widths): colspec['colwidth'] = col_width # @@@ the colwidths argument for <tgroup> is not part of the # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm) # and hence violates the docutils.dtd. if self.widths == 'auto': table_node['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table_node['classes'] += ['colwidths-given'] self.add_name(table_node) if title: table_node.insert(0, title) return [table_node] + messages
Example #14
Source File: tables.py From blackmamba with MIT License | 5 votes |
def run(self): if not self.content: warning = self.state_machine.reporter.warning( 'Content block expected for the "%s" directive; none found.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [warning] title, messages = self.make_title() node = nodes.Element() # anonymous container for parsing self.state.nested_parse(self.content, self.content_offset, node) if len(node) != 1 or not isinstance(node[0], nodes.table): error = self.state_machine.reporter.error( 'Error parsing content block for the "%s" directive: exactly ' 'one table expected.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [error] table_node = node[0] table_node['classes'] += self.options.get('class', []) if 'align' in self.options: table_node['align'] = self.options.get('align') tgroup = table_node[0] if type(self.widths) == list: colspecs = [child for child in tgroup.children if child.tagname == 'colspec'] for colspec, col_width in zip(colspecs, self.widths): colspec['colwidth'] = col_width # @@@ the colwidths argument for <tgroup> is not part of the # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm) # and hence violates the docutils.dtd. if self.widths == 'auto': table_node['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table_node['classes'] += ['colwidths-given'] self.add_name(table_node) if title: table_node.insert(0, title) return [table_node] + messages
Example #15
Source File: tables.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() if self.widths == 'auto': table['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec() if col_width is not None: colspec.attributes['colwidth'] = col_width if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell in row: entry = nodes.entry() entry += cell row_node += entry rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
Example #16
Source File: tables.py From blackmamba with MIT License | 5 votes |
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() if self.widths == 'auto': table['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec() if col_width is not None: colspec.attributes['colwidth'] = col_width if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell in row: entry = nodes.entry() entry += cell row_node += entry rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
Example #17
Source File: tables.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() if self.widths == 'auto': table['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec() if col_width is not None: colspec.attributes['colwidth'] = col_width if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell in row: entry = nodes.entry() entry += cell row_node += entry rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
Example #18
Source File: tables.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def run(self): if not self.content: warning = self.state_machine.reporter.warning( 'Content block expected for the "%s" directive; none found.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [warning] title, messages = self.make_title() node = nodes.Element() # anonymous container for parsing self.state.nested_parse(self.content, self.content_offset, node) if len(node) != 1 or not isinstance(node[0], nodes.table): error = self.state_machine.reporter.error( 'Error parsing content block for the "%s" directive: exactly ' 'one table expected.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [error] table_node = node[0] table_node['classes'] += self.options.get('class', []) self.set_table_width(table_node) if 'align' in self.options: table_node['align'] = self.options.get('align') tgroup = table_node[0] if type(self.widths) == list: colspecs = [child for child in tgroup.children if child.tagname == 'colspec'] for colspec, col_width in zip(colspecs, self.widths): colspec['colwidth'] = col_width # @@@ the colwidths argument for <tgroup> is not part of the # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm) # and hence violates the docutils.dtd. if self.widths == 'auto': table_node['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table_node['classes'] += ['colwidths-given'] self.add_name(table_node) if title: table_node.insert(0, title) return [table_node] + messages
Example #19
Source File: tables.py From aws-extender with MIT License | 5 votes |
def run(self): if not self.content: warning = self.state_machine.reporter.warning( 'Content block expected for the "%s" directive; none found.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [warning] title, messages = self.make_title() node = nodes.Element() # anonymous container for parsing self.state.nested_parse(self.content, self.content_offset, node) if len(node) != 1 or not isinstance(node[0], nodes.table): error = self.state_machine.reporter.error( 'Error parsing content block for the "%s" directive: exactly ' 'one table expected.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [error] table_node = node[0] table_node['classes'] += self.options.get('class', []) if 'align' in self.options: table_node['align'] = self.options.get('align') tgroup = table_node[0] if type(self.widths) == list: colspecs = [child for child in tgroup.children if child.tagname == 'colspec'] for colspec, col_width in zip(colspecs, self.widths): colspec['colwidth'] = col_width # @@@ the colwidths argument for <tgroup> is not part of the # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm) # and hence violates the docutils.dtd. if self.widths == 'auto': table_node['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table_node['classes'] += ['colwidths-given'] self.add_name(table_node) if title: table_node.insert(0, title) return [table_node] + messages
Example #20
Source File: tables.py From aws-extender with MIT License | 5 votes |
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() if self.widths == 'auto': table['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec() if col_width is not None: colspec.attributes['colwidth'] = col_width if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell in row: entry = nodes.entry() entry += cell row_node += entry rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
Example #21
Source File: test_rst_directives.py From seqdiag with Apache License 2.0 | 5 votes |
def test_desctable_option_with_numbered(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. seqdiag::\n" " :desctable:\n" "\n" " A [numbered = 2]" " B [numbered = 1]") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(nodes.table, type(doctree[1])) # tgroup self.assertEqual(4, len(doctree[1][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][1])) self.assertEqual(nodes.thead, type(doctree[1][0][2])) self.assertEqual(nodes.tbody, type(doctree[1][0][3])) # colspec self.assertEqual(25, doctree[1][0][0]['colwidth']) self.assertEqual(50, doctree[1][0][1]['colwidth']) # thead thead = doctree[1][0][2] self.assertEqual(2, len(thead[0])) self.assertEqual('No', thead[0][0][0][0]) self.assertEqual('Name', thead[0][1][0][0]) # tbody tbody = doctree[1][0][3] self.assertEqual(2, len(tbody)) self.assertEqual('1', tbody[0][0][0][0]) self.assertEqual('B', tbody[0][1][0][0]) self.assertEqual('2', tbody[1][0][0][0]) self.assertEqual('A', tbody[1][1][0][0])
Example #22
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_desctable_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. nwdiag::\n" " :desctable:\n" "\n" " network {" " A [description = foo]" " B [description = bar]" " }") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(nodes.table, type(doctree[1])) # tgroup self.assertEqual(4, len(doctree[1][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][1])) self.assertEqual(nodes.thead, type(doctree[1][0][2])) self.assertEqual(nodes.tbody, type(doctree[1][0][3])) # colspec self.assertEqual(50, doctree[1][0][0]['colwidth']) self.assertEqual(50, doctree[1][0][1]['colwidth']) # thead thead = doctree[1][0][2] self.assertEqual(2, len(thead[0])) self.assertEqual('Name', thead[0][0][0][0]) self.assertEqual('Description', thead[0][1][0][0]) # tbody tbody = doctree[1][0][3] self.assertEqual(2, len(tbody)) self.assertEqual('A', tbody[0][0][0][0]) self.assertEqual('foo', tbody[0][1][0][0]) self.assertEqual('B', tbody[1][0][0][0]) self.assertEqual('bar', tbody[1][1][0][0])
Example #23
Source File: test_rst_directives.py From nwdiag with Apache License 2.0 | 5 votes |
def test_desctable_option_with_numbered(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. nwdiag::\n" " :desctable:\n" "\n" " network {" " A [numbered = 2]" " B [numbered = 1]" " }") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(nodes.table, type(doctree[1])) # tgroup self.assertEqual(4, len(doctree[1][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][1])) self.assertEqual(nodes.thead, type(doctree[1][0][2])) self.assertEqual(nodes.tbody, type(doctree[1][0][3])) # colspec self.assertEqual(25, doctree[1][0][0]['colwidth']) self.assertEqual(50, doctree[1][0][1]['colwidth']) # thead thead = doctree[1][0][2] self.assertEqual(2, len(thead[0])) self.assertEqual('No', thead[0][0][0][0]) self.assertEqual('Name', thead[0][1][0][0]) # tbody tbody = doctree[1][0][3] self.assertEqual(2, len(tbody)) self.assertEqual('1', tbody[0][0][0][0]) self.assertEqual('B', tbody[0][1][0][0]) self.assertEqual('2', tbody[1][0][0][0]) self.assertEqual('A', tbody[1][1][0][0])
Example #24
Source File: resources.py From senlin with Apache License 2.0 | 5 votes |
def _build_table(self, section, title, headers, description=None): """Creates a table with given title, headers and description :returns: Table body node """ table_section = self._create_section(section, title, title=title) if description: field = nodes.line('', description) table_section.append(field) table = nodes.table() tgroup = nodes.tgroup(len(headers)) table += tgroup table_section.append(table) for _ in headers: tgroup.append(nodes.colspec(colwidth=1)) # create header thead = nodes.thead() tgroup += thead self._create_table_row(headers, thead) tbody = nodes.tbody() tgroup += tbody # create body consisting of targets tbody = nodes.tbody() tgroup += tbody return tbody
Example #25
Source File: test_blockdiag_directives.py From blockdiag with Apache License 2.0 | 5 votes |
def test_desctable_option_with_numbered(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. blockdiag::\n" " :desctable:\n" "\n" " A [numbered = 2]" " B [numbered = 1]") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(nodes.table, type(doctree[1])) # tgroup self.assertEqual(4, len(doctree[1][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][1])) self.assertEqual(nodes.thead, type(doctree[1][0][2])) self.assertEqual(nodes.tbody, type(doctree[1][0][3])) # colspec self.assertEqual(25, doctree[1][0][0]['colwidth']) self.assertEqual(50, doctree[1][0][1]['colwidth']) # thead thead = doctree[1][0][2] self.assertEqual(2, len(thead[0])) self.assertEqual('No', thead[0][0][0][0]) self.assertEqual('Name', thead[0][1][0][0]) # tbody tbody = doctree[1][0][3] self.assertEqual(2, len(tbody)) self.assertEqual('1', tbody[0][0][0][0]) self.assertEqual('B', tbody[0][1][0][0]) self.assertEqual('2', tbody[1][0][0][0]) self.assertEqual('A', tbody[1][1][0][0])
Example #26
Source File: progress.py From PGPy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def create_progtable(self, **attrs): _attrs = { 'classes': ['progress', 'outer', 'docutils', 'field-list'], 'colwidths': [20, 80] } _attrs.update(attrs) # create container elements node = nodes.table(classes=_attrs['classes']) tgroup = nodes.tgroup(cols=2) thead = thead = nodes.thead() thead += self.create_headrow() tbody = nodes.tbody() # tgroup gets: # - colspec # - thead # - tbody for w in _attrs['colwidths']: tgroup += nodes.colspec(colwidth=w) # assemble the hierarchy tgroup += thead tgroup += tbody node += tgroup # return the table return node
Example #27
Source File: versionutils.py From qiskit with Apache License 2.0 | 5 votes |
def build_table(self, versions): table = nodes.table() table['classes'] += ['colwidths-auto'] tgroup = nodes.tgroup(cols=len(self.headers)) table += tgroup self.options['widths'] = [30, 15, 15, 15, 20, 15] tgroup.extend( nodes.colspec(colwidth=col_width, colname='c' + str(idx)) for idx, col_width in enumerate(self.col_widths) ) thead = nodes.thead() tgroup += thead row_node = nodes.row() thead += row_node row_node.extend(nodes.entry(h, nodes.paragraph(text=h)) for h in self.headers) tbody = nodes.tbody() tgroup += tbody rows = [] for version in versions: row_node = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text=version) row_node += entry for cell in self.headers[1:]: if cell in versions[version]: entry = nodes.entry() text = versions[version][cell] entry += nodes.paragraph(text=text) else: entry = nodes.entry() row_node += entry rows.append(row_node) tbody.extend(rows) return table
Example #28
Source File: sphinxutil.py From cc-utils with Apache License 2.0 | 5 votes |
def _setup_column_groups(self, column_count: int): self.column_count = column_count self.group = nodes.tgroup('', cols=column_count) for _ in range(column_count): self.group.append(nodes.colspec(''))
Example #29
Source File: directives.py From blockdiag with Apache License 2.0 | 5 votes |
def _description_table(self, descriptions, widths, headers): # generate table-root tgroup = nodes.tgroup(cols=len(widths)) for width in widths: tgroup += nodes.colspec(colwidth=width) table = nodes.table() table += tgroup # generate table-header thead = nodes.thead() row = nodes.row() for header in headers: entry = nodes.entry() entry += nodes.paragraph(text=header) row += entry thead += row tgroup += thead # generate table-body tbody = nodes.tbody() for desc in descriptions: row = nodes.row() for attr in desc: entry = nodes.entry() if not isinstance(attr, str): attr = str(attr) self.state.nested_parse(ViewList([attr], source=attr), 0, entry) row += entry tbody += row tgroup += tbody return table
Example #30
Source File: test_blockdiag_directives.py From blockdiag with Apache License 2.0 | 5 votes |
def test_desctable_option(self): directives.setup(format='SVG', outputdir=self.tmpdir) text = (".. blockdiag::\n" " :desctable:\n" "\n" " A [description = foo]" " B [description = bar]" " group { A }") doctree = publish_doctree(text) self.assertEqual(2, len(doctree)) self.assertEqual(nodes.image, type(doctree[0])) self.assertEqual(nodes.table, type(doctree[1])) # tgroup self.assertEqual(4, len(doctree[1][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][0])) self.assertEqual(nodes.colspec, type(doctree[1][0][1])) self.assertEqual(nodes.thead, type(doctree[1][0][2])) self.assertEqual(nodes.tbody, type(doctree[1][0][3])) # colspec self.assertEqual(50, doctree[1][0][0]['colwidth']) self.assertEqual(50, doctree[1][0][1]['colwidth']) # thead thead = doctree[1][0][2] self.assertEqual(2, len(thead[0])) self.assertEqual('Name', thead[0][0][0][0]) self.assertEqual('Description', thead[0][1][0][0]) # tbody tbody = doctree[1][0][3] self.assertEqual(2, len(tbody)) self.assertEqual('A', tbody[0][0][0][0]) self.assertEqual('foo', tbody[0][1][0][0]) self.assertEqual('B', tbody[1][0][0][0]) self.assertEqual('bar', tbody[1][1][0][0])