Table Of Contents

Previous topic

TranslationsLoader

Next topic

TreeEvent

This Page

phoenix_title TreeCtrl

A tree control presents information as a hierarchy, with items that may be expanded to show further items.

Items in a tree control are referenced by TreeItemId handles, which may be tested for validity by calling TreeItemId.IsOk .

A similar control with a fully native implementation for GTK+ and OS X as well is DataViewTreeCtrl.

To intercept events from a tree control, use the event table macros described in TreeEvent.

styles Window Styles

This class supports the following styles:

  • TR_EDIT_LABELS: Use this style if you wish the user to be able to edit labels in the tree control.
  • TR_NO_BUTTONS: For convenience to document that no buttons are to be drawn.
  • TR_HAS_BUTTONS: Use this style to show + and - buttons to the left of parent items.
  • TR_TWIST_BUTTONS: Selects alternative style of +/ - buttons and shows rotating (“twisting”) arrows instead. Currently this style is only implemented under Microsoft Windows Vista and later Windows versions and is ignored under the other platforms. Notice that under Vista this style results in the same appearance as used by the tree control in Explorer and other built-in programs and so using it may be preferable to the default style.
  • TR_NO_LINES: Use this style to hide vertical level connectors.
  • TR_FULL_ROW_HIGHLIGHT: Use this style to have the background colour and the selection highlight extend over the entire horizontal row of the tree control window. (This flag is ignored under Windows unless you specify TR_NO_LINES as well.)
  • TR_LINES_AT_ROOT: Use this style to show lines between root nodes. Only applicable if TR_HIDE_ROOT is set and TR_NO_LINES is not set.
  • TR_HIDE_ROOT: Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes.
  • TR_ROW_LINES: Use this style to draw a contrasting border between displayed rows.
  • TR_HAS_VARIABLE_ROW_HEIGHT: Use this style to cause row heights to be just big enough to fit the content. If not set, all rows use the largest row height. The default is that this flag is unset. Generic only.
  • TR_SINGLE: For convenience to document that only one item may be selected at a time. Selecting another item causes the current selection, if any, to be deselected. This is the default.
  • TR_MULTIPLE: Use this style to allow a range of items to be selected. If a second range is selected, the current range, if any, is deselected.
  • TR_DEFAULT_STYLE: The set of flags that are closest to the defaults for the native control for a particular toolkit.

events Events Emitted by this Class

Handlers bound for the following event types will receive a TreeEvent parameter.

  • EVT_TREE_BEGIN_DRAG: Begin dragging with the left mouse button. If you want to enable left-dragging you need to intercept this event and explicitly call TreeEvent.Allow , as it’s vetoed by default. Processes a wxEVT_COMMAND_TREE_BEGIN_DRAG event type.
  • EVT_TREE_BEGIN_RDRAG: Begin dragging with the right mouse button. If you want to enable right-dragging you need to intercept this event and explicitly call TreeEvent.Allow , as it’s vetoed by default. Processes a wxEVT_COMMAND_TREE_BEGIN_RDRAG event type.
  • EVT_TREE_END_DRAG: End dragging with the left or right mouse button. Processes a wxEVT_COMMAND_TREE_END_DRAG event type.
  • EVT_TREE_BEGIN_LABEL_EDIT: Begin editing a label. This can be prevented by calling Veto(). Processes a wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT event type.
  • EVT_TREE_END_LABEL_EDIT: Finish editing a label. This can be prevented by calling Veto(). Processes a wxEVT_COMMAND_TREE_END_LABEL_EDIT event type.
  • EVT_TREE_DELETE_ITEM: An item was deleted. Processes a wxEVT_COMMAND_TREE_DELETE_ITEM event type.
  • EVT_TREE_GET_INFO: Request information from the application. Processes a wxEVT_COMMAND_TREE_GET_INFO event type.
  • EVT_TREE_SET_INFO: Information is being supplied. Processes a wxEVT_COMMAND_TREE_SET_INFO event type.
  • EVT_TREE_ITEM_ACTIVATED: The item has been activated, i.e. chosen by float clicking it with mouse or from keyboard. Processes a wxEVT_COMMAND_TREE_ITEM_ACTIVATED event type.
  • EVT_TREE_ITEM_COLLAPSED: The item has been collapsed. Processes a wxEVT_COMMAND_TREE_ITEM_COLLAPSED event type.
  • EVT_TREE_ITEM_COLLAPSING: The item is being collapsed. This can be prevented by calling Veto(). Processes a wxEVT_COMMAND_TREE_ITEM_COLLAPSING event type.
  • EVT_TREE_ITEM_EXPANDED: The item has been expanded. Processes a wxEVT_COMMAND_TREE_ITEM_EXPANDED event type.
  • EVT_TREE_ITEM_EXPANDING: The item is being expanded. This can be prevented by calling Veto(). Processes a wxEVT_COMMAND_TREE_ITEM_EXPANDING event type.
  • EVT_TREE_ITEM_RIGHT_CLICK: The user has clicked the item with the right mouse button. Processes a wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK event type.
  • EVT_TREE_ITEM_MIDDLE_CLICK: The user has clicked the item with the middle mouse button. This is only supported by the generic control. Processes a wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK event type.
  • EVT_TREE_SEL_CHANGED: Selection has changed. Processes a wxEVT_COMMAND_TREE_SEL_CHANGED event type.
  • EVT_TREE_SEL_CHANGING: Selection is changing. This can be prevented by calling Veto(). Processes a wxEVT_COMMAND_TREE_SEL_CHANGING event type.
  • EVT_TREE_KEY_DOWN: A key has been pressed. Processes a wxEVT_COMMAND_TREE_KEY_DOWN event type.
  • EVT_TREE_ITEM_GETTOOLTIP: The opportunity to set the item tooltip is being given to the application (call TreeEvent.SetToolTip ). Windows only. Processes a wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP event type.
  • EVT_TREE_ITEM_MENU: The context menu for the selected item has been requested, either by a right click or by using the menu key. Processes a wxEVT_COMMAND_TREE_ITEM_MENU event type.
  • EVT_TREE_STATE_IMAGE_CLICK: The state image has been clicked. Windows only. Processes a wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK event type.

