ReSTOnlyDirective

class documentationtools.ReSTOnlyDirective(argument=None, children=None, name=None)

A ReST only directive.

>>> import abjad
>>> only = abjad.documentationtools.ReSTOnlyDirective(argument='latex')
>>> heading = abjad.documentationtools.ReSTHeading(
...     level=3, text='A LaTeX-Only Heading')
>>> only.append(heading)
>>> only
ReSTOnlyDirective(
    argument='latex',
    children=(
        ReSTHeading(
            level=3,
            text='A LaTeX-Only Heading'
            ),
        )
    )
>>> print(only.rest_format)
.. only:: latex

A LaTeX-Only Heading
--------------------

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_datastructuretools { graph [label=datastructuretools]; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" [color=3, group=2, label=TreeContainer, shape=box]; "abjad.tools.datastructuretools.TreeNode.TreeNode" [color=3, group=2, label=TreeNode, shape=box]; "abjad.tools.datastructuretools.TreeNode.TreeNode" -> "abjad.tools.datastructuretools.TreeContainer.TreeContainer"; } subgraph cluster_documentationtools { graph [label=documentationtools]; "abjad.tools.documentationtools.ReSTDirective.ReSTDirective" [color=4, group=3, label=ReSTDirective, shape=box]; "abjad.tools.documentationtools.ReSTOnlyDirective.ReSTOnlyDirective" [color=black, fontcolor=white, group=3, label=<<B>ReSTOnlyDirective</B>>, shape=box, style="filled, rounded"]; "abjad.tools.documentationtools.ReSTDirective.ReSTDirective" -> "abjad.tools.documentationtools.ReSTOnlyDirective.ReSTOnlyDirective"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.datastructuretools.TreeNode.TreeNode"; "abjad.tools.datastructuretools.TreeContainer.TreeContainer" -> "abjad.tools.documentationtools.ReSTDirective.ReSTDirective"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Attribute summary

append(node) Appends node to tree container.
argument Gets and sets argument of ReST directive.
children Children of tree container.
depth The depth of a node in a rhythm-tree structure.
depthwise_inventory A dictionary of all nodes in a rhythm-tree, organized by their depth relative the root node.
directive Returns 'only'.
extend(argument) Extendes argument against tree container.
graph_order Graph order of tree node.
improper_parentage The improper parentage of a node in a rhythm-tree, being the sequence of node beginning with itself and ending with the root node of the tree.
index(node) Indexes node in tree container.
insert(i, node) Insert node in tree container at index i.
leaves Leaves of tree container.
name Named of tree node.
node_class Node class of ReST directive.
nodes The collection of tree nodes produced by iterating tree container depth-first.
options Options of ReST directive.
parent Parent of tree node.
pop([i]) Pops node i from tree container.
proper_parentage The proper parentage of a node in a rhythm-tree, being the sequence of node beginning with the node’s immediate parent and ending with the root node of the tree.
remove(node) Remove node from tree container.
rest_format ReST format of ReST directive.
root The root node of the tree: that node in the tree which has no parent.
__contains__(argument) True if argument is in container.
__copy__() Copies tree node.
__delitem__(i) Deletes node i in tree container.
__eq__(argument) Is true when container equals argument.
__format__([format_specification]) Formats Abjad object.
__getitem__(argument) Gets item or slice identified by argument.
__hash__() Hashes tree container.
__iter__() Iterates tree container.
__len__() Returns nonnegative integer number of nodes in container.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.
__setitem__(i, argument) Sets argument in self at nonnegative integer index i, or set argument in self at slice i.

Read-only properties

(TreeContainer).children

Children of tree container.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> d = abjad.TreeNode()
>>> e = abjad.TreeContainer()
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> a.children == (b, c)
True
>>> b.children == (d, e)
True
>>> e.children == ()
True

Returns tuple of tree nodes.

(TreeNode).depth

The depth of a node in a rhythm-tree structure.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.depth
0
>>> a[0].depth
1
>>> a[0][0].depth
2

Returns int.

(TreeNode).depthwise_inventory

A dictionary of all nodes in a rhythm-tree, organized by their depth relative the root node.

>>> a = abjad.TreeContainer(name='a')
>>> b = abjad.TreeContainer(name='b')
>>> c = abjad.TreeContainer(name='c')
>>> d = abjad.TreeContainer(name='d')
>>> e = abjad.TreeContainer(name='e')
>>> f = abjad.TreeContainer(name='f')
>>> g = abjad.TreeContainer(name='g')
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> c.extend([f, g])
>>> inventory = a.depthwise_inventory
>>> for depth in sorted(inventory):
...     print('DEPTH: {}'.format(depth))
...     for node in inventory[depth]:
...         print(node.name)
...
DEPTH: 0
a
DEPTH: 1
b
c
DEPTH: 2
d
e
f
g

Returns dictionary.

ReSTOnlyDirective.directive

Returns 'only'.

(TreeNode).graph_order

Graph order of tree node.

Returns tuple.

(TreeNode).improper_parentage

The improper parentage of a node in a rhythm-tree, being the sequence of node beginning with itself and ending with the root node of the tree.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.improper_parentage == (a,)
True
>>> b.improper_parentage == (b, a)
True
>>> c.improper_parentage == (c, b, a)
True

Returns tuple of tree nodes.

(TreeContainer).leaves

Leaves of tree container.

>>> a = abjad.TreeContainer(name='a')
>>> b = abjad.TreeContainer(name='b')
>>> c = abjad.TreeNode(name='c')
>>> d = abjad.TreeNode(name='d')
>>> e = abjad.TreeContainer(name='e')
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> for leaf in a.leaves:
...     print(leaf.name)
...
d
e
c

Returns tuple.

(ReSTDirective).node_class

Node class of ReST directive.

(TreeContainer).nodes

The collection of tree nodes produced by iterating tree container depth-first.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> d = abjad.TreeNode()
>>> e = abjad.TreeContainer()
>>> a.extend([b, c])
>>> b.extend([d, e])
>>> nodes = a.nodes
>>> len(nodes)
5
>>> nodes[0] is a
True
>>> nodes[1] is b
True
>>> nodes[2] is d
True
>>> nodes[3] is e
True
>>> nodes[4] is c
True

Returns tuple.

(ReSTDirective).options

Options of ReST directive.

(TreeNode).parent

Parent of tree node.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.parent is None
True
>>> b.parent is a
True
>>> c.parent is b
True

Returns tree node.

(TreeNode).proper_parentage

The proper parentage of a node in a rhythm-tree, being the sequence of node beginning with the node’s immediate parent and ending with the root node of the tree.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.proper_parentage == ()
True
>>> b.proper_parentage == (a,)
True
>>> c.proper_parentage == (b, a)
True

Returns tuple of tree nodes.

(ReSTDirective).rest_format

ReST format of ReST directive.

(TreeNode).root

The root node of the tree: that node in the tree which has no parent.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeContainer()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.append(c)
>>> a.root is a
True
>>> b.root is a
True
>>> c.root is a
True

Returns tree node.

Read/write properties

(ReSTDirective).argument

Gets and sets argument of ReST directive.

(TreeNode).name

Named of tree node.

Returns string.

Methods

(TreeContainer).append(node)

Appends node to tree container.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> a
TreeContainer()
>>> a.append(b)
>>> a
TreeContainer(
    children=(
        TreeNode(),
        )
    )
>>> a.append(c)
>>> a
TreeContainer(
    children=(
        TreeNode(),
        TreeNode(),
        )
    )

Returns none.

(TreeContainer).extend(argument)

Extendes argument against tree container.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> a
TreeContainer()
>>> a.extend([b, c])
>>> a
TreeContainer(
    children=(
        TreeNode(),
        TreeNode(),
        )
    )

Returns none.

(TreeContainer).index(node)

Indexes node in tree container.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> a.extend([b, c])
>>> a.index(b)
0
>>> a.index(c)
1

Returns nonnegative integer.

(TreeContainer).insert(i, node)

Insert node in tree container at index i.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> d = abjad.TreeNode()
>>> a.extend([b, c])
>>> a
TreeContainer(
    children=(
        TreeNode(),
        TreeNode(),
        )
    )
>>> a.insert(1, d)
>>> a
TreeContainer(
    children=(
        TreeNode(),
        TreeNode(),
        TreeNode(),
        )
    )

Return None.

(TreeContainer).pop(i=-1)

Pops node i from tree container.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> a.extend([b, c])
>>> a
TreeContainer(
    children=(
        TreeNode(),
        TreeNode(),
        )
    )
>>> node = a.pop()
>>> node == c
True
>>> a
TreeContainer(
    children=(
        TreeNode(),
        )
    )

Returns node.

(TreeContainer).remove(node)

Remove node from tree container.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> a.extend([b, c])
>>> a
TreeContainer(
    children=(
        TreeNode(),
        TreeNode(),
        )
    )
>>> a.remove(b)
>>> a
TreeContainer(
    children=(
        TreeNode(),
        )
    )

Returns none.

Special methods

(TreeContainer).__contains__(argument)

True if argument is in container. Otherwise false:

>>> container = abjad.TreeContainer()
>>> a = abjad.TreeNode()
>>> b = abjad.TreeNode()
>>> container.append(a)
>>> a in container
True
>>> b in container
False

Returns true or false.

(TreeNode).__copy__()

Copies tree node.

(TreeContainer).__delitem__(i)

Deletes node i in tree container.

>>> container = abjad.TreeContainer()
>>> leaf = abjad.TreeNode()
>>> container.append(leaf)
>>> container.children == (leaf,)
True
>>> leaf.parent is container
True
>>> del(container[0])
>>> container.children == ()
True
>>> leaf.parent is None
True

Return None.

(TreeContainer).__eq__(argument)

Is true when container equals argument. Otherwise false.

>>> tree_container_1 = abjad.TreeContainer([])
>>> tree_container_2 = abjad.TreeContainer([])
>>> format(tree_container_1) == format(tree_container_2)
True
>>> tree_container_1 != tree_container_2
True
>>> tree_container_1 = abjad.TreeContainer([abjad.TreeNode()])
>>> tree_container_2 = abjad.TreeContainer([abjad.TreeNode()])
>>> format(tree_container_1) == format(tree_container_2)
True
>>> tree_container_1 != tree_container_2
True
>>> tree_container_1 = abjad.TreeContainer([])
>>> tree_container_2 = abjad.TreeContainer([abjad.TreeNode()])
>>> tree_container_3 = abjad.TreeContainer([
...    abjad.TreeNode(),
...    abjad.TreeNode()
...    ])
>>> format(tree_container_1) != format(tree_container_2)
True
>>> tree_container_1 != tree_container_2
True
>>> tree_container_1 != tree_container_3
True
>>> tree_container_2 != tree_container_3
True

Returns true, false or none.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(TreeContainer).__getitem__(argument)

Gets item or slice identified by argument.

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeContainer()
>>> d = abjad.TreeNode()
>>> e = abjad.TreeNode()
>>> f = abjad.TreeNode()
>>> a.extend([b, c, f])
>>> c.extend([d, e])
>>> a[0] is b
True
>>> a[1] is c
True
>>> a[2] is f
True

If i is a string, the container will attempt to return the single child node, at any depth, whose name matches i:

>>> foo = abjad.TreeContainer(name='foo')
>>> bar = abjad.TreeContainer(name='bar')
>>> baz = abjad.TreeNode(name='baz')
>>> quux = abjad.TreeNode(name='quux')
>>> foo.append(bar)
>>> bar.extend([baz, quux])
>>> foo['bar'] is bar
True
>>> foo['baz'] is baz
True
>>> foo['quux'] is quux
True

Return TreeNode instance.

(TreeContainer).__hash__()

Hashes tree container.

Returns number.

(TreeContainer).__iter__()

Iterates tree container.

Yields children of tree container.

(TreeContainer).__len__()

Returns nonnegative integer number of nodes in container.

>>> leaf_a = abjad.TreeNode()
>>> leaf_b = abjad.TreeNode()
>>> leaf_c = abjad.TreeNode()
>>> subcontainer = abjad.TreeContainer([leaf_b, leaf_c])
>>> leaf_d = abjad.TreeNode()
>>> container = abjad.TreeContainer([
...     leaf_a,
...     subcontainer,
...     leaf_d,
...     ])
>>> len(container)
3
(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

(TreeContainer).__setitem__(i, argument)

Sets argument in self at nonnegative integer index i, or set argument in self at slice i. Replace contents of self[i] with argument. Attach parentage to contents of argument, and detach parentage of any replaced nodes:

>>> a = abjad.TreeContainer()
>>> b = abjad.TreeNode()
>>> c = abjad.TreeNode()
>>> a.append(b)
>>> b.parent is a
True
>>> a.children == (b,)
True
>>> a[0] = c
>>> c.parent is a
True
>>> b.parent is None
True
>>> a.children == (c,)
True

Returns none.