traitsui.tree_node module

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

class traitsui.tree_node.ITreeNode(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: Interface

activated()[source]

Handles an object being activated.

allows_children()[source]

Returns whether this object can have children.

append_child(child)[source]

Appends a child to the object’s children.

can_add(add_object)[source]

Returns whether a given object is droppable on the node.

can_auto_close()[source]

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

can_auto_open()[source]

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

can_copy()[source]

Returns whether the object’s children can be copied.

can_delete()[source]

Returns whether the object’s children can be deleted.

can_delete_me()[source]

Returns whether the object can be deleted.

can_insert()[source]

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

can_rename()[source]

Returns whether the object’s children can be renamed.

can_rename_me()[source]

Returns whether the object can be renamed.

click()[source]

Handles an object being clicked.

confirm_delete()[source]

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()[source]

Handles an object being double-clicked.

delete_child(index)[source]

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

drop_object(dropped_object)[source]

Returns a droppable version of a specified object.

get_add()[source]

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

get_children()[source]

Gets the object’s children.

get_children_id()[source]

Gets the object’s children identifier.

get_column_labels(object)[source]

Get the labels for any columns that have been defined.

get_drag_object()[source]

Returns a draggable version of a specified object.

get_icon(is_expanded)[source]

Returns the icon for a specified object.

get_icon_path()[source]

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

get_label()[source]

Gets the label to display for a specified object.

get_menu()[source]

Returns the right-click context menu for an object.

get_name()[source]

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

get_tooltip()[source]

Gets the tooltip to display for a specified object.

get_view()[source]

Gets the view to use when editing an object.

has_children()[source]

Returns whether the object has children.

insert_child(index, child)[source]

Inserts a child into the object’s children.

select()[source]

Handles an object being selected.

set_label(label)[source]

Sets the label for a specified object.

when_children_changed(listener, remove)[source]

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

when_children_replaced(listener, remove)[source]

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

when_column_labels_change(object, listener, remove)[source]

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)[source]

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

class traitsui.tree_node.ITreeNodeAdapter(adaptee, **traits)[source]

Bases: 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()[source]

Handles an object being activated.

allows_children()[source]

Returns whether this object can have children.

append_child(child)[source]

Appends a child to the object’s children.

can_add(add_object)[source]

Returns whether a given object is droppable on the node.

can_auto_close()[source]

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

can_auto_open()[source]

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

can_copy()[source]

Returns whether the object’s children can be copied.

can_delete()[source]

Returns whether the object’s children can be deleted.

can_delete_me()[source]

Returns whether the object can be deleted.

can_insert()[source]

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

can_rename()[source]

Returns whether the object’s children can be renamed.

can_rename_me()[source]

Returns whether the object can be renamed.

click()[source]

Handles an object being clicked.

confirm_delete()[source]

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()[source]

Handles an object being double-clicked.

delete_child(index)[source]

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

drop_object(dropped_object)[source]

Returns a droppable version of a specified object.

get_add()[source]

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

get_background()[source]

Returns the background for object

get_children()[source]

Gets the object’s children.

get_children_id()[source]

Gets the object’s children identifier.

get_column_labels()[source]

Get the labels for any columns that have been defined.

get_drag_object()[source]

Returns a draggable version of a specified object.

get_foreground()[source]

Returns the foreground for object

get_icon(is_expanded)[source]

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()[source]

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

get_label()[source]

Gets the label to display for a specified object.

get_menu()[source]

Returns the right-click context menu for an object.

get_name()[source]

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

get_renderer(column=0)[source]

Returns the renderer for object

get_tooltip()[source]

Gets the tooltip to display for a specified object.

get_view()[source]

Gets the view to use when editing an object.

has_children()[source]

Returns whether the object has children.

insert_child(index, child)[source]

Inserts a child into the object’s children.

select()[source]

Handles an object being selected.

set_label(label)[source]

Sets the label for a specified object.

when_children_changed(listener, remove)[source]

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

when_children_replaced(listener, remove)[source]

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

when_column_labels_change(listener, remove)[source]

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)[source]

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

class traitsui.tree_node.ITreeNodeAdapterBridge[source]

Bases: 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)[source]

Handles an object being activated.

adapter = Supports(ITreeNode)

The ITreeNode adapter being bridged:

allows_children(object)[source]

Returns whether this object can have children.

append_child(object, child)[source]

Appends a child to the object’s children.

can_add(object, add_object)[source]

Returns whether a given object is droppable on the node.

can_auto_close(object)[source]

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

can_auto_open(object)[source]

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

can_copy(object)[source]

Returns whether the object’s children can be copied.

can_delete(object)[source]

Returns whether the object’s children can be deleted.

can_delete_me(object)[source]

Returns whether the object can be deleted.

can_insert(object)[source]

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

can_rename(object)[source]

Returns whether the object’s children can be renamed.

can_rename_me(object)[source]

Returns whether the object can be renamed.

click(object)[source]

Handles an object being clicked.

confirm_delete(object)[source]

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)[source]

Handles an object being double-clicked.

delete_child(object, index)[source]

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