See also

Window Styles.

Win32 notes:

TreeCtrl class uses the standard common treeview control under Win32 implemented in the system library comctl32.dll. Some versions of this library are known to have bugs with handling the tree control colours: the usual symptom is that the expanded items leave black (or otherwise incorrectly coloured) background behind them, especially for the controls using non-default background colour. The recommended solution is to upgrade the comctl32.dll to a newer version: see http://www.microsoft.com/downloads/details.aspx?familyid=cb2cf3a2-8025-4e8f-8511-9b476a8d35d2

See also

DataViewTreeCtrl, TreeEvent, TreeItemData, TreeCtrl Overview, ListBox, ListCtrl, ImageList


class_hierarchy Inheritance Diagram

Inheritance diagram for class TreeCtrl

Inheritance diagram of TreeCtrl


appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


method_summary Methods Summary

__init__ Default Constructor.
AddRoot Adds the root node to the tree, returning the new item.
AppendItem Appends an item to the end of the branch identified by parent, return a new item id.
AssignImageList Sets the normal image list.
AssignStateImageList Sets the state image list.
ClearFocusedItem Clears the currently focused item.
Collapse Collapses the given item.
CollapseAll Collapses the root item.
CollapseAllChildren Collapses this item and all of its children, recursively.
CollapseAndReset Collapses the given item and removes all children.
Create Creates the tree control.
Delete Deletes the specified item.
DeleteAllItems Deletes all items in the control.
DeleteChildren Deletes all children of the given item (but not the item itself).
EditLabel Starts editing the label of the given item.
EndEditLabel Ends label editing.
EnsureVisible Scrolls and/or expands items to ensure that the given item is visible.
Expand Expands the given item.
ExpandAll Expands all items in the tree.
ExpandAllChildren Expands the given item and all its children recursively.
GetChildrenCount Returns the number of items in the branch.
GetCount Returns the number of items in the control.
GetEditControl Returns the edit control being currently used to edit a label.
GetFirstChild Returns the first child; call GetNextChild for the next child.
GetFirstVisibleItem Returns the first visible item.
GetFocusedItem Returns the item last clicked or otherwise selected.
GetImageList Returns the normal image list.
GetIndent Returns the current tree control indentation.
GetItemBackgroundColour Returns the background colour of the item.
GetItemData Returns the tree item data associated with the item.
GetItemFont Returns the font of the item label.
GetItemImage Gets the specified item image.
GetItemParent Returns the item’s parent.
GetItemState Gets the specified item state.
GetItemText Returns the item label.
GetItemTextColour Returns the colour of the item label.
GetLastChild Returns the last child of the item (or an invalid tree item if this item has no children).
GetNextChild Returns the next child; call GetFirstChild for the first child.
GetNextSibling Returns the next sibling of the specified item; call GetPrevSibling for the previous sibling.
GetNextVisible Returns the next visible item or an invalid item if this item is the last visible one.
GetPrevSibling Returns the previous sibling of the specified item; call GetNextSibling for the next sibling.
GetPrevVisible Returns the previous visible item or an invalid item if this item is the first visible one.
GetQuickBestSize Returns True if the control will use a quick calculation for the best size, looking only at the first and last items.
GetRootItem Returns the root item for the tree control.
GetSelection Returns the selection, or an invalid item if there is no selection.
GetStateImageList Returns the state image list (from which application-defined state images are taken).
HitTest Calculates which (if any) item is under the given point, returning the tree item id at this point plus extra information flags.
InsertItem Inserts an item after a given one (previous).
IsBold Returns True if the given item is in bold state.
IsEmpty Returns True if the control is empty (i.e.
IsExpanded Returns True if the item is expanded (only makes sense if it has children).
IsSelected Returns True if the item is selected.
IsVisible Returns True if the item is visible on the screen.
ItemHasChildren Returns True if the item has children.
OnCompareItems Override this function in the derived class to change the sort order of the items in the tree control.
PrependItem Appends an item as the first child of parent, return a new item id.
ScrollTo Scrolls the specified item into view.
SelectChildren Select all the immediate children of the given parent.
SelectItem Selects the given item.
SetFocusedItem Sets the currently focused item.
SetImageList Sets the normal image list.
SetIndent Sets the indentation for the tree control.
SetItemBackgroundColour Sets the colour of the item’s background.
SetItemBold Makes item appear in bold font if bold parameter is True or resets it to the normal state.
SetItemData Sets the item client data.
SetItemDropHighlight Gives the item the visual feedback for Drag’n’Drop actions, which is useful if something is dragged from the outside onto the tree control (as opposed to a DnD operation within the tree control, which already is implemented internally).
SetItemFont Sets the item’s font.
SetItemHasChildren Force appearance of the button next to the item.
SetItemImage Sets the specified item’s image.
SetItemState Sets the specified item state.
SetItemText Sets the item label.
SetItemTextColour Sets the colour of the item’s text.
SetQuickBestSize If True is passed, specifies that the control will use a quick calculation for the best size, looking only at the first and last items.
SetStateImageList Sets the state image list (from which application-defined state images are taken).
SetWindowStyle Sets the mode flags associated with the display of the tree control.
SortChildren Sorts the children of the given item using OnCompareItems .
Toggle Toggles the given item between collapsed and expanded states.
ToggleItemSelection Toggles the given item between selected and unselected states.
Unselect Removes the selection from the currently selected item (if any).
UnselectAll This function either behaves the same as Unselect if the control doesn’t have TR_MULTIPLE style, or removes the selection from all items if it does have this style.
UnselectItem Unselects the given item.

api Class API



class TreeCtrl(Control)

A tree control presents information as a hierarchy, with items that may be expanded to show further items.

Possible constructors:

TreeCtrl()

TreeCtrl(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
         style=TR_DEFAULT_STYLE, validator=DefaultValidator,
         name=TreeCtrlNameStr)

Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default Constructor.



__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=TR_DEFAULT_STYLE, validator=DefaultValidator, name=TreeCtrlNameStr)

