Exemplo n.º 1
0
def test_find_nodes():
    root = _recursive_make_group([0, 1, [20, [210, 211], 22], 3, 4])

    qt_tree = QtNodeTreeModel(root)
    _assert_models_synced(root, qt_tree)
    node = Node(name='212')
    root[2, 1].append(node)
    assert qt_tree.findIndex(node).row() == 2
    assert not qt_tree.findIndex(Node(name='new node')).isValid()
Exemplo n.º 2
0
def test_qt_tree_model_insertion():
    """Test that we can append and insert items to a QTreeModel."""
    root = _recursive_make_group([0, 1, [20, [210, 211], 22], 3, 4])
    qt_tree = QtNodeTreeModel(root)
    _assert_models_synced(root, qt_tree)
    root[2, 1].append(Node(name='212'))
    e = _recursive_make_group([0, 1, [20, [210, 211, 212], 22], 3, 4])
    _assert_models_synced(e, qt_tree)

    root.insert(-2, Node(name='9'))
    e = _recursive_make_group([0, 1, [20, [210, 211, 212], 22], 9, 3, 4])
    _assert_models_synced(e, qt_tree)
Exemplo n.º 3
0
def _recursive_make_group(lst, level=0):
    """Make a Tree of Group/Node objects from a nested list."""
    out = []
    for item in lst:
        if isinstance(item, list):
            out.append(_recursive_make_group(item, level=level + 1))
        else:
            out.append(Node(name=str(item)))
    return Group(out, name=f'g{level}')
Exemplo n.º 4
0
def tree():
    return Group(
        [
            Node(name="1"),
            Group(
                [
                    Node(name="2"),
                    Group([Node(name="3"), Node(name="4")], name="g2"),
                    Node(name="5"),
                    Node(name="6"),
                    Node(name="7"),
                ],
                name="g1",
            ),
            Node(name="8"),
            Node(name="9"),
        ],
        name="root",
    )
Exemplo n.º 5
0
def tree_model():
    root = Group(
        [
            Node(name="1"),
            Group(
                [
                    Node(name="2"),
                    Group([Node(name="3"), Node(name="4")], name="g2"),
                    Node(name="5"),
                    Node(name="6"),
                    Node(name="7"),
                ],
                name="g1",
            ),
            Node(name="8"),
            Node(name="9"),
        ],
        name="root",
    )
    return QtNodeTreeModel(root)
Exemplo n.º 6
0
import logging

# create some readable logging.  Drag and drop the items in the tree to
# see what sort of events are happening in the background.
end = "\033[0m"
Bold = "\033[1m"
Dim = "\033[2m"
ResetDim = "\033[22m"
red = "\033[0;31m"
green = "\033[0;32m"
colorlog_format = f'{green}%(levelname)6s:{end} {Dim}%(name)43s.{ResetDim}{red}%(funcName)-18s{end}{"%(message)s"}'
logging.basicConfig(level=logging.DEBUG, format=colorlog_format)

get_app()

tip = Node(name='tip')
lg2 = Group([Node(name='2'), Node(name='3')], name="g2")
lg1 = Group(
    [Node(name='1'), lg2,
     Node(name='4'), Node(name='5'), tip],
    name="g1",
)
root = Group(
    [Node(name='6'), lg1,
     Node(name='7'),
     Node(name='8'),
     Node(name='9')],
    name="root",
)

# pretty repr makes nested tree structure more interpretable
Exemplo n.º 7
0
This examples shows that :class:`napari._qt.containers.QtNodeTreeView`
is capable of providing a basic GUI for any tree structure based on
`napari.utils.tree.Group`.
"""
import napari
from napari.qt import get_app
from napari._qt.containers import QtNodeTreeView
from napari.utils.tree import Node, Group

get_app()

# create a group of nodes.
root = Group(
    [
        Node(name='6'),
        Group(
            [
                Node(name='1'),
                Group([Node(name='2'), Node(name='3')], name="g2"),
                Node(name='4'),
                Node(name='5'),
                Node(name='tip'),
            ],
            name="g1",
        ),
        Node(name='7'),
        Node(name='8'),
        Node(name='9'),
    ],
    name="root",