drop_object(object, dropped_object)[source]

Returns a droppable version of a specified object.

get_add(object)[source]

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

get_background(object)[source]

Returns the background for object

get_children(object)[source]

Gets the object’s children.

get_children_id(object)[source]

Gets the object’s children identifier.

get_column_labels(object)[source]

Get the labels for any columns that have been defined.

get_drag_object(object)[source]

Returns a draggable version of a specified object.

get_foreground(object)[source]

Returns the foreground for object

get_icon(object, is_expanded)[source]

Returns the icon for a specified object.

get_icon_path(object)[source]

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

get_label(object)[source]

Gets the label to display for a specified object.

get_menu(object)[source]

Returns the right-click context menu for an object.

get_name(object)[source]

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

get_renderer(object, column=0)[source]

Returns the renderer for object

get_tooltip(object)[source]

Gets the tooltip to display for a specified object.

get_view(object)[source]

Gets the view to use when editing an object.

has_children(object)[source]

Returns whether the object has children.

insert_child(object, index, child)[source]

Inserts a child into the object’s children.

select(object)[source]

Handles an object being selected.

set_label(object, label)[source]

Sets the label for a specified object.

when_children_changed(object, listener, remove)[source]

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

when_children_replaced(object, listener, remove)[source]

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

when_column_labels_change(object, listener, remove)[source]

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)[source]

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

class traitsui.tree_node.MultiTreeNode(**traits)[source]

Bases: TreeNode

activated(object)[source]

Handles an object being activated.

allows_children(object)[source]

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

can_add(object, add_object)[source]

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

can_auto_close(object)[source]

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

can_auto_open(object)[source]

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

can_copy(object)[source]

Returns whether the object’s children can be copied.

can_delete(object)[source]

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

can_delete_me(object)[source]

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

can_insert(object)[source]

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

can_rename(object)[source]

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

can_rename_me(object)[source]

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

click(object)[source]

Handles an object being clicked.

dclick(object)[source]

Handles an object being double-clicked.

drop_object(object, dropped_object)[source]

Returns a droppable version of a specified object.

get_add(object)[source]

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

get_children(object)[source]

Gets the object’s children.

get_children_id(object)[source]

Gets the object’s children identifier.

get_drag_object(object)[source]

Returns a draggable version of a specified object.

get_icon(object, is_expanded)[source]

Returns the icon for a specified object.

get_icon_path(object)[source]

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

get_label(object)[source]

Gets the label to display for a specified object.

get_menu(object)[source]

Returns the right-click context menu for an object.

get_name(object)[source]

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

get_view(object)[source]

Gets the view to use when editing an object.

has_children(object)[source]

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)[source]

Handles an object being selected.

set_label(object, label)[source]

Sets the label for a specified object.

when_children_changed(object, listener, remove)[source]

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

when_children_replaced(object, listener, remove)[source]

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

when_label_changed(object, listener, remove)[source]

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

class traitsui.tree_node.ObjectTreeNode(**traits)[source]

Bases: TreeNode

activated(object)[source]

Handles an object being activated.

allows_children(object)[source]

Returns whether this object can have children.

append_child(object, child)[source]

Appends a child to the object’s children.

can_add(object, add_object)[source]

Returns whether a given object is droppable on the node.

can_auto_close(object)[source]

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

can_auto_open(object)[source]

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

can_copy(object)[source]

Returns whether the object’s children can be copied.

can_delete(object)[source]

Returns whether the object’s children can be deleted.

can_delete_me(object)[source]

Returns whether the object can be deleted.

can_insert(object)[source]

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

can_rename(object)[source]

Returns whether the object’s children can be renamed.

can_rename_me(object)[source]

Returns whether the object can be renamed.

click(object)[source]

Handles an object being clicked.

confirm_delete(object)[source]

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)[source]

Handles an object being double-clicked.

delete_child(object, index)[source]

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

drop_object(object, dropped_object)[source]

Returns a droppable version of a specified object.

get_add(object)[source]

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

get_children(object)[source]

Gets the object’s children.

get_children_id(object)[source]

Gets the object’s children identifier.

get_drag_object(object)[source]

Returns a draggable version of a specified object.

get_icon(object, is_expanded)[source]

Returns the icon for a specified object.

get_icon_path(object)[source]

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

get_label(object)[source]

Gets the label to display for a specified object.

get_menu(object)[source]

Returns the right-click context menu for an object.

get_name(object)[source]

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

get_tooltip(object)[source]

Gets the tooltip to display for a specified object.

get_view(object)[source]

Gets the view to use when editing an object.

has_children(object)[source]

Returns whether the object has children.

insert_child(object, index, child)[source]

Inserts a child into the object’s children.

is_node_for(object)[source]

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

select(object)[source]

Handles an object being selected.

set_label(object, label)[source]

Sets the label for a specified object.

when_children_changed(object, listener, remove)[source]

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

when_children_replaced(object, listener, remove)[source]

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

when_label_changed(object, listener, remove)[source]

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

class traitsui.tree_node.TreeNode(**traits)[source]