Constructor, creating and showing a tree control.

Parameters:
  • parent (Window) – Parent window. Must not be None.
  • id (int) – Window identifier. The value ID_ANY indicates a default value.
  • pos (Point) – Window position. If DefaultPosition is specified then a default position is chosen.
  • size (Size) – Window size. If DefaultSize is specified then the window is sized appropriately.
  • style (long) – Window style. See TreeCtrl.
  • validator (Validator) – Window validator.
  • name (string) – Window name.

See also

Create , Validator





AddRoot(self, text, image=-1, selImage=-1, data=None)

Adds the root node to the tree, returning the new item.

The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image -1 and selImage is -1, the same image is used for both selected and unselected items.

Parameters:
  • text (string) –
  • image (int) –
  • selImage (int) –
  • data (TreeItemData) –
Return type:

TreeItemId



AppendItem(self, parent, text, image=-1, selImage=-1, data=None)

Appends an item to the end of the branch identified by parent, return a new item id.

The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image -1 and selImage is -1, the same image is used for both selected and unselected items.

Parameters:
  • parent (TreeItemId) –
  • text (string) –
  • image (int) –
  • selImage (int) –
  • data (TreeItemData) –
Return type:

TreeItemId



AssignImageList(self, imageList)

Sets the normal image list.

The image list assigned with this method will be automatically deleted by TreeCtrl as appropriate (i.e. it takes ownership of the list).

Parameters:imageList (ImageList) –

See also

SetImageList .



AssignStateImageList(self, imageList)

Sets the state image list.

Image list assigned with this method will be automatically deleted by TreeCtrl as appropriate (i.e. it takes ownership of the list).

Parameters:imageList (ImageList) –

See also

SetStateImageList .



ClearFocusedItem(self)

Clears the currently focused item.

New in version 2.9.1.



Collapse(self, item)

Collapses the given item.

Parameters:item (TreeItemId) –


CollapseAll(self)

Collapses the root item.

See also

ExpandAll



CollapseAllChildren(self, item)

Collapses this item and all of its children, recursively.

Parameters:item (TreeItemId) –


CollapseAndReset(self, item)

Collapses the given item and removes all children.

Parameters:item (TreeItemId) –


Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=TR_DEFAULT_STYLE, validator=DefaultValidator, name=TreeCtrlNameStr)

Creates the tree control.

See TreeCtrl.__init__ for further details.

Parameters:
  • parent (Window) –
  • id (int) –
  • pos (Point) –
  • size (Size) –
  • style (long) –
  • validator (Validator) –
  • name (string) –
Return type:

bool



Delete(self, item)

Deletes the specified item.

A EVT_TREE_DELETE_ITEM event will be generated.

This function may cause a subsequent call to GetNextChild to fail.

Parameters:item (TreeItemId) –


DeleteAllItems(self)

Deletes all items in the control.

Note that this may not generate EVT_TREE_DELETE_ITEM events under some Windows versions although normally such event is generated for each removed item.



DeleteChildren(self, item)

Deletes all children of the given item (but not the item itself).

Note that this will not generate any events unlike Delete method.

If you have called SetItemHasChildren , you may need to call it again since DeleteChildren does not automatically clear the setting.

Parameters:item (TreeItemId) –


EditLabel(self, item)

Starts editing the label of the given item.

This function generates a EVT_TREE_BEGIN_LABEL_EDIT event which can be vetoed so that no text control will appear for in-place editing.

If the user changed the label (i.e. s/he does not press ESC or leave the text control without changes, a EVT_TREE_END_LABEL_EDIT event will be sent which can be vetoed as well.

Parameters:item (TreeItemId) –
Return type: TextCtrl


EndEditLabel(self, item, discardChanges=False)

Ends label editing.

If cancelEdit is True, the edit will be cancelled.

Parameters:

Note

This function is currently supported under Windows only.

See also

EditLabel



EnsureVisible(self, item)

Scrolls and/or expands items to ensure that the given item is visible.

Parameters:item (TreeItemId) –


Expand(self, item)

Expands the given item.

Parameters:item (TreeItemId) –


ExpandAll(self)

Expands all items in the tree.



ExpandAllChildren(self, item)

Expands the given item and all its children recursively.

Parameters:item (TreeItemId) –


GetChildrenCount(self, item, recursively=True)

Returns the number of items in the branch.

If recursively is True, returns the total number of descendants, otherwise only one level of children is counted.

Parameters:
Return type:

int



GetCount(self)

Returns the number of items in the control.

Return type:int


GetEditControl(self)

Returns the edit control being currently used to edit a label.

Returns None if no label is being edited.

Return type: TextCtrl

Note

This is currently only implemented for wxMSW.



GetFirstChild(self, item)

Returns the first child; call GetNextChild for the next child.

For this enumeration function you must pass in a ‘cookie’ parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to GetFirstChild and GetNextChild should be the same variable.

Returns an invalid tree item (i.e. TreeItemId.IsOk returns False) if there are no further children.

Parameters:item (TreeItemId) –
Return type:tuple
Returns:( TreeItemId, cookie )


GetFirstVisibleItem(self)

Returns the first visible item.

Return type: TreeItemId


GetFocusedItem(self)

Returns the item last clicked or otherwise selected.

Unlike GetSelection , it can be used whether or not the control has the TR_MULTIPLE style.

Return type: TreeItemId

New in version 2.9.1.



GetImageList(self)

Returns the normal image list.

Return type: ImageList


GetIndent(self)

Returns the current tree control indentation.

Return type:int


GetItemBackgroundColour(self, item)

Returns the background colour of the item.

Parameters:item (TreeItemId) –
Return type: Colour


GetItemData(self, item)

Returns the tree item data associated with the item.

  • GetPlData(item): returns the Perl data associated with the Wx.TreeItemData. It is just the same as tree->GetItemData(item)->GetData().
Parameters:item (TreeItemId) –
Return type:TreeItemData

See also

TreeItemData



GetItemFont(self, item)

Returns the font of the item label.

Parameters:item (TreeItemId) –
Return type: Font


GetItemImage(self, item, which=TreeItemIcon_Normal)

Gets the specified item image.

The value of which may be:

  • TreeItemIcon_Normal : to get the normal item image.
  • TreeItemIcon_Selected : to get the selected item image (i.e. the image which is shown when the item is currently selected).
  • TreeItemIcon_Expanded : to get the expanded image (this only makes sense for items which have children - then this image is shown when the item is expanded and the normal image is shown when it is collapsed).
  • TreeItemIcon_SelectedExpanded : to get the selected expanded image (which is shown when an expanded item is currently selected).
Parameters:
Return type:

int



GetItemParent(self, item)

Returns the item’s parent.

Parameters:item (TreeItemId) –
Return type: TreeItemId


GetItemState(self, item)

Gets the specified item state.

Parameters:item (TreeItemId) –
Return type:int


GetItemText(self, item)

Returns the item label.

Parameters:item (TreeItemId) –
Return type:string


GetItemTextColour(self, item)

Returns the colour of the item label.

Parameters:item (TreeItemId) –
Return type: Colour


GetLastChild(self, item)

Returns the last child of the item (or an invalid tree item if this item has no children).

Parameters:item (TreeItemId) –
Return type: TreeItemId


GetNextChild(self, item, cookie)

Returns the next child; call GetFirstChild for the first child.

For this enumeration function you must pass in a ‘cookie’ parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to GetFirstChild and GetNextChild should be the same.

Returns an invalid tree item if there are no further children.

Parameters:
  • item (TreeItemId) –
  • cookie (TreeItemIdValue) –
Return type:

TreeItemId

See also

GetFirstChild



GetNextSibling(self, item)

Returns the next sibling of the specified item; call GetPrevSibling for the previous sibling.

Returns an invalid tree item if there are no further siblings.

Parameters:item (TreeItemId) –
Return type: TreeItemId

See also

GetPrevSibling



GetNextVisible(self, item)

Returns the next visible item or an invalid item if this item is the last visible one.

Parameters:item (TreeItemId) –
Return type: TreeItemId

Note

The item itself must be visible.



GetPrevSibling(self, item)

Returns the previous sibling of the specified item; call GetNextSibling for the next sibling.

Returns an invalid tree item if there are no further children.

Parameters:item (TreeItemId) –
Return type: TreeItemId

See also

GetNextSibling



GetPrevVisible(self, item)

Returns the previous visible item or an invalid item if this item is the first visible one.

Parameters:item (TreeItemId) –
Return type: TreeItemId

Note

The item itself must be visible.



GetQuickBestSize(self)

Returns True if the control will use a quick calculation for the best size, looking only at the first and last items.

The default is False.

Return type:bool

See also

SetQuickBestSize



GetRootItem(self)

Returns the root item for the tree control.

Return type: TreeItemId


GetSelection(self)

Returns the selection, or an invalid item if there is no selection.

This function only works with the controls without TR_MULTIPLE style, use GetSelections for the controls which do have this style or, if a single item is wanted, use GetFocusedItem .

Return type: TreeItemId


GetStateImageList(self)

Returns the state image list (from which application-defined state images are taken).

Return type: ImageList


HitTest(self, point, flags)

Calculates which (if any) item is under the given point, returning the tree item id at this point plus extra information flags.

flags is a bitlist of the following:

  • TREE_HITTEST_ABOVE: Above the client area.
  • TREE_HITTEST_BELOW: Below the client area.
  • TREE_HITTEST_NOWHERE: In the client area but below the last item.
  • TREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
  • TREE_HITTEST_ONITEMICON: On the bitmap associated with an item.
  • TREE_HITTEST_ONITEMINDENT: In the indentation associated with an item.
  • TREE_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
  • TREE_HITTEST_ONITEMRIGHT: In the area to the right of an item.
  • TREE_HITTEST_ONITEMSTATEICON: On the state icon for a tree view item that is in a user-defined state.
  • TREE_HITTEST_TOLEFT: To the right of the client area.
  • TREE_HITTEST_TORIGHT: To the left of the client area.
Parameters:
  • point (Point) –
  • flags (int) –
Return type:

TreeItemId



InsertItem(self, *args, **kw)

overload Overloaded Implementations:



InsertItem (self, parent, previous, text, image=-1, selImage=-1, data=None)

Inserts an item after a given one (previous).

The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image -1 and selImage is -1, the same image is used for both selected and unselected items.

Parameters:
  • parent (TreeItemId) –
  • previous (TreeItemId) –
  • text (string) –
  • image (int) –
  • selImage (int) –
  • data (TreeItemData) –
Return type:

TreeItemId



InsertItem (self, parent, before, text, image=-1, selImage=-1, data=None)

Inserts an item before one identified by its position (before).

before must be less than the number of children.

The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image -1 and selImage is -1, the same image is used for both selected and unselected items.

Parameters:
  • parent (TreeItemId) –
  • before (int) –
  • text (string) –
  • image (int) –
  • selImage (int) –
  • data (TreeItemData) –
Return type:

TreeItemId





IsBold(self, item)

Returns True if the given item is in bold state.

Parameters:item (TreeItemId) –
Return type:bool

See also

SetItemBold



IsEmpty(self)

Returns True if the control is empty (i.e.

has no items, even no root one).

Return type:bool


IsExpanded(self, item)

Returns True if the item is expanded (only makes sense if it has children).

Parameters:item (TreeItemId) –
Return type:bool


IsSelected(self, item)

Returns True if the item is selected.

Parameters:item (TreeItemId) –
Return type:bool


IsVisible(self, item)

Returns True if the item is visible on the screen.

Parameters:item (TreeItemId) –
Return type:bool


ItemHasChildren(self, item)

Returns True if the item has children.

Parameters:item (TreeItemId) –
Return type:bool


OnCompareItems(self, item1, item2)

Override this function in the derived class to change the sort order of the items in the tree control.

The function should return a negative, zero or positive value if the first item is less than, equal to or greater than the second one.

Please note that you must use RTTI macros DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS if you override this function because otherwise the base class considers that it is not overridden and uses the default comparison, i.e. sorts the items alphabetically, which allows it optimize away the calls to the virtual function completely.

Parameters:
Return type:

int

See also

SortChildren



PrependItem(self, parent, text, image=-1, selImage=-1, data=None)

Appends an item as the first child of parent, return a new item id.

The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image -1 and selImage is -1, the same image is used for both selected and unselected items.

Parameters:
  • parent (TreeItemId) –
  • text (string) –
  • image (int) –
  • selImage (int) –
  • data (TreeItemData) –
Return type:

TreeItemId



ScrollTo(self, item)

Scrolls the specified item into view.

Parameters:item (TreeItemId) –


SelectChildren(self, parent)

Select all the immediate children of the given parent.

This function can be used with multiselection controls only.

Parameters:parent (TreeItemId) –

New in version 2.9.1.



SelectItem(self, item, select=True)

Selects the given item.

In multiple selection controls, can be also used to deselect a currently selected item if the value of select is False.

Notice that calling this method will generate wxEVT_COMMAND_TREE_SEL_CHANGING and wxEVT_COMMAND_TREE_SEL_CHANGED events and that the change could be vetoed by the former event handler.

Parameters:


SetFocusedItem(self, item)

Sets the currently focused item.

Parameters:item (TreeItemId) – The item to make the current one. It must be valid.

New in version 2.9.1.



SetImageList(self, imageList)

Sets the normal image list.

The image list assigned with this method will not be deleted by TreeCtrl‘s destructor, you must delete it yourself.

Parameters:imageList (ImageList) –

See also

AssignImageList .



SetIndent(self, indent)

Sets the indentation for the tree control.

Parameters:indent (int) –


SetItemBackgroundColour(self, item, col)

Sets the colour of the item’s background.

Parameters:


SetItemBold(self, item, bold=True)

Makes item appear in bold font if bold parameter is True or resets it to the normal state.

Parameters:

See also

IsBold



SetItemData(self, item, data)

Sets the item client data.

Notice that the client data previously associated with the item (if any) is not freed by this function and so calling this function multiple times for the same item will result in memory leaks unless you delete the old item data pointer yourself.

  • SetPlData(item, data): sets the Perl data associated with the Wx::TreeItemData . It is just the same as tree->GetItemData(item)->SetData(data).
Parameters:


SetItemDropHighlight(self, item, highlight=True)

Gives the item the visual feedback for Drag’n’Drop actions, which is useful if something is dragged from the outside onto the tree control (as opposed to a DnD operation within the tree control, which already is implemented internally).

Parameters:


SetItemFont(self, item, font)

Sets the item’s font.

All items in the tree should have the same height to avoid text clipping, so the fonts height should be the same for all of them, although font attributes may vary.

Parameters:

See also

SetItemBold



SetItemHasChildren(self, item, hasChildren=True)

Force appearance of the button next to the item.

This is useful to allow the user to expand the items which don’t have any children now, but instead adding them only when needed, thus minimizing memory usage and loading time.

Parameters:


SetItemImage(self, item, image, which=TreeItemIcon_Normal)

Sets the specified item’s image.

See GetItemImage for the description of the which parameter.

Parameters:


SetItemState(self, item, state)

Sets the specified item state.

The value of state may be:

  • TREE_ITEMSTATE_NONE: to disable the item state (the state image will be not displayed).
  • TREE_ITEMSTATE_NEXT: to set the next item state.
  • TREE_ITEMSTATE_PREV: to set the previous item state.
Parameters:


SetItemText(self, item, text)

Sets the item label.

Parameters:


SetItemTextColour(self, item, col)

Sets the colour of the item’s text.

Parameters:


SetQuickBestSize(self, quickBestSize)

If True is passed, specifies that the control will use a quick calculation for the best size, looking only at the first and last items.

Otherwise, it will look at all items. The default is False.

Parameters:quickBestSize (bool) –

See also

GetQuickBestSize



SetStateImageList(self, imageList)

Sets the state image list (from which application-defined state images are taken).

Image list assigned with this method will not be deleted by TreeCtrl‘s destructor, you must delete it yourself.

Parameters:imageList (ImageList) –


SetWindowStyle(self, styles)

Sets the mode flags associated with the display of the tree control.

The new mode takes effect immediately.

Parameters:styles (long) –

Note

Generic only; MSW ignores changes.



SortChildren(self, item)

Sorts the children of the given item using OnCompareItems .

You should override that method to change the sort order (the default is ascending case-sensitive alphabetical order).

Parameters:item (TreeItemId) –

See also

TreeItemData, OnCompareItems



Toggle(self, item)

Toggles the given item between collapsed and expanded states.

Parameters:item (TreeItemId) –


ToggleItemSelection(self, item)

Toggles the given item between selected and unselected states.

For multiselection controls only.

Parameters:item (TreeItemId) –


Unselect(self)

Removes the selection from the currently selected item (if any).



UnselectAll(self)

This function either behaves the same as Unselect if the control doesn’t have TR_MULTIPLE style, or removes the selection from all items if it does have this style.



UnselectItem(self, item)

Unselects the given item.

This works in multiselection controls only.

Parameters:item (TreeItemId) –

Properties



BoundingRect

See GetBoundingRect



Count

See GetCount



EditControl

See GetEditControl



FirstVisibleItem

See GetFirstVisibleItem



FocusedItem

See GetFocusedItem and SetFocusedItem



ImageList

See GetImageList and SetImageList



Indent

See GetIndent and SetIndent



QuickBestSize

See GetQuickBestSize and SetQuickBestSize



RootItem

See GetRootItem



Selection

See GetSelection



Selections

See GetSelections



StateImageList

See GetStateImageList and SetStateImageList