exopy.utils.widgets.tree_nodes module

Declarative node for tree node generation.

class exopy.utils.widgets.tree_nodes.TreeNode(parent=None, **kwargs)[source]

Bases: enaml.core.declarative.Declarative

Represents a tree node.

This declaration is used to help the system determine how to extract informations from the underlying object to populate the node.

Note that a Menu can be contributed as a child and will be used when right clicking a node. It will be passed a ‘context’ describing the node being right-clicked.

The context will be a dictionary with the following keys : - ‘copyable’: bool, can the node be copied - ‘cutable’: bool, can the node be cut - ‘pasteable’: bool, can node be pasted here - ‘renamable’: bool, can the node be renamed - ‘deletable’: bool, can the node be deleted - ‘not_root’: bool, is the node the root node of the tree - ‘data’: tuple, (tree, TreeNode instance, object, id of the node)

node_for

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

label

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

tooltip

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

children_member

Name of the member containing children (if ‘’, the node is a leaf).

children_changed

Name of the signal use to notify changes to the children. The payload of the signal should be a ContainerChange instance.

add

List of object classes than can be added or copied

move

List of object classes that can be moved

name

Name to use for a new instance

rename

Can the object’s children be renamed?

rename_me

Can the object be renamed?

copy

Can the object’s children be copied?

delete

Can the object’s children be deleted?

delete_me

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

insert

Can children be inserted (vs. appended)?

auto_open

Should tree nodes be automatically opened (expanded)?

auto_close

Automatically close sibling tree nodes?

node_for_class

Tuple of object classes that the node applies to

icon_item

Name of leaf item icon

icon_group

Name of group item icon

icon_open

Name of opened group item icon

icon_path

Resource path used to locate the node icon

background

Selector or name for background color

foreground

Selector or name for foreground color

insert_child(obj, index, child)[source]

Inserts a child into the object’s children.

confirm_delete(obj)[source]

Checks whether a specified object can be deleted.

Returns

  • - **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).

delete_child(obj, index)[source]

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

move_child(obj, old, new)[source]

Move a child of the object’s children.

enter_rename(obj)[source]

Start renaming an object.

This method can be customized in case the renaming operation should not occur directly on the label.

Parameters

obj – Refrence to the object the tree node being renamed is representing.

Returns

name – String on which to perform the renaming.

Return type

unicode

exit_rename(obj, label)[source]

Sets the label for a specified object after a renaming operation.

get_label(obj)[source]

Gets the label to display for a specified object.

initialize()[source]

Collect the Menu provided as a child.

allows_children(obj)[source]

Returns whether this object can have children.

has_children(obj)[source]

Returns whether the object has children.

get_children(obj)[source]

Gets the object’s children.

get_children_id(obj)[source]

Gets the object’s children identifier.

append_child(obj, child)[source]

Appends a child to the object’s children.

get_tooltip(obj)[source]

Gets the tooltip to display for a specified object.

get_icon(obj, is_expanded)[source]

Returns the icon for a specified object.

get_icon_path(obj)[source]

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

get_name(obj)[source]

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

get_menu(context)[source]

Returns the right-click context menu for an object.

get_background(obj)[source]

Returns the background color for the item.

get_foreground(obj)[source]

Returns the foreground color for the item.

can_rename(obj)[source]

Returns whether the object’s children can be renamed.

can_rename_me(obj)[source]

Returns whether the object can be renamed.

can_copy(obj)[source]

Returns whether the object’s children can be copied.

can_delete(obj)[source]

Returns whether the object’s children can be deleted.

can_delete_me(obj)[source]

Returns whether the object can be deleted.

can_insert(obj)[source]

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

can_auto_open(obj)[source]

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

can_auto_close(obj)[source]

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

is_node_for(obj)[source]

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

can_add(obj, add_object)[source]

Returns whether a given object is droppable on the node.

get_add(obj)[source]

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

get_drag_object(obj)[source]

Returns a draggable version of a specified object.

drop_object(obj, dropped_object)[source]

Returns a droppable version of a specified object.

select(obj)[source]

Handles an object being selected.

is_addable(klass)[source]

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

when_label_changed(obj, listener, remove)[source]

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