def create_cross_table(self, app, docname, node, matrix, options): table = nodes.table() table["classes"].append("traceables-crosstable") tgroup = nodes.tgroup(cols=len(matrix.secondaries), colwidths="auto") table += tgroup # Add column specifications. tgroup += nodes.colspec(colwidth=1) for column in matrix.secondaries: tgroup += nodes.colspec(colwidth=1) # Add heading row. thead = nodes.thead() tgroup += thead row = nodes.row() thead += row entry = nodes.entry() row += entry for secondary in matrix.secondaries: entry = nodes.entry() row += entry container = nodes.container() entry += container inline = nodes.inline() container += inline paragraph = nodes.paragraph() inline += paragraph paragraph += secondary.make_reference_node(app.builder, docname) # Add table body. tbody = nodes.tbody() tgroup += tbody for primary in matrix.primaries: row = nodes.row() tbody += row entry = nodes.entry() row += entry paragraph = nodes.paragraph() entry += paragraph paragraph += primary.make_reference_node(app.builder, docname) for is_related in matrix.get_boolean_row(primary): entry = nodes.entry() row += entry if is_related: checkmark = traceable_checkmark() entry += checkmark checkmark += nodes.inline(u"\u2714", u"\u2714") else: continue container = traceable_matrix_crosstable() container += table container["traceables-matrix"] = matrix # backward = matrix.backward_relationship.capitalize() # forward = matrix.forward_relationship.capitalize() # container["relationships"] = (forward, backward) # container["boolean_matrix"] = 0#boolean_matrix # container["secondaries"] = matrix.secondaries return container
def run(self): if ValueTableDirective.values[0].description is None: list = nodes.bullet_list() for v in ValueTableDirective.values: item = nodes.list_item() item += nodes.literal(v.value, v.value) list += item return [list] table = nodes.table() tgroup = nodes.tgroup() tbody = nodes.tbody() for v in ValueTableDirective.values: row = nodes.row() entry = nodes.entry() entry += nodes.literal(v.value, v.value) row += entry entry = nodes.entry() entry += nodes.paragraph(text=v.description) row += entry tbody += row tgroup += nodes.colspec(colwidth=10) tgroup += nodes.colspec(colwidth=90) tgroup += tbody table += tgroup return [table]
def get_tablespec(self): table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) return table, table_spec, append_row
def build_toc(descinfo, env): """Return a desc table of contents node tree""" separator = EMDASH child_ids = descinfo['children'] if not child_ids: return None max_fullname_len = 0 max_summary_len = 0 rows = [] for fullname, refid, summary in ichild_ids(child_ids, env): max_fullname_len = max(max_fullname_len, len(fullname)) max_summary_len = max(max_summary_len, len(summary)) reference_node = toc_ref(fullname, refid) ref_entry_node = entry('', paragraph('', '', reference_node)) sep_entry_node = entry('', paragraph('', separator)) sum_entry_node = entry('', paragraph('', summary)) row_node = row('', ref_entry_node, sep_entry_node, sum_entry_node) rows.append(row_node) col0_len = max_fullname_len + 2 # add error margin col1_len = len(separator) # no padding col2_len = max_summary_len + 10 # add error margin tbody_node = tbody('', *rows) col0_colspec_node = colspec(colwidth=col0_len) col1_colspec_node = colspec(colwidth=col1_len) col2_colspec_node = colspec(colwidth=col2_len) tgroup_node = tgroup('', col0_colspec_node, col1_colspec_node, col2_colspec_node, tbody_node, cols=3) return TocTable('', tgroup_node, classes=['toc'])
def create_list_table(self, matrix, options, docname): table = nodes.table() tgroup = nodes.tgroup(cols=2, colwidths="auto") table += tgroup # Add column specifications. tgroup += nodes.colspec(colwidth=50) tgroup += nodes.colspec(colwidth=50) # Add heading row. thead = nodes.thead() tgroup += thead row = nodes.row() thead += row entry = nodes.entry() row += entry backward_relationship = matrix.backward_relationship.capitalize() entry += nodes.paragraph(backward_relationship, backward_relationship) entry = nodes.entry() row += entry forward_relationship = matrix.forward_relationship.capitalize() entry += nodes.paragraph(forward_relationship, forward_relationship) # Add table body. tbody = nodes.tbody() tgroup += tbody for traceable in matrix.primaries: relatives = matrix.get_relatives(traceable) # Create first row with a first column. row = nodes.row() entry = nodes.entry(morerows=len(relatives) - 1) row += entry paragraph = nodes.paragraph() entry += paragraph paragraph += traceable.make_reference_node( self.app.builder, docname) for relative in relatives: if not row: # Create subsequent rows without a first column. row = nodes.row() tbody += row entry = nodes.entry() row += entry paragraph = nodes.paragraph() entry += paragraph paragraph += relative.make_reference_node( self.app.builder, docname) row = None return table
def build_links_table(self, resource): is_list = "is-list" in self.options table = nodes.table() tgroup = nodes.tgroup(cols=3) table += tgroup tgroup += nodes.colspec(colwidth=25) tgroup += nodes.colspec(colwidth=15) tgroup += nodes.colspec(colwidth=60) thead = nodes.thead() tgroup += thead append_row(thead, ["Name", "Method", "Resource"]) tbody = nodes.tbody() tgroup += tbody request = DummyRequest() if is_list: child_resources = resource.list_child_resources else: child_resources = resource.item_child_resources names_to_resource = {} for child in child_resources: names_to_resource[child.name_plural] = (child, True) if not is_list and resource.model: child_keys = {} create_fake_resource_path(request, resource, child_keys, True) obj = resource.get_queryset(request, **child_keys)[0] else: obj = None related_links = resource.get_related_links(request=request, obj=obj) for key, info in related_links.iteritems(): if "resource" in info: names_to_resource[key] = (info["resource"], info.get("list-resource", False)) links = resource.get_links(child_resources, request=DummyRequest(), obj=obj) for linkname in sorted(links.iterkeys()): info = links[linkname] child, is_child_link = names_to_resource.get(linkname, (resource, is_list)) paragraph = nodes.paragraph() paragraph += get_ref_to_resource(child, is_child_link) append_row(tbody, [nodes.strong(text=linkname), info["method"], paragraph]) return table
def get_table(self, items_set): """Generate a proper list of table nodes for errorsummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=3) real_table.append(group) group.append(nodes.colspec('', colwidth=70)) group.append(nodes.colspec('', colwidth=20)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) col1 = u"**Name**" col2 = u"**Code**" col3 = u"**Message**" append_row(col1, col2, col3) for class_name, items in sorted(items_set.items()): for name, sig, summary, real_name, code in items: if 'nosignatures' not in self.options: col1 = '_%s' % name col2 = '{}'.format(code) translated = translate(summary, "ru") if summary else "" if translated != summary: col3 = u"{} / {}".format(translated, summary) else: col3 = summary append_row(col1, col2, col3) return [table_spec, table]
def get_autosummary(names, state, no_signatures=False): """ Generate a proper table node for autosummary:: directive. *names* is a list of names of Python objects to be imported and added to the table. *document* is the Docutils document object. """ document = state.document real_names = {} warnings = [] prefixes = [''] prefixes.insert(0, document.settings.env.currmodule) table = nodes.table('') group = nodes.tgroup('', cols=2) table.append(group) group.append(nodes.colspec('', colwidth=30)) group.append(nodes.colspec('', colwidth=70)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') state.nested_parse(vl, 0, node) row.append(nodes.entry('', node)) body.append(row) for name in names: try: obj, real_name = import_by_name(name, prefixes=prefixes) except ImportError: warnings.append(document.reporter.warning( 'failed to import %s' % name)) append_row(':obj:`%s`' % name, '') continue real_names[name] = real_name title = '' qualifier = 'obj' col1 = ':'+qualifier+':`%s <%s>`' % (name, real_name) col2 = title append_row(col1, col2) return table, warnings, real_names
def build_details_table(self, error_obj): table = nodes.table() tgroup = nodes.tgroup(cols=2) table += tgroup tgroup += nodes.colspec(colwidth=20) tgroup += nodes.colspec(colwidth=80) tbody = nodes.tbody() tgroup += tbody # API Error Code append_detail_row(tbody, 'API Error Code', nodes.literal(text=error_obj.code)) # HTTP Status Code ref = parse_text(self, ':http:`%s`' % error_obj.http_status) append_detail_row(tbody, 'HTTP Status Code', ref) # Error Text append_detail_row(tbody, 'Error Text', nodes.literal(text=error_obj.msg)) if error_obj.headers: if callable(error_obj.headers): headers = error_obj.headers(DummyRequest()) # HTTP Headers if len(headers) == 1: content = nodes.literal(text=headers.keys()[0]) else: content = nodes.bullet_list() for header in headers.iterkeys(): item = nodes.list_item() content += item literal = nodes.literal(text=header) item += literal append_detail_row(tbody, 'HTTP Headers', content) # Description append_detail_row( tbody, 'Description', parse_text(self, '\n'.join(self.content), where='API error %s description' % error_obj.code)) return table
def process_indigo_option_nodes(app, doctree, fromdocname): env = app.builder.env for node in doctree.traverse(optionslist): content = [] tbl = nodes.table() tgroup = nodes.tgroup(cols=4) tbl += tgroup tgroup += nodes.colspec(colwidth=35) tgroup += nodes.colspec(colwidth=9) tgroup += nodes.colspec(colwidth=9) tgroup += nodes.colspec(colwidth=73) thead = nodes.thead() tgroup += thead row = nodes.row() thead += row row += createRowEntryText('Name') row += createRowEntryText('Type') row += createRowEntryText('Default') row += createRowEntryText('Short description') tbody = nodes.tbody() tgroup += tbody content.append(tbl) sorted_options = sorted(env.indigo_options, key=lambda o:o['name']) for opt_info in sorted_options: row = nodes.row() tbody += row # Create a reference newnode = nodes.reference('', '') innernode = nodes.Text(opt_info['name'], opt_info['name']) newnode['refdocname'] = opt_info['docname'] newnode['refuri'] = app.builder.get_relative_uri( fromdocname, opt_info['docname']) newnode['refuri'] += '#' + normalize_name(opt_info['name']) newnode.append(innernode) row += createRowEntry(newnode) row += createRowEntryText(opt_info['type']) row += createRowEntryText(opt_info['default']) row += createRowEntryText(opt_info['short']) node.replace_self(content)
def get_table(self): """docstring for get_table""" table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) return table_spec, table, body
def get_table(self, items): """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'LL' table = autosummary_table('') real_table = nodes.table('') if "title" in self.options: title_node = self.make_title(self.options["title"]) real_table.insert(0, title_node) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<doxybridge-autosummary>') self.sphinx_directive.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name in items: qualifier = self.get_qualifier(name) if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary append_row(col1, col2) return [table_spec, table]
def gen_table(columns, data): table = nodes.table() tgroup = nodes.tgroup(cols=len(columns)) table += tgroup for column in columns: tgroup += nodes.colspec(colwidth=1) thead = nodes.thead() tgroup += thead headrow = nodes.row() for column in columns: entry = nodes.entry() para = nodes.paragraph() entry += para header = column.header() para += nodes.Text(header, header) headrow += entry thead += headrow tbody = nodes.tbody() tgroup += tbody for obj in data: row = nodes.row() for column in columns: entry = nodes.entry() para = nodes.paragraph() entry += para para += column.data(obj) row += entry tbody += row return [table]
def build_table(self, table_data): table = nodes.table() tgroup = nodes.tgroup(cols=len(self.headers)) table += tgroup 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, groups = self.get_rows(table_data) tbody.extend(rows) table.extend(groups) return table
def initialize_table(self): """ Initializes a table node. Returns: (nodes.table) A table node initialized with column widths and a table header. """ table = nodes.table() table['classes'].append('longtable') if self['widths'] == 'auto': table['classes'].append('colwidths-auto') elif self['widths']: # "grid" or list of integers table['classes'].append('colwidths-given') tgroup = nodes.tgroup() for _ in self['col']: tgroup += [nodes.colspec(colwidth=5)] tgroup += nodes.thead('', self.create_row(self['col'])) if isinstance(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 self.tbody = nodes.tbody() tgroup += self.tbody table += tgroup return table
def make_armour_table(env, node): """ Utility method to create a table for armours """ table = nodes.table() tgroup = nodes.tgroup(cols=3) table += tgroup for i in range(4): colspec = nodes.colspec(colwidth=1) tgroup += colspec rows = [] thead = nodes.thead() row_node = make_row('armour', 'damage reduction', 'speed modifier') thead += row_node tgroup += thead for item_entry in (x for x in env.pyherc_context.items if node.options['type'] in x['item'].tags): item = item_entry['item'] row_node = make_row(item.name, item.armour_data.damage_reduction, item.armour_data.speed_modifier) rows.append(row_node) tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
def get_attr_table(self): atable = nodes.table() atgroup = build_node(nodes.tgroup('', cols=5), nodes.colspec(colwidth=10), nodes.colspec(colwidth=50), nodes.colspec(colwidth=20), nodes.colspec(colwidth=10), nodes.colspec(colwidth=10), nodes.thead('', build_table_row("Name", "Description", "Values", "Required", "Default"))) atable.append(atgroup) atable_body = nodes.tbody() atgroup.append(atable_body) return (atable, atable_body)
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec(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
def description_table(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 col in desc: entry = nodes.entry() if not isinstance(col, basestring): col = str(col) paragraph = nodes.paragraph() paragraph += nodes.Text(col) entry += paragraph row += entry tbody += row tgroup += tbody return table
def build_table(self): table = nodes.table() tgroup = nodes.tgroup(cols=len(self.headers)) table += tgroup # TODO(sdague): it would be really nice to figure out how not # to have this stanza, it kind of messes up all of the table # formatting because it doesn't let tables just be the right # size. 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, groups = self.collect_rows() tbody.extend(rows) table.extend(groups) return table
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
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, string_types): attr = str(attr) self.state.nested_parse(ViewList([attr], source=attr), 0, entry) row += entry tbody += row tgroup += tbody return table
def build_table(row_nodes, colwidth_list, headrow_data=None): """ Creates new rst table node tree. Args: row_nodes (list): list of docutils.nodes.row nodes, contains actual content of the rst table colwidth_list (list): list of width percentages for each column, eg.: use [10, 90] for 2 columns, 1st has 10% width, 2nd the rest Returns: docutils.nodes.table: rst table node tree which contains given rows """ table = nodes.table() tgroup = nodes.tgroup(cols=len(colwidth_list)) table += tgroup for colwidth in colwidth_list: colspec = nodes.colspec(colwidth=colwidth) tgroup += colspec if headrow_data is not None: thead = nodes.thead() tgroup += thead head_row_node = build_row(headrow_data) thead += head_row_node tbody = nodes.tbody() tgroup += tbody for row in row_nodes: tbody += row return table
def build_table_from_list(self, table_data, num_cols, col_widths, header_rows, stub_columns): table = nodes.table() tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec(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_index, cell in enumerate(row): entry = nodes.entry() entry += cell row_node += entry if self.bias == "left" and not cell_index: remainder = num_cols - len(row) if remainder: entry["morecols"] = remainder if self.bias == "right" and cell_index == len(row) - 1: remainder = num_cols - (cell_index + 1) if remainder: entry["morecols"] = remainder 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
def run(self): ncolumns = self.options.get('columns', 2) node = nodes.Element() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list): return [self.state.document.reporter.warning( '.. hlist content is not a list', line=self.lineno)] fulllist = node.children[0] # create a hlist node where the items are distributed npercol, nmore = divmod(len(fulllist), ncolumns) index = 0 table = nodes.table() tg = nodes.tgroup() table += tg row = nodes.row() tbody = nodes.tbody() for column in range(ncolumns): endindex = index + (column < nmore and (npercol + 1) or npercol) colspec = nodes.colspec() colspec.attributes['stub'] = 0 colspec.attributes['colwidth'] = 100. / ncolumns col = nodes.entry() col += nodes.bullet_list() col[0] += fulllist.children[index:endindex] index = endindex tg += colspec row += col tbody += row tg += tbody table['classes'].append('hlist') return [table]
def _get_table_spec(self): ncols = self.f2x_ncols() column_titles = self.f2x_get_title() table_spec = addnodes.tabular_col_spec() table_spec['spec'] = r'\X{1}{2}' * ncols table_wrap = autosummary_table('') table_layout = nodes.table('', classes=['longtable']) table_group = nodes.tgroup('', cols=ncols) table_body = nodes.tbody('') table_wrap.append(table_layout) table_layout.append(table_group) for width in self.f2x_get_width(): table_group.append(nodes.colspec('', colwidth=width)) if self.options.get('showheader', False) and column_titles is not None: table_head = nodes.thead('') table_group.append(table_head) self._append_row(table_head, column_titles) table_group.append(table_body) return table_spec, table_wrap, table_body
def run(self): header = self.options.get('header').split(',') lines = self._get_lines() regex = self.options.get('regex') max_cols = len(header) table = nodes.table() tgroup = nodes.tgroup(max_cols) table += tgroup col_widths = self.get_column_widths(max_cols) tgroup.extend(nodes.colspec(colwidth=col_width) for col_width in col_widths) thead = nodes.thead() tgroup += thead thead += self.create_table_row(header) tbody = nodes.tbody() tgroup += tbody for row in lines: matched = re.search(regex, row) if matched: tbody += self.create_table_row(matched.groups()) return [table]
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
def create_table(self, data, num_headers=1): table_node = nodes.table() if len(data) > 0: tgroup_node = nodes.tgroup(cols=len(data[0])) table_node += tgroup_node col_width = 100 // len(data[0]) for col_index in range(len(data[0])): colspec_node = nodes.colspec(colwidth=col_width) tgroup_node += colspec_node thead = nodes.thead() tgroup_node += thead tbody = nodes.tbody() tgroup_node += tbody for row_index, row in enumerate(data): row_node = nodes.row() for col_index, cell_item in enumerate(row): row_node += self.create_cell(col_index, cell_item, row_index < num_headers) if row_index < num_headers: thead += row_node else: tbody += row_node return table_node
def run(self): doc = ET.parse("doxyxml/xml/namespacetweedledum.xml") members = doc.findall("compounddef/sectiondef[@kind='func']/memberdef/detaileddescription/para/xrefsect/xrefdescription/[para='synthesis ']/../../../..") table = nodes.table() tgroup = nodes.tgroup(cols = 4) tgroup += nodes.colspec(colwidth = 50) tgroup += nodes.colspec(colwidth = 100) tgroup += nodes.colspec(colwidth = 50) tgroup += nodes.colspec(colwidth = 50) # header tgroup += nodes.thead('', nodes.row('', *[nodes.entry('', nodes.line(text = c)) for c in ["Function", "Description", "Expects", "Returns"]])) # body tbody = nodes.tbody() for member in members: text = member.find('name').text.strip() brief = member.find('briefdescription/para').text.strip() expects = "foo" returns = "bar" for e in member.findall('detaileddescription/para/xrefsect'): key = e.find('xreftitle').text.strip() value = e.find('xrefdescription/para').text.strip() if key == "algexpects": expects = value elif key == "algreturns": returns = value filename = os.path.basename(member.find('location').attrib['file'])[:-4] ref = nodes.reference('', text, internal = True) ref['refuri'] = 'synthesis/{}.html#{}'.format(filename, member.attrib["id"]) reft = nodes.paragraph() reft.extend([ref]) function = nodes.entry('', reft) description = nodes.entry('', nodes.line(text = brief)) expects = nodes.entry('', nodes.line(text = expects)) returns = nodes.entry('', nodes.line(text = returns)) tbody += nodes.row('', function, description, expects, returns) tgroup += tbody table += tgroup return [table]
def get_table(self, items): # type: (List[Tuple[unicode, unicode, unicode, unicode]]) -> List[Union[addnodes.tabular_col_spec, autosummary_table]] # NOQA """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = r'\X{1}{2}\X{1}{2}' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): # type: (unicode) -> None row = nodes.row('') source, line = self.state_machine.get_source_and_line() for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '%s:%d:<autosummary>' % (source, line)) with switch_source_input(self.state, vl): self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name in items: qualifier = 'obj' if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig)) # type: unicode # NOQA else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary append_row(col1, col2) return [table_spec, table]
def get_table(self, items): """ Subclass to get support for `hidesummary` as options to enable displaying the short summary in the table """ hidesummary = 'hidesummary' in self.options table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'p{0.5\linewidth}p{0.5\linewidth}' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name in items: qualifier = 'obj' if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, rst.escape(sig)) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary if hidesummary: append_row(col1) else: append_row(col1, col2) return [table_spec, table]
def run(self): table = nodes.table('') ## Create table group = nodes.tgroup('', cols=3) table.append(group) for colwidth in 10, 40, 5: group.append(nodes.colspec('', colwidth=colwidth)) head = nodes.thead('') group.append(head) body = nodes.tbody('') group.append(body) def add_row(target, *column_texts): row = nodes.row('') for text in column_texts: if text == None: text = "" node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) target.append(row) def get_symbol(s): parametertable_path = s.split('.') for i in reversed(range(len(parametertable_path))): module = '.'.join(parametertable_path[:i]) symbol = parametertable_path[i:] try: m = __import__(str(module), fromlist='true') except ImportError: continue else: break parent = m for sym in symbol: parent = getattr(parent, sym) return parent add_row(head, 'Parameter', 'Description', 'Unit') for param in get_symbol(self.arguments[0]): add_row(body, param.name, param.desc, param.unit) return [table]
def envy_resolve(app, doctree, fromdocname): objects = app.env.domaindata['envy']['objects'] # add uplink info for holder in doctree.traverse(uplink_placeholder): obj = objects[holder.name] links = [] for sp, pos, name, variants in obj.uplinks: signode = addnodes.desc_signature('', '') signode['first'] = False signode += make_refnode(app.builder, fromdocname, sp.docname, sp.iname + '-' + sp.name, addnodes.desc_addname(sp.name, sp.name), sp.name) text = ' {}: {}'.format(pos, name) signode += addnodes.desc_name(text, text) if variants is not None: text = ' [{}]'.format(variants) signode += addnodes.desc_annotation(text, text) links.append(signode) holder.replace_self(links) # add subnode list for holder in doctree.traverse(sub_placeholder): obj = objects[holder.name] add_variant = False for pos, name, child, variants in obj.subs: if variants is not None: add_variant = True table = nodes.table() headers = [(1, 'Address'), (1, 'Name'), (10, 'Description')] if add_variant: headers.insert(1, (1, 'Variants')) tgroup = nodes.tgroup(cols=len(headers)) table += tgroup for colwidth, header in headers: tgroup += nodes.colspec(colwidth=colwidth) thead = nodes.thead() tgroup += thead headrow = nodes.row() for colwidth, header in headers: entry = nodes.entry() para = nodes.paragraph() entry += para para += nodes.Text(header, header) headrow += entry thead += headrow tbody = nodes.tbody() tgroup += tbody for pos, name, child, variants in obj.subs: row = nodes.row() row += wrap_text_entry(pos) if add_variant: row += wrap_text_entry('all' if variants is None else variants) row += wrap_text_entry(name) entry = nodes.entry() para = nodes.paragraph() entry += para para += make_refnode(app.builder, fromdocname, child.docname, child.iname + '-' + child.name, nodes.Text(child.brief, child.brief), obj.brief) row += entry tbody += row holder.replace_self([table])
def run(self): table = nodes.table('') ## Create table group = nodes.tgroup('', cols=3) table.append(group) for colwidth in 10,40,5: group.append(nodes.colspec('', colwidth=colwidth)) head = nodes.thead('') group.append(head) body = nodes.tbody('') group.append(body) def add_row(target, *column_texts): row = nodes.row('') for text in column_texts: if text == None: text = "" node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) target.append(row) def get_symbol(s): parametertable_path = s.split('.') for i in reversed(range(len(parametertable_path))): module = '.'.join(parametertable_path[:i]) symbol = parametertable_path[i:] try: m = __import__(str(module), fromlist='true') except ImportError: continue else: break parent = m for sym in symbol: parent = getattr(parent, sym) return parent add_row(head, 'Parameter', 'Description' , 'Unit') for param in get_symbol(self.arguments[0]): add_row(body, param.name, param.desc, param.unit) return [table]
def build_details_table(self, error_obj): table = nodes.table() tgroup = nodes.tgroup(cols=2) table += tgroup tgroup += nodes.colspec(colwidth=20) tgroup += nodes.colspec(colwidth=80) tbody = nodes.tbody() tgroup += tbody # API Error Code append_detail_row(tbody, 'API Error Code', nodes.literal(text=error_obj.code)) # HTTP Status Code ref = parse_text(self, ':http:`%s`' % error_obj.http_status) append_detail_row(tbody, 'HTTP Status Code', ref) # Error Text append_detail_row(tbody, 'Error Text', nodes.literal(text=error_obj.msg)) if error_obj.headers: # HTTP Headers if len(error_obj.headers) == 1: content = nodes.literal(text=error_obj.headers.keys()[0]) else: content = nodes.bullet_list() for header in error_obj.headers.iterkeys(): item = nodes.list_item() content += item literal = nodes.literal(text=header) item += literal append_detail_row(tbody, 'HTTP Headers', content) # Description append_detail_row(tbody, 'Description', parse_text(self, '\n'.join(self.content))) return table
def make_stat_table(nb_execution_data): key2header = { "mtime": "Modified", "method": "Method", "runtime": "Run Time (s)", "succeeded": "Status", } key2transform = { "mtime": lambda x: datetime.fromtimestamp(x).strftime("%Y-%m-%d %H:%M") if x else "", "method": str, "runtime": lambda x: "-" if x is None else str(round(x, 2)), "succeeded": lambda x: "✅" if x is True else "❌", } # top-level element table = nodes.table() table["classes"] += ["colwidths-auto"] # self.set_source_info(table) # column settings element ncols = len(key2header) + 1 tgroup = nodes.tgroup(cols=ncols) table += tgroup colwidths = [round(100 / ncols, 2)] * ncols for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) tgroup += colspec # header thead = nodes.thead() tgroup += thead row = nodes.row() thead += row for name in ["Document"] + list(key2header.values()): row.append(nodes.entry("", nodes.paragraph(text=name))) # body tbody = nodes.tbody() tgroup += tbody for docname in sorted(nb_execution_data.keys()): data = nb_execution_data[docname] row = nodes.row() tbody += row row.append(nodes.entry("", nodes.paragraph(text=docname))) for name in key2header.keys(): text = key2transform[name](data[name]) row.append(nodes.entry("", nodes.paragraph(text=text))) return table
def make_seq_table(self, title, data): hdr = 'Repeats Condition Position Time A B C D E F Time A B C D E F' hdr = hdr.split() col_widths = [len(x) for x in hdr] ncols = len(col_widths) table = nodes.table() # set the column width specs tgroup = nodes.tgroup(cols=ncols) table += tgroup for col_width in col_widths: tgroup += nodes.colspec(colwidth=col_width) # add the header thead = nodes.thead() tgroup += thead thead += self.make_row([title], [ncols - 1]) h1_text = [ "#", "Trigger", "Phase1", "Phase1 Outputs", "Phase2", "Phase2 Outputs" ] h1_more = [None, 1, None, 5, None, 5] thead += self.make_row(h1_text, h1_more) thead += self.make_row(hdr) tbody = nodes.tbody() tgroup += tbody # Add each row for frame in range(len(data) / 4): row = [] # First we get n repeats rpt = int(data[0 + frame * 4], 0) & 0xFFFF row.append(rpt) # Then the trigger values trigger = int(data[0 + frame * 4], 0) >> 16 & 0xF strings = [ "Immediate", "BITA=0", "BITA=1", "BITB=0", "BITB=1", "BITC=0", "BITC=1", "POSA>=POSITION", "POSA<=POSITION", "POSB>=POSITION", "POSB<=POSITION", "POSC>=POSITION", "POSC<=POSITION", "", "", "" ] row.append(strings[trigger]) # Then the position position = data[1 + frame * 4] row.append(position) # Then the phase 1 time p1Len = data[2 + frame * 4] row.append(p1Len) # Then the phase 1 outputs p1Out = (int(data[0 + frame * 4], 0) >> 20) & 0x3F for i in range(6): row.append(p1Out >> i & 1) # Then the phase 2 time p2Len = data[3 + frame * 4] row.append(p2Len) # Finally the phase 2 outputs p2Out = (int(data[0 + frame * 4], 0) >> 26) & 0x3F for i in range(6): row.append(p2Out >> i & 1) tbody += self.make_row(row) return table
def build_result_table(product, cut): meta = product.get('meta') data = product.get('data') if 'domain' not in meta: return build = get_build_by_domain(meta['domain']) if not build.span: return table_node = nodes.table() measures = build.measures(data, cut) group_node = nodes.tgroup(cols=build.span) table_node += group_node for measure in measures: colspec_node = nodes.colspec(colwidth=measure) group_node += colspec_node head_node = nodes.thead() group_node += head_node head_rows = build.head(build.head_height()) if head_rows: for row in head_rows: row_node = nodes.row() head_node += row_node for cell, rowspan, colspan, classes in row: entry_node = nodes.entry(classes=classes) if rowspan > 1: entry_node['morerows'] = rowspan - 1 if colspan > 1: entry_node['morecols'] = colspan - 1 row_node += entry_node para_node = nodes.paragraph() entry_node += para_node text_node = nodes.Text(cell) para_node += text_node body_node = nodes.tbody() group_node += body_node body_rows = build.body(build.body_height(data, cut), data, cut) if body_rows: for row in body_rows: row_node = nodes.row() body_node += row_node for cell, rowspan, colspan, classes in row: entry_node = nodes.entry(classes=classes) if rowspan > 1: entry_node['morerows'] = rowspan - 1 if colspan > 1: entry_node['morecols'] = colspan - 1 row_node += entry_node para_node = nodes.paragraph() entry_node += para_node text_node = nodes.Text(cell) if any(cls in classes for cls in ['htsql-empty-val', 'htsql-null-val', 'htsql-cut']): only_node = addnodes.only(expr='latex or text') only_node += text_node para_node += only_node else: para_node += text_node return table_node
def run(self): env = self.state.document.settings.env items = [] data = list(csv.reader(self.content)) for row in data: if not row: continue if len(row) == 3: items.append((row[0], row[1], True)) else: items.append((row[0], row[1], False)) col_widths = self.get_column_widths(2) title, messages = self.make_title() table = nodes.table() # Set up column specifications based on widths tgroup = nodes.tgroup(cols=2) table += tgroup tgroup.extend( nodes.colspec(colwidth=col_width) for col_width in col_widths) thead = nodes.thead() tgroup += thead trow = nodes.row() thead += trow trow.extend( nodes.entry(h, nodes.paragraph(text=h)) for h in ('Pin', 'Function')) tbody = nodes.tbody() tgroup += tbody for name, func, important in items: trow = nodes.row() entry = nodes.entry() para = nodes.paragraph() para += nodes.literal(text=name) entry += para trow += entry entry = nodes.entry() if important: para = nodes.paragraph() para += nodes.strong(text=func) else: para = nodes.paragraph(text=func) entry += para trow += entry tbody += trow table['classes'] += ['no-center'] self.add_name(table) if title: table.insert(0, title) return [table] + messages
def get_table(self, items): """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('') real_table.append(group) group.append(nodes.colspec('', colwidth=0)) group.append(nodes.colspec('', colwidth=100)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name, prefix in items: qualifier = 'obj' if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) if prefix: prefix = "*%s*" % prefix append_row(prefix, col1) return [table_spec, table]
def build_errors_table(self, errors): """Build a table representing a list of errors. Args: errors (list of djblets.webapi.errors.WebAPIError): The errors to display. Returns: list of docutils.nodes.Node: The resulting list of nodes for the errors table. """ table = nodes.table(classes=['api-errors']) tgroup = nodes.tgroup(cols=2) table += tgroup tgroup += nodes.colspec(colwidth=25) tgroup += nodes.colspec(colwidth=75) tbody = nodes.tbody() tgroup += tbody for error in sorted(errors, key=lambda x: x.code): http_code = nodes.inline(classes=['http-error']) http_code += nodes.reference( text='HTTP %s - %s' % (error.http_status, HTTP_STATUS_CODES[error.http_status]), refuri=(DEFAULT_HTTP_STATUS_CODES_URL % error.http_status)), error_code = nodes.inline(classes=['api-error']) error_code += get_ref_to_error(error) error_info = nodes.inline() error_info += error_code error_info += http_code append_row( tbody, [ error_info, nodes.inline(text=error.msg), ]) return table
def transform_content(self, contentnode: addnodes.desc_content) -> None: name = self.names[0] path = Path(name) js_path = path.with_suffix('.json') if not js_path.exists(): w = self.state.reporter.warning( f'schema file {js_path} does not exist') contentnode += w return schema = json.loads(js_path.read_text()) table = nodes.table(classes=['colwidths-auto']) tg = nodes.tgroup(cols=2) tg += nodes.colspec(colwidth=1) tg += nodes.colspec(colwidth=0) table += tg # set up the table heading head = nodes.thead() hrow = nodes.row() head += hrow hrow += nodes.entry('', nodes.paragraph('', '', nodes.inline('', 'Field'))) hrow += nodes.entry('', nodes.paragraph('', '', nodes.inline('', 'Type'))) tg += head # write the field table tb = nodes.tbody() tg += tb for field in schema.get('fields', []): row = nodes.row() row += nodes.entry( '', nodes.paragraph('', '', nodes.literal('', field['name']))) type = field['data_type'] if field['nullable']: type += '?' row += nodes.entry( '', nodes.paragraph('', '', nodes.literal('', type))) tb += row contentnode += table
def model_table(model): table = nodes.table() tgroup = nodes.tgroup(cols=2) colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) table += tgroup rows = [] row = nodes.row() rows.append(row) entry = nodes.entry() entry += nodes.paragraph(text="id") row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.id) row += entry row = nodes.row() rows.append(row) entry = nodes.entry() entry += nodes.paragraph(text="name") row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.name) row += entry row = nodes.row() rows.append(row) entry = nodes.entry() entry += nodes.paragraph(text="num_populations") row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.num_populations) row += entry tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
def _get_table(self, objects): table_spec = addnodes.tabular_col_spec() table_spec["spec"] = r"p{0.5\linewidth}p{0.5\linewidth}" table = sphinx.ext.autosummary.autosummary_table("") real_table = nodes.table("", classes=["longtable"]) table.append(real_table) group = nodes.tgroup("", cols=2) real_table.append(group) group.append(nodes.colspec("", colwidth=10)) group.append(nodes.colspec("", colwidth=90)) body = nodes.tbody("") group.append(body) for obj in objects: body.append(self._get_row(obj)) return [table_spec, table]
def chromosomes_table(self, species): table = nodes.table() tgroup = nodes.tgroup(cols=4) for _ in range(4): 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="Length") row += entry entry = nodes.entry() entry += nodes.paragraph(text="Recombination rate") row += entry entry = nodes.entry() entry += nodes.paragraph(text="Mutation rate") row += entry thead.append(row) rows = [] for chrom in species.genome.chromosomes: row = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text=chrom.id) row += entry entry = nodes.entry() entry += nodes.paragraph(text="{:d}".format(chrom.length)) row += entry entry = nodes.entry() entry += nodes.paragraph( text="{:g}".format(chrom.recombination_rate)) row += entry entry = nodes.entry() entry += nodes.paragraph(text="{:g}".format(chrom.mutation_rate)) row += entry # TODO add mutation/recombination rate. rows.append(row) tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
def _get_table(self, objects): table_spec = addnodes.tabular_col_spec() table_spec['spec'] = r'p{0.5\linewidth}p{0.5\linewidth}' table = sphinx.ext.autosummary.autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) for obj in objects: body.append(self._get_row(obj)) return [table_spec, table]
def run(self): table = nodes.table( "", classes=[ "longtable", "colwidths-auto", # "colwidths-given", ], ) group = nodes.tgroup("", cols=3) table.append(group) group.append(nodes.colspec("", colwidth=35)) group.append(nodes.colspec("", colwidth=15)) group.append(nodes.colspec("", colwidth=50)) thead = nodes.thead("") group.append(thead) headrow = nodes.row("") thead.append(headrow) headrow.append(nodes.entry("", nodes.paragraph(text="Config Option"))) headrow.append(nodes.entry("", nodes.paragraph(text="Default Value"))) headrow.append(nodes.entry("", nodes.paragraph(text="Description"))) tbody = nodes.tbody("") group.append(tbody) for config_option in pn.config._options_registry.values(): row = nodes.row("") tbody.append(row) name = config_option.name default_value = config_option.default_value description = config_option.description row.append(nodes.entry("", nodes.literal(text=name))) row.append(nodes.entry("", nodes.literal(text=repr(default_value)))) row.append(nodes.entry("", self._parse_string(description))) return [table]
def make_cols(directive, num_cols): # tgroup = nodes.tgroup(cols=num_cols) col_widths = directive.get_column_widths(num_cols) for w in col_widths: colspec = nodes.colspec() colspec['colwidth'] = w tgroup += colspec return tgroup
def visit_table(self, node): # docutils html writer crashes without tgroup/colspec table = nodes.table() table['classes'] = ["colwidths-auto"] self.append_node(table) tgroup = nodes.tgroup() maxrow = max(len(row.findall("td")) for row in node.findall("*/tr")) for _ in range(maxrow): tgroup += nodes.colspec() tgroup['stub'] = None return tgroup
def make_seq_table(self, title, data): hdr = 'Repeats A B C D A B C D Time A B C D E F Time A B C D E F' hdr = hdr.split() col_widths = [len(x) for x in hdr] ncols = len(col_widths) table = nodes.table() # set the column width specs tgroup = nodes.tgroup(cols=ncols) table += tgroup for col_width in col_widths: tgroup += nodes.colspec(colwidth=col_width) # add the header thead = nodes.thead() tgroup += thead thead += self.make_row([title], [ncols - 1]) h1_text = [ "#", "Use Input", "Input Val", "Ph1", "Ph1 Outputs", "Ph2", "Ph2 Outputs" ] h1_more = [None, 3, 3, None, 5, None, 5] thead += self.make_row(h1_text, h1_more) thead += self.make_row(hdr) tbody = nodes.tbody() tgroup += tbody # Add each row for frame in range(len(data) / 4): row = [] # First we get n repeats rpt = data[0 + frame * 4] row.append(rpt) # Then the input use inMask = (data[1 + frame * 4] >> 28) & 0xF for i in range(4): row.append(inMask >> i & 1) # Then the input values inCond = (data[1 + frame * 4] >> 24) & 0xF for i in range(4): row.append(inCond >> i & 1) # Then the phase 1 time p1Len = data[2 + frame * 4] row.append(p1Len) # Then the phase 1 outputs p1Out = (data[1 + frame * 4] >> 16) & 0x3F for i in range(6): row.append(p1Out >> i & 1) # Then the phase 2 time p2Len = data[3 + frame * 4] row.append(p2Len) # Finally the phase 2 outputs p2Out = (data[1 + frame * 4] >> 8) & 0x3F for i in range(6): row.append(p2Out >> i & 1) tbody += self.make_row(row) return table
def _build_table(self, options, title, description): table = n.table() table["classes"] += ["colwidths-auto"] options_group = n.tgroup(cols=3) table += options_group for _ in range(3): options_group += n.colspec() body = self._make_table_body(self.build_rows(options), title, description) options_group += body return table
def run(self): tree = self.state.document.settings.env.app.doxyxml table = nodes.table() tgroup = nodes.tgroup(cols=2) tgroup += nodes.colspec(colwidth=50) tgroup += nodes.colspec(colwidth=50) # header tgroup += nodes.thead( '', nodes.row( '', *[ nodes.entry('', nodes.line(text=c)) for c in ["Function", "Description"] ])) # rows tbody = nodes.tbody() for c in self.content: name = c.strip() query = name.replace("&", " &") for elem in tree.findall( "./compounddef/sectiondef/memberdef/[name='%s']" % query): args = ', '.join(e.text for e in elem.findall("./param/declname")) ref = addnodes.pending_xref('', refdomain='cpp', refexplicit=False, reftype='func', reftarget='percy::' + name) ref += nodes.literal(text='%s(%s)' % (name, args)) reft = nodes.paragraph() reft.extend([ref]) func = nodes.entry('', reft) desc = nodes.entry( '', nodes.line(text=elem.findtext("./briefdescription/para"))) tbody += nodes.row('', func, desc) tgroup += tbody table += tgroup return [table]
def _build_table(data, number_of_columns): colwidths = tuple(repeat(1, times=number_of_columns)) table = nodes.table() tgroup = nodes.tgroup(cols=number_of_columns) table += tgroup for colwidth in colwidths: tgroup += nodes.colspec(colwidth=colwidth) tbody = nodes.tbody() tgroup += tbody for data_row in data: tbody += _create_table_row(data_row) return [table]
def build_table_from_list( table_data, # col_widths, header_rows, stub_columns=0, widths="auto"): """ :param table_data: list of lists giving table data :param header_rows: list of header rows :param stub_columns: number of columns to mark as "stubs" """ table = nodes.table() max_cols = len(table_data[0]) col_widths = [100 // max_cols] * max_cols # if widths == 'auto': # table['classes'] += ['colwidths-auto'] # elif widths: # "grid" or list of integers # table['classes'] += ['colwidths-given'] table['classes'] += ['colwidths-auto'] tgroup = nodes.tgroup(cols=max_cols) 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
def run(self): doc = ET.parse("doxyxml/xml/{}.xml".format(self.arguments[0])) table = nodes.table() tgroup = nodes.tgroup(cols=2) tgroup += nodes.colspec(colwidth=50) tgroup += nodes.colspec(colwidth=50) # header colname = self.options.get('column', "Function") tgroup += nodes.thead( '', nodes.row( '', *[ nodes.entry('', nodes.line(text=c)) for c in [colname, "Description"] ])) # rows tbody = nodes.tbody() for target in self.content: for elem in doc.findall( "./compounddef/sectiondef/memberdef/[name='%s']" % target): ref = nodes.reference('', target, internal=True) ref['refuri'] = '#{}'.format(elem.attrib["id"]) reft = nodes.paragraph() reft.extend([ref]) func = nodes.entry('', reft) desc = nodes.entry( '', nodes.line(text=elem.findtext("./briefdescription/para"))) tbody += nodes.row('', func, desc) tgroup += tbody table += tgroup return [table]