# dupeGuru 4.3.1 documentation

## hscommon.gui.tree

`Tree`() | Cross-toolkit GUI-enabled tree view.
`Node`(name) | Pretty bland node implementation to be used in a `Tree`.

class hscommon.gui.tree.Tree

  Cross-toolkit GUI-enabled tree view.

  This class is a bit too thin to be used as a tree view controller out of the box and HS apps that subclasses it each add quite a bit of logic to it to make it workable. Making this more usable out of the box is a work in progress.

  This class is here (in addition to being a `Node`) mostly to handle selection.

  Subclasses `Node` (it is the root node of all its children) and `GUIObject`.

  _select_nodes(nodes)

    (Virtual) Customize node selection behavior.

    By default, simply set `_selected_nodes`.

  _view_updated()

    (Virtual) Called after `view` has been set.

    Doing nothing by default, this method is called after `view` has been set (it isn’t called when it’s unset, however). Use this for initialization code that requires a view (which is often the whole of the initialization code).

  clear()

    Clears the node of all its children.

  _selected_nodes

    Where we store selected nodes (as a list of `Node`)

  property selected_node

    Currently selected node.

    :class:`Node`. get/set.

    First of `selected_nodes`. `None` if empty.

  property selected_nodes

    List of selected nodes in the tree.

    List of :class:`Node`. get/set.

    We use nodes instead of indexes to store selection because it’s simpler when it’s time to manage selection of multiple node levels.

  property selected_path

    Currently selected path.

    :attr:`Node.path`. get/set.

    First of `selected_paths`. `None` if empty.

  property selected_paths

    List of selected paths in the tree.

    List of :attr:`Node.path`. get/set

    Computed from `selected_nodes`.

class hscommon.gui.tree.Node(name)

  Pretty bland node implementation to be used in a `Tree`.

  It has a `parent`, behaves like a list, its content being its children. Link integrity is somewhat enforced (adding a child to a node will set the child’s `parent`, but that’s pretty much as far as we go, integrity-wise. Nodes don’t tend to move around much in a GUI tree). We don’t even check for infinite node loops. Don’t play around these grounds too much.

  Nodes are designed to be subclassed and given meaningful attributes (those you’ll want to display in your tree view), but they all have a `name`, which is given on initialization.

  append(node)

    S.append(value) – append value to the end of the sequence

  clear()

    Clears the node of all its children.

  find(predicate, include_self=True)

    Return the first child to match `predicate`.

    See `findall()`.

  findall(predicate, include_self=True)

    Yield all children matching `predicate`.

    Parameters

      - predicate – `f(node) --> bool`

      - include_self – Whether we can return `self` or we return only children.

  get_node(index_path)

    Returns the node at `index_path`.

    Parameters

      index_path – a list of int indexes leading to our node. See `path`.

  get_path(target_node)

    Returns the `path` of `target_node`.

    If `target_node` is `None`, returns `None`.

  insert(index, node)

    S.insert(index, value) – insert value before index

  property children_count

    Same as `len(self)`.

  property name

    Name for the node, supplied on init.

  property parent

    Parent of the node.

    If `None`, we have a root node.

  property path

    A list of node indexes leading from the root node to `self`.

    The path of a node is always related to its `root`. It’s the sequences of index that we have to take to get to our node, starting from the root. For example, if `node.path == [1, 2, 3, 4]`, it means that `node.root[1][2][3][4] is node`.

  property root

    Root node of current node.

    To get it, we recursively follow our `parent` chain until we have `None`.