Bases: HasPrivateTraits

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

activated(object)[source]

Handles an object being activated.

add = List(Any)

List of object classes than can be added or copied. Elements of the list can be either:

  • the klass itself that can be added or copied

  • 2-tuples of the form (klass, prompt) in which case klass is as above and prompt is a boolean indicating whether or not to prompt the user to specify trait values after instantiation when adding the object.

  • 3-tuples of the form (klass, prompt, factory) in which case klass and prompt are as above. factory is a callable that is expected to return an instance of klass. Useful if klass has required traits. Otherwise added object is created by simply instantiating klass() ref: enthought/traits#1502

allows_children(object)[source]

Returns whether this object can have children.

append_child(object, child)[source]

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)[source]

Returns whether a given object is droppable on the node.

can_auto_close(object)[source]

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

can_auto_open(object)[source]

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

can_copy(object)[source]

Returns whether the object’s children can be copied.

can_delete(object)[source]

Returns whether the object’s children can be deleted.

can_delete_me(object)[source]

Returns whether the object can be deleted.

can_insert(object)[source]

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

can_rename(object)[source]

Returns whether the object’s children can be renamed.

can_rename_me(object)[source]

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)[source]

Handles an object being clicked.

column_formatters = List(Union(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)[source]

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)[source]

Handles an object being double-clicked.

delete = Bool(True)

Can the object’s children be deleted?

delete_child(object, index)[source]

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)[source]

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)[source]

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

get_background(object)[source]
get_children(object)[source]

Gets the object’s children.

get_children_id(object)[source]

Gets the object’s children identifier.

get_column_labels(object)[source]

Get the labels for any columns that have been defined.

get_drag_object(object)[source]

Returns a draggable version of a specified object.

get_foreground(object)[source]
get_icon(object, is_expanded)[source]

Returns the icon for a specified object.

get_icon_path(object)[source]

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

get_label(object)[source]

Gets the label to display for a specified object.

get_menu(object)[source]

Returns the right-click context menu for an object.

get_name(object)[source]

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

get_renderer(object, column=0)[source]

Return the renderer for the object and column.

get_tooltip(object)[source]

Gets the tooltip to display for a specified object.

get_view(object)[source]

Gets the view to use when editing an object.

has_children(object)[source]

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)[source]

Inserts a child into the object’s children.

is_addable(klass)[source]

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

is_node_for(object)[source]

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(observe="node_for")

Tuple of object classes that the node applies to

node_for_interface = Property(observe="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)[source]

Handles an object being selected.

set_label(object, label)[source]

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)[source]

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

when_children_replaced(object, listener, remove)[source]

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

when_column_labels_change(object, listener, remove)[source]

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)[source]

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

class traitsui.tree_node.TreeNodeObject[source]

Bases: HasPrivateTraits

Represents the object that corresponds to a tree node.

tno_activated(node)[source]

Handles an object being activated.

tno_allows_children(node)[source]

Returns whether this object allows children.

tno_append_child(node, child)[source]

Appends a child to the object’s children.

tno_can_add(node, add_object)[source]

Returns whether a given object is droppable on the node.

tno_can_auto_close(node)[source]

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

tno_can_auto_open(node)[source]

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

tno_can_copy(node)[source]

Returns whether the object’s children can be copied.

tno_can_delete(node)[source]

Returns whether the object’s children can be deleted.

tno_can_delete_me(node)[source]

Returns whether the object can be deleted.

tno_can_insert(node)[source]

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

tno_can_rename(node)[source]

Returns whether the object’s children can be renamed.

tno_can_rename_me(node)[source]

Returns whether the object can be renamed.

tno_click(node)[source]

Handles an object being clicked.

tno_confirm_delete(node)[source]

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)[source]

Handles an object being double-clicked.

tno_delete_child(node, index)[source]

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

tno_drop_object(node, dropped_object)[source]

Returns a droppable version of a specified object.

tno_get_add(node)[source]

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

tno_get_children(node)[source]

Gets the object’s children.

tno_get_children_id(node)[source]

Gets the object’s children identifier.

tno_get_drag_object(node)[source]

Returns a draggable version of a specified object.

tno_get_icon(node, is_expanded)[source]

Returns the icon for a specified object.

tno_get_icon_path(node)[source]

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

tno_get_label(node)[source]

Gets the label to display for a specified object.

tno_get_menu(node)[source]

Returns the right-click context menu for an object.

tno_get_name(node)[source]

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

tno_get_tooltip(node)[source]

Gets the tooltip to display for a specified object.

tno_get_view(node)[source]

Gets the view to use when editing an object.

tno_has_children(node)[source]

Returns whether this object has children.

tno_insert_child(node, index, child)[source]

Inserts a child into the object’s children.

tno_is_node_for(node)[source]

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

tno_select(node)[source]

Handles an object being selected.

tno_set_label(node, label)[source]

Sets the label for a specified object.

tno_when_children_changed(node, listener, remove)[source]

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

tno_when_children_replaced(node, listener, remove)[source]

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

tno_when_label_changed(node, listener, remove)[source]

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