hscommon.gui.tree¶
|
Cross-toolkit GUI-enabled tree view. |
|
Pretty bland node implementation to be used in a |
- 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) andGUIObject
.- _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.
- 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’sparent
, 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.
- 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
.
- 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, ifnode.path == [1, 2, 3, 4]
, it means thatnode.root[1][2][3][4] is node
.