traitsui.tree_node module

Defines the tree node descriptor used by the tree editor and tree editor factory classes.

class traitsui.tree_node.ITreeNode

Bases: traits.has_traits.Interface

activated()

Handles an object being activated.

allows_children()

Returns whether this object can have children.

append_child(child)

Appends a child to the object’s children.

can_add(add_object)

Returns whether a given object is droppable on the node.

can_auto_close()

Returns whether the object’s children should be automatically closed.

can_auto_open()

Returns whether the object’s children should be automatically opened.

can_copy()

Returns whether the object’s children can be copied.

can_delete()

Returns whether the object’s children can be deleted.

can_delete_me()

Returns whether the object can be deleted.

can_insert()

Returns whether the object’s children can be inserted (vs. appended).

can_rename()

Returns whether the object’s children can be renamed.

can_rename_me()

Returns whether the object can be renamed.

click()

Handles an object being clicked.

confirm_delete()

Checks whether a specified object can be deleted.

The following return values are possible:

  • True if the object should be deleted with no further prompting.

  • False if the object should not be deleted.

  • Anything else: Caller should take its default action (which might include prompting the user to confirm deletion).

dclick()

Handles an object being double-clicked.

delete_child(index)

Deletes a child at a specified index from the object’s children.

drop_object(dropped_object)

Returns a droppable version of a specified object.

get_add()

Returns the list of classes that can be added to the object.

get_children()

Gets the object’s children.

get_children_id()

Gets the object’s children identifier.

get_column_labels(object)

Get the labels for any columns that have been defined.

get_drag_object()

Returns a draggable version of a specified object.

get_icon(is_expanded)

Returns the icon for a specified object.

get_icon_path()

Returns the path used to locate an object’s icon.

get_label()

Gets the label to display for a specified object.

get_menu()

Returns the right-click context menu for an object.

get_name()

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

get_tooltip()

Gets the tooltip to display for a specified object.

get_view()

Gets the view to use when editing an object.

has_children()

Returns whether the object has children.

insert_child(index, child)

Inserts a child into the object’s children.

select()

Handles an object being selected.

set_label(label)

Sets the label for a specified object.

when_children_changed(listener, remove)

Sets up or removes a listener for children being changed on a specified object.

when_children_replaced(listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

when_column_labels_change(object, listener, remove)

Sets up or removes a listener for the column labels being changed on a specified object.

This will fire when either the list is reassigned or when it is modified. I.e., it listens both to the trait change event and the trait_items change event. Implement the listener appropriately to handle either case.

when_label_changed(listener, remove)

Sets up or removes a listener for the label being changed on a specified object.

class traitsui.tree_node.ITreeNodeAdapter(adaptee, **traits)

Bases: traits.adaptation.adapter.Adapter

Abstract base class for an adapter that implements the ITreeNode interface.

Usage:

  1. Create a subclass of ITreeNodeAdapter.

  2. Register the adapter to define what class (or classes) this is an ITreeNode adapter for (ie. register_factory(<from class>, ITreeNode, ITreeNodeAdapter)).

  3. Override any of the following methods as necessary, using the self.adaptee trait to access the adapted object if needed.

Note

This base class implements all of the ITreeNode interface methods, but does not necessarily provide useful implementations for all of the methods. It allows you to get a new adapter class up and running quickly, but you should carefully review your final adapter implementation class to make sure it behaves correctly in your application.

activated()

Handles an object being activated.

allows_children()

Returns whether this object can have children.

append_child(child)

Appends a child to the object’s children.

can_add(add_object)

Returns whether a given object is droppable on the node.

can_auto_close()

Returns whether the object’s children should be automatically closed.

can_auto_open()

Returns whether the object’s children should be automatically opened.

can_copy()

Returns whether the object’s children can be copied.

can_delete()

Returns whether the object’s children can be deleted.

can_delete_me()

Returns whether the object can be deleted.

can_insert()

Returns whether the object’s children can be inserted (vs. appended).

can_rename()

Returns whether the object’s children can be renamed.

can_rename_me()

Returns whether the object can be renamed.

click()

Handles an object being clicked.

confirm_delete()

Checks whether a specified object can be deleted.

The following return values are possible:

  • True if the object should be deleted with no further prompting.

  • False if the object should not be deleted.

  • Anything else: Caller should take its default action (which might include prompting the user to confirm deletion).

dclick()

Handles an object being double-clicked.

delete_child(index)

Deletes a child at a specified index from the object’s children.

drop_object(dropped_object)

Returns a droppable version of a specified object.

get_add()

Returns the list of classes that can be added to the object.

get_background()

Returns the background for object

get_children()

Gets the object’s children.

get_children_id()

Gets the object’s children identifier.

get_column_labels()

Get the labels for any columns that have been defined.

get_drag_object()

Returns a draggable version of a specified object.

get_foreground()

Returns the foreground for object

get_icon(is_expanded)

Returns the icon for a specified object.

Valid values are ‘<item>’ (file looking icon), ‘<group>’ (closed folder looking icon) and ‘<open>’ (open folder looking icon).

get_icon_path()

Returns the path used to locate an object’s icon.

get_label()

Gets the label to display for a specified object.

get_menu()

Returns the right-click context menu for an object.

get_name()

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

get_renderer(column=0)

Returns the renderer for object

get_tooltip()

Gets the tooltip to display for a specified object.

get_view()

Gets the view to use when editing an object.

has_children()

Returns whether the object has children.

insert_child(index, child)

Inserts a child into the object’s children.

select()

Handles an object being selected.

set_label(label)

Sets the label for a specified object.

when_children_changed(listener, remove)

Sets up or removes a listener for children being changed on a specified object.

when_children_replaced(listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

when_column_labels_change(listener, remove)

Sets up or removes a listener for the column labels being changed on a specified object.

This will fire when either the list is reassigned or when it is modified. I.e., it listens both to the trait change event and the trait_items change event. Implement the listener appropriately to handle either case.

when_label_changed(listener, remove)

Sets up or removes a listener for the label being changed on a specified object.

class traitsui.tree_node.ITreeNodeAdapterBridge

Bases: traits.has_traits.HasPrivateTraits

Private class for use by a toolkit-specific implementation of the TreeEditor to allow bridging the TreeNode interface used by the editor to the ITreeNode interface used by object adapters.

activated(object)

Handles an object being activated.

adapter = Supports(ITreeNode)

The ITreeNode adapter being bridged:

allows_children(object)

Returns whether this object can have children.

append_child(object, child)

Appends a child to the object’s children.

can_add(object, add_object)

Returns whether a given object is droppable on the node.

can_auto_close(object)

Returns whether the object’s children should be automatically closed.

can_auto_open(object)

Returns whether the object’s children should be automatically opened.

can_copy(object)

Returns whether the object’s children can be copied.

can_delete(object)

Returns whether the object’s children can be deleted.

can_delete_me(object)

Returns whether the object can be deleted.

can_insert(object)

Returns whether the object’s children can be inserted (vs. appended).

can_rename(object)

Returns whether the object’s children can be renamed.

can_rename_me(object)

Returns whether the object can be renamed.

click(object)

Handles an object being clicked.

confirm_delete(object)

Checks whether a specified object can be deleted.

The following return values are possible:

  • True if the object should be deleted with no further prompting.

  • False if the object should not be deleted.

  • Anything else: Caller should take its default action (which might include prompting the user to confirm deletion).

dclick(object)

Handles an object being double-clicked.

delete_child(object, index)

Deletes a child at a specified index from the object’s children.

drop_object(object, dropped_object)

Returns a droppable version of a specified object.

get_add(object)

Returns the list of classes that can be added to the object.

get_background(object)

Returns the background for object

get_children(object)

Gets the object’s children.

get_children_id(object)

Gets the object’s children identifier.

get_column_labels(object)

Get the labels for any columns that have been defined.

get_drag_object(object)

Returns a draggable version of a specified object.

get_foreground(object)

Returns the foreground for object

get_icon(object, is_expanded)

Returns the icon for a specified object.

get_icon_path(object)

Returns the path used to locate an object’s icon.

get_label(object)

Gets the label to display for a specified object.

get_menu(object)

Returns the right-click context menu for an object.

get_name(object)

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

get_renderer(object, column=0)

Returns the renderer for object

get_tooltip(object)

Gets the tooltip to display for a specified object.

get_view(object)

Gets the view to use when editing an object.

has_children(object)

Returns whether the object has children.

insert_child(object, index, child)

Inserts a child into the object’s children.

select(object)

Handles an object being selected.

set_label(object, label)

Sets the label for a specified object.

when_children_changed(object, listener, remove)

Sets up or removes a listener for children being changed on a specified object.

when_children_replaced(object, listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

when_column_labels_change(object, listener, remove)

Sets up or removes a listener for the column labels being changed on a specified object.

This will fire when either the list is reassigned or when it is modified. I.e., it listens both to the trait change event and the trait_items change event. Implement the listener appropriately to handle either case.

when_label_changed(object, listener, remove)

Sets up or removes a listener for the label being changed on a specified object.

class traitsui.tree_node.MultiTreeNode(**traits)

Bases: traitsui.tree_node.TreeNode

activated(object)

Handles an object being activated.

allows_children(object)

Returns whether this object can have children (True for this class).

can_add(object, add_object)

Returns whether a given object is droppable on the node (False for this class).

can_auto_close(object)

Returns whether the object’s children should be automatically closed.

can_auto_open(object)

Returns whether the object’s children should be automatically opened.

can_copy(object)

Returns whether the object’s children can be copied.

can_delete(object)

Returns whether the object’s children can be deleted (False for this class).

can_delete_me(object)

Returns whether the object can be deleted (True for this class).

can_insert(object)

Returns whether the object’s children can be inserted (False, meaning that children are appended, for this class).

can_rename(object)

Returns whether the object’s children can be renamed (False for this class).

can_rename_me(object)

Returns whether the object can be renamed (False for this class).

click(object)

Handles an object being clicked.

dclick(object)

Handles an object being double-clicked.

drop_object(object, dropped_object)

Returns a droppable version of a specified object.

get_add(object)

Returns the list of classes that can be added to the object.

get_children(object)

Gets the object’s children.

get_children_id(object)

Gets the object’s children identifier.

get_drag_object(object)

Returns a draggable version of a specified object.

get_icon(object, is_expanded)

Returns the icon for a specified object.

get_icon_path(object)

Returns the path used to locate an object’s icon.

get_label(object)

Gets the label to display for a specified object.

get_menu(object)

Returns the right-click context menu for an object.

get_name(object)

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

get_view(object)

Gets the view to use when editing an object.

has_children(object)

Returns whether this object has children (True for this class).

nodes = List(TreeNode)

List of TreeNodes (one for each sub-item list)

root_node = Instance(TreeNode)

TreeNode that applies to the base object itself

select(object)

Handles an object being selected.

set_label(object, label)

Sets the label for a specified object.

when_children_changed(object, listener, remove)

Sets up or removes a listener for children being changed on a specified object.

when_children_replaced(object, listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

when_label_changed(object, listener, remove)

Sets up or removes a listener for the label being changed on a specified object.

class traitsui.tree_node.ObjectTreeNode(**traits)

Bases: traitsui.tree_node.TreeNode

activated(object)

Handles an object being activated.

allows_children(object)

Returns whether this object can have children.

append_child(object, child)

Appends a child to the object’s children.

can_add(object, add_object)

Returns whether a given object is droppable on the node.

can_auto_close(object)

Returns whether the object’s children should be automatically closed.

can_auto_open(object)

Returns whether the object’s children should be automatically opened.

can_copy(object)

Returns whether the object’s children can be copied.

can_delete(object)

Returns whether the object’s children can be deleted.

can_delete_me(object)

Returns whether the object can be deleted.

can_insert(object)

Returns whether the object’s children can be inserted (vs. appended).

can_rename(object)

Returns whether the object’s children can be renamed.

can_rename_me(object)

Returns whether the object can be renamed.

click(object)

Handles an object being clicked.

confirm_delete(object)

Checks whether a specified object can be deleted.

The following return values are possible:

  • True if the object should be deleted with no further prompting.

  • False if the object should not be deleted.

  • Anything else: Caller should take its default action (which might include prompting the user to confirm deletion).

dclick(object)

Handles an object being double-clicked.

delete_child(object, index)

Deletes a child at a specified index from the object’s children.

drop_object(object, dropped_object)

Returns a droppable version of a specified object.

get_add(object)

Returns the list of classes that can be added to the object.

get_children(object)

Gets the object’s children.

get_children_id(object)

Gets the object’s children identifier.

get_drag_object(object)

Returns a draggable version of a specified object.

get_icon(object, is_expanded)

Returns the icon for a specified object.

get_icon_path(object)

Returns the path used to locate an object’s icon.

get_label(object)

Gets the label to display for a specified object.

get_menu(object)

Returns the right-click context menu for an object.

get_name(object)

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

get_tooltip(object)

Gets the tooltip to display for a specified object.

get_view(object)

Gets the view to use when editing an object.

has_children(object)

Returns whether the object has children.

insert_child(object, index, child)

Inserts a child into the object’s children.

is_node_for(object)

Returns whether this is the node that should handle a specified object.

select(object)

Handles an object being selected.

set_label(object, label)

Sets the label for a specified object.

when_children_changed(object, listener, remove)

Sets up or removes a listener for children being changed on a specified object.

when_children_replaced(object, listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

when_label_changed(object, listener, remove)

Sets up or removes a listener for the label being changed on a specified object.

class traitsui.tree_node.TreeNode(**traits)

Bases: traits.has_traits.HasPrivateTraits

Represents a tree node. Used by the tree editor and tree editor factory classes.

activated(object)

Handles an object being activated.

add = List(Any)

List of object classes than can be added or copied

allows_children(object)

Returns whether this object can have children.

append_child(object, child)

Appends a child to the object’s children.

auto_close = Bool(False)

Automatically close sibling tree nodes?

auto_open = Bool(False)

Should tree nodes be automatically opened (expanded)?

background = Any()

Selector or name for background color

can_add(object, add_object)

Returns whether a given object is droppable on the node.

can_auto_close(object)

Returns whether the object’s children should be automatically closed.

can_auto_open(object)

Returns whether the object’s children should be automatically opened.

can_copy(object)

Returns whether the object’s children can be copied.

can_delete(object)

Returns whether the object’s children can be deleted.

can_delete_me(object)

Returns whether the object can be deleted.

can_insert(object)

Returns whether the object’s children can be inserted (vs. appended).

can_rename(object)

Returns whether the object’s children can be renamed.

can_rename_me(object)

Returns whether the object can be renamed.

children = Str()

Name of trait containing children (if ‘’, the node is a leaf). Nested attributes are allowed, e.g., ‘library.books’

click(object)

Handles an object being clicked.

column_formatters = List(Either(None, Callable))

Functions for formatting the other columns.

column_labels = Str()

The name of a trait containing a list of labels for any columns.

confirm_delete(object)

Checks whether a specified object can be deleted.

The following return values are possible:

  • True if the object should be deleted with no further prompting.

  • False if the object should not be deleted.

  • Anything else: Caller should take its default action (which might include prompting the user to confirm deletion).

copy = Bool(True)

Can the object’s children be copied?

dclick(object)

Handles an object being double-clicked.

delete = Bool(True)

Can the object’s children be deleted?

delete_child(object, index)

Deletes a child at a specified index from the object’s children.

delete_me = Bool(True)

Can the object be deleted (if its parent allows it)?

drop_object(object, dropped_object)

Returns a droppable version of a specified object.

foreground = Any()

Selector or name for foreground color

formatter = Callable()

Function for formatting the label

get_add(object)

Returns the list of classes that can be added to the object.

get_background(object)
get_children(object)

Gets the object’s children.

get_children_id(object)

Gets the object’s children identifier.

get_column_labels(object)

Get the labels for any columns that have been defined.

get_drag_object(object)

Returns a draggable version of a specified object.

get_foreground(object)
get_icon(object, is_expanded)

Returns the icon for a specified object.

get_icon_path(object)

Returns the path used to locate an object’s icon.

get_label(object)

Gets the label to display for a specified object.

get_menu(object)

Returns the right-click context menu for an object.

get_name(object)

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

get_renderer(object, column=0)

Return the renderer for the object and column.

get_tooltip(object)

Gets the tooltip to display for a specified object.

get_view(object)

Gets the view to use when editing an object.

has_children(object)

Returns whether the object has children.

icon_group = Str("<group>")

Name of group item icon

icon_item = Str("<item>")

Name of leaf item icon

icon_open = Str("<open>")

Name of opened group item icon

icon_path = Str()

Resource path used to locate the node icon

insert = Bool(True)

Can children be inserted (vs. appended)?

insert_child(object, index, child)

Inserts a child into the object’s children.

is_addable(klass)

Returns whether a specified object class can be added to the node.

is_node_for(object)

Returns whether this is the node that handles a specified object.

label = Str()

Either the name of a trait containing a label, or a constant label, if the string starts with ‘=’.

menu = Any()

Right-click context menu. The value can be one of:

  • Instance( Menu ): Use this menu as the context menu

  • None: Use the default context menu

  • False: Do not display a context menu

move = List(Any)

List of object classes that can be moved

name = Str()

Name to use for a new instance

node_for = List(Any)

List of object classes and/or interfaces that the node applies to

node_for_class = Property(depends_on="node_for")

Tuple of object classes that the node applies to

node_for_interface = Property(depends_on="node_for")

List of object interfaces that the node applies to

on_activated = Callable()

Function for handling activation of an object (double-click or Enter key press when node is in focus)

on_click = Callable()

Function for handling clicking an object

on_dclick = Callable()

Function for handling double-clicking an object

on_select = Callable()

Function for handling selecting an object

rename = Bool(True)

Can the object’s children be renamed?

rename_me = Bool(True)

Can the object be renamed?

renderer = Any()

A toolkit-appropriate cell renderer (currently Qt only)

select(object)

Handles an object being selected.

set_label(object, label)

Sets the label for a specified object.

tooltip = Str()

Either the name of a trait containing a tooltip, or constant tooltip, if the string starts with ‘=’.

tooltip_formatter = Callable()

Function for formatting the tooltip

view = AView

View to use for editing the object

when_children_changed(object, listener, remove)

Sets up or removes a listener for children being changed on a specified object.

when_children_replaced(object, listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

when_column_labels_change(object, listener, remove)

Sets up or removes a listener for the column labels being changed on a specified object.

This will fire when either the list is reassigned or when it is modified. I.e., it listens both to the trait change event and the trait_items change event. Implement the listener appropriately to handle either case.

when_label_changed(object, listener, remove)

Sets up or removes a listener for the label being changed on a specified object.

class traitsui.tree_node.TreeNodeObject

Bases: traits.has_traits.HasPrivateTraits

Represents the object that corresponds to a tree node.

tno_activated(node)

Handles an object being activated.

tno_allows_children(node)

Returns whether this object allows children.

tno_append_child(node, child)

Appends a child to the object’s children.

tno_can_add(node, add_object)

Returns whether a given object is droppable on the node.

tno_can_auto_close(node)

Returns whether the object’s children should be automatically closed.

tno_can_auto_open(node)

Returns whether the object’s children should be automatically opened.

tno_can_copy(node)

Returns whether the object’s children can be copied.

tno_can_delete(node)

Returns whether the object’s children can be deleted.

tno_can_delete_me(node)

Returns whether the object can be deleted.

tno_can_insert(node)

Returns whether the object’s children can be inserted (vs. appended).

tno_can_rename(node)

Returns whether the object’s children can be renamed.

tno_can_rename_me(node)

Returns whether the object can be renamed.

tno_click(node)

Handles an object being clicked.

tno_confirm_delete(node)

Checks whether a specified object can be deleted.

The following return values are possible:

  • True if the object should be deleted with no further prompting.

  • False if the object should not be deleted.

  • Anything else: Caller should take its default action (which might include prompting the user to confirm deletion).

tno_dclick(node)

Handles an object being double-clicked.

tno_delete_child(node, index)

Deletes a child at a specified index from the object’s children.

tno_drop_object(node, dropped_object)

Returns a droppable version of a specified object.

tno_get_add(node)

Returns the list of classes that can be added to the object.

tno_get_children(node)

Gets the object’s children.

tno_get_children_id(node)

Gets the object’s children identifier.

tno_get_drag_object(node)

Returns a draggable version of a specified object.

tno_get_icon(node, is_expanded)

Returns the icon for a specified object.

tno_get_icon_path(node)

Returns the path used to locate an object’s icon.

tno_get_label(node)

Gets the label to display for a specified object.

tno_get_menu(node)

Returns the right-click context menu for an object.

tno_get_name(node)

Returns the name to use when adding a new object instance (displayed in the “New” submenu).

tno_get_tooltip(node)

Gets the tooltip to display for a specified object.

tno_get_view(node)

Gets the view to use when editing an object.

tno_has_children(node)

Returns whether this object has children.

tno_insert_child(node, index, child)

Inserts a child into the object’s children.

tno_is_node_for(node)

Returns whether this is the node that should handle a specified object.

tno_select(node)

Handles an object being selected.

tno_set_label(node, label)

Sets the label for a specified object.

tno_when_children_changed(node, listener, remove)

Sets up or removes a listener for children being changed on a specified object.

tno_when_children_replaced(node, listener, remove)

Sets up or removes a listener for children being replaced on a specified object.

tno_when_label_changed(node, listener, remove)

Sets up or removes a listener for the label being changed on a specified object.