*********** wx.TreeCtrl *********** Inheritance diagram for `wx.TreeCtrl`: | .. inheritance-diagram:: wx.TreeCtrl | Description =========== 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 `wx.TreeItemId `_ handles, which may be tested for validity by calling `wx.TreeItemId.IsOk `_. To intercept events from a tree control, use the event table macros described in `wx.TreeEvent <../Events/wx.TreeEvent.html>`_. .. note:: **Win32 note:** `wx.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/release.asp?ReleaseID=11916 `_. .. seealso:: `wx.TreeItemData `_, `wx.ListBox `_, `wx.ListCtrl `_, `wx.ImageList `_, `wx.TreeEvent <../Events/wx.TreeEvent.html>`_ Derived From ^^^^^^^^^^^^^ * `wx.Control `_ * `wx.Window `_ * `wx.EvtHandler `_ * `wx.Object `_ Window Styles ^^^^^^^^^^^^^ ================================================== ================================================== Window Style Description ================================================== ================================================== ``wx.TR_EDIT_LABELS`` Use this style if you wish the user to be able to edit labels in the tree control. ``wx.TR_NO_BUTTONS`` For convenience to document that no buttons are to be drawn. ``wx.TR_HAS_BUTTONS`` Use this style to show + and - buttons to the left of parent items. ``wx.TR_NO_LINES`` Use this style to hide vertical level connectors. ``wx.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 ``wx.TR_NO_LINES`` as well.) ``wx.TR_LINES_AT_ROOT`` Use this style to show lines between root nodes. Only applicable if ``wx.TR_HIDE_ROOT`` is set and ``wx.TR_NO_LINES`` is not set. ``wx.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. ``wx.TR_ROW_LINES`` Use this style to draw a contrasting border between displayed rows. ``wx.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. ``wx.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. ``wx.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. ``wx.TR_EXTENDED`` Use this style to allow disjoint items to be selected. (Only partially implemented; may not work in all cases.) ``wx.TR_DEFAULT_STYLE`` The set of flags that are closest to the defaults for the native control for a particular toolkit. ================================================== ================================================== Event Handling ^^^^^^^^^^^^^^ ================================================== ================================================== Event Name Description ================================================== ================================================== wx.EVT_TREE_BEGIN_DRAG(id, func) Begin dragging with the left mouse button. wx.EVT_TREE_BEGIN_RDRAG(id, func) Begin dragging with the right mouse button. wx.EVT_TREE_END_DRAG(id, func) End dragging with the left or right mouse button. wx.EVT_TREE_BEGIN_LABEL_EDIT(id, func) Begin editing a label. This can be prevented by calling `Veto`. wx.EVT_TREE_END_LABEL_EDIT(id, func) Finish editing a label. This can be prevented by calling `Veto`. wx.EVT_TREE_DELETE_ITEM(id, func) Delete an item. wx.EVT_TREE_GET_INFO(id, func) Request information from the application. wx.EVT_TREE_SET_INFO(id, func) Information is being supplied. wx.EVT_TREE_ITEM_ACTIVATED(id, func) The item has been activated, i.e. chosen by double clicking it with mouse or from keyboard wx.EVT_TREE_ITEM_COLLAPSED(id, func) The item has been collapsed. wx.EVT_TREE_ITEM_COLLAPSING(id, func) The item is being collapsed. This can be prevented by calling `Veto`. wx.EVT_TREE_ITEM_EXPANDED(id, func) The item has been expanded. wx.EVT_TREE_ITEM_EXPANDING(id, func) The item is being expanded. This can be prevented by calling `Veto`. wx.EVT_TREE_ITEM_RIGHT_CLICK(id, func) The user has clicked the item with the right mouse button. wx.EVT_TREE_ITEM_MIDDLE_CLICK(id, func) The user has clicked the item with the middle mouse button. wx.EVT_TREE_SEL_CHANGED(id, func) Selection has changed. wx.EVT_TREE_SEL_CHANGING(id, func) Selection is changing. This can be prevented by calling `Veto`. wx.EVT_TREE_KEY_DOWN(id, func) A key has been pressed. wx.EVT_TREE_ITEM_GETTOOLTIP(id, func) The opportunity to set the item tooltip is being given to the application (call `wx.TreeEvent.SetToolTip <../Events/wx.TreeEvent.html#SetToolTip>`_). Windows only. wx.EVT_TREE_ITEM_MENU(id, func) The context menu for the selected item has been requested, either by a right click or by using the menu key. wx.EVT_TREE_STATE_IMAGE_CLICK(id, func) The state image has been clicked. Windows only. ================================================== ================================================== | Control Appearance ^^^^^^^^^^^^^^^^^^ | .. figure:: ../images/wxWidgets/wxmsw/treectrl.png :alt: wxMSW :figclass: floatleft **wxMSW** .. figure:: ../images/wxWidgets/wxmac/treectrl.png :alt: wxMAC :figclass: floatright **wxMAC** .. figure:: ../images/wxWidgets/wxgtk/treectrl.png :alt: wxGTK :figclass: floatcenter **wxGTK** | Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `AddRoot <#AddRoot>`_ * `AppendItem <#AppendItem>`_ * `AssignImageList <#AssignImageList>`_ * `AssignStateImageList <#AssignStateImageList>`_ * `Collapse <#Collapse>`_ * `CollapseAll <#CollapseAll>`_ * `CollapseAllChildren <#CollapseAllChildren>`_ * `CollapseAndReset <#CollapseAndReset>`_ * `Delete <#Delete>`_ * `DeleteAllItems <#DeleteAllItems>`_ * `DeleteChildren <#DeleteChildren>`_ * `EditLabel <#EditLabel>`_ * `EndEditLabel <#EndEditLabel>`_ * `EnsureVisible <#EnsureVisible>`_ * `Expand <#Expand>`_ * `ExpandAll <#ExpandAll>`_ * `ExpandAllChildren <#ExpandAllChildren>`_ * `GetBoundingRect <#GetBoundingRect>`_ * `GetChildrenCount <#GetChildrenCount>`_ * `GetCount <#GetCount>`_ * `GetEditControl <#GetEditControl>`_ * `GetFirstChild <#GetFirstChild>`_ * `GetFirstVisibleItem <#GetFirstVisibleItem>`_ * `GetImageList <#GetImageList>`_ * `GetIndent <#GetIndent>`_ * `GetItemBackgroundColour <#GetItemBackgroundColour>`_ * `GetItemFont <#GetItemFont>`_ * `GetItemImage <#GetItemImage>`_ * `GetItemParent <#GetItemParent>`_ * `GetItemPyData <#GetItemPyData>`_ * `GetItemText <#GetItemText>`_ * `GetItemTextColour <#GetItemTextColour>`_ * `GetLastChild <#GetLastChild>`_ * `GetNextChild <#GetNextChild>`_ * `GetNextSibling <#GetNextSibling>`_ * `GetNextVisible <#GetNextVisible>`_ * `GetPrevSibling <#GetPrevSibling>`_ * `GetPrevVisible <#GetPrevVisible>`_ * `GetPyData <#GetPyData>`_ * `GetQuickBestSize <#GetQuickBestSize>`_ * `GetRootItem <#GetRootItem>`_ * `GetSelection <#GetSelection>`_ * `GetSelections <#GetSelections>`_ * `GetSpacing <#GetSpacing>`_ * `GetState <#GetState>`_ * `GetStateImageList <#GetStateImageList>`_ * `HitTest <#HitTest>`_ * `InsertItem <#InsertItem>`_ * `InsertItemBefore <#InsertItemBefore>`_ * `IsBold <#IsBold>`_ * `IsEmpty <#IsEmpty>`_ * `IsExpanded <#IsExpanded>`_ * `IsSelected <#IsSelected>`_ * `IsVisible <#IsVisible>`_ * `ItemHasChildren <#ItemHasChildren>`_ * `PrependItem <#PrependItem>`_ * `ScrollTo <#ScrollTo>`_ * `SelectItem <#SelectItem>`_ * `SetImageList <#SetImageList>`_ * `SetIndent <#SetIndent>`_ * `SetItemBackgroundColour <#SetItemBackgroundColour>`_ * `SetItemBold <#SetItemBold>`_ * `SetItemData <#SetItemData>`_ * `SetItemDropHighlight <#SetItemDropHighlight>`_ * `SetItemFont <#SetItemFont>`_ * `SetItemHasChildren <#SetItemHasChildren>`_ * `SetItemImage <#SetItemImage>`_ * `SetItemPyData <#SetItemPyData>`_ * `SetItemText <#SetItemText>`_ * `SetItemTextColour <#SetItemTextColour>`_ * `SetPyData <#SetPyData>`_ * `SetQuickBestSize <#SetQuickBestSize>`_ * `SetSpacing <#SetSpacing>`_ * `SetState <#SetState>`_ * `SetStateImageList <#SetStateImageList>`_ * `SortChildren <#SortChildren>`_ * `Toggle <#Toggle>`_ * `ToggleItemSelection <#ToggleItemSelection>`_ * `Unselect <#Unselect>`_ * `UnselectAll <#UnselectAll>`_ * `UnselectItem <#UnselectItem>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Count <#Count>`_ * `EditControl <#EditControl>`_ * `FirstVisibleItem <#FirstVisibleItem>`_ * `ImageList <#ImageList>`_ * `Indent <#Indent>`_ * `QuickBestSize <#QuickBestSize>`_ * `RootItem <#RootItem>`_ * `Selection <#Selection>`_ * `Selections <#Selections>`_ * `Spacing <#Spacing>`_ * `StateImageList <#StateImageList>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TR_DEFAULT_STYLE, validator=wx.DefaultValidator, name=wx.TreeCtrlNameStr) Constructor, creating and showing a tree control. **Parameters:** * `parent` (`wx.Window `_) * `id` (int) * `pos` (`wx.Point `_) * `size` (`wx.Size `_) * `style` (long) * `validator` (`wx.Validator `_) * `name` (string) | **Returns:** `wx.TreeCtrl `_ -------- .. method:: AddRoot(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` (PyObject) | **Returns:** `wx.TreeItemId `_ -------- .. method:: AppendItem(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` (`wx.TreeItemId `_) * `text` (string) * `image` (int) * `selImage` (int) * `data` (PyObject) | **Returns:** `wx.TreeItemId `_ -------- .. method:: AssignImageList(imageList) Sets the normal image list. Image list assigned with this method will be automatically deleted by `wx.TreeCtrl` as appropriate (i.e. it takes ownership of the list). **Parameters:** * `imageList` (`wx.ImageList `_) .. seealso:: `SetImageList <#SetImageList>`_. -------- .. method:: AssignStateImageList(imageList) Sets the state image list. Image list assigned with this method will be automatically deleted by `wx.TreeCtrl` as appropriate (i.e. it takes ownership of the list). **Parameters:** * `imageList` (`wx.ImageList `_) .. seealso:: `SetStateImageList <#SetStateImageList>`_. -------- .. method:: Collapse(item) Collapses the given item. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: CollapseAll() Collapses the root item. .. seealso:: `ExpandAll <#ExpandAll>`_ -------- .. method:: CollapseAllChildren(item) Collapses this item and all of its children, recursively. **Parameters:** * `item` (`wx.TreeItemId `_) .. seealso:: `ExpandAllChildren <#ExpandAllChildren>`_ -------- .. method:: CollapseAndReset(item) Collapses the given item and removes all children. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: Delete(item) Deletes the specified item. A ``wx.EVT_TREE_DELETE_ITEM`` event will be generated. This function may cause a subsequent call to `GetNextChild <#GetNextChild>`_ to fail. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: DeleteAllItems() Deletes all items in the control. .. note:: Note that this may not generate ``wx.EVT_TREE_DELETE_ITEM`` events under some Windows versions although normally such event is generated for each removed item. -------- .. method:: DeleteChildren(item) Deletes all children of the given item (but not the item itself). If you have called `SetItemHasChildren <#SetItemHasChildren>`_, you may need to call it again since `DeleteChildren` does not automatically clear the setting. **Parameters:** * `item` (`wx.TreeItemId `_) .. note:: Note that this will **not** generate any events unlike `Delete <#Delete>`_ method. -------- .. method:: EditLabel(item) Starts editing the label of the given item. This function generates a ``wx.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 ``wx.EVT_TREE_END_LABEL_EDIT`` event will be sent which can be vetoed as well. **Parameters:** * `item` (`wx.TreeItemId `_) .. seealso:: `EndEditLabel <#EndEditLabel>`_, `wx.TreeEvent <../Events/wx.TreeEvent.html>`_ -------- .. method:: EndEditLabel(cancelEdit) Ends label editing. If `cancelEdit` is ``True``, the edit will be cancelled. **Parameters:** * `cancelEdit` (bool) .. note:: This function is currently supported under Windows only. .. seealso:: `wx.TreeCtrl.EditLabel `_ -------- .. method:: EnsureVisible(item) Scrolls and/or expands items to ensure that the given item is visible. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: Expand(item) Expands the given item. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: ExpandAll() Expands all items in the tree. -------- .. method:: ExpandAllChildren(item) Expands the given item and all its children recursively. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: GetBoundingRect(item, textOnly) Retrieves the rectangle bounding the `item`. If `textOnly` is ``True``, only the rectangle around the item's label will be returned, otherwise the item's image is also taken into account. **Parameters:** * `item` (`wx.TreeItemId `_) * `textOnly` (bool) | **Returns:** `wx.Rect `_ .. note:: Notice that the rectangle coordinates are logical, not physical ones. So, for example, the x coordinate may be negative if the tree has a horizontal scrollbar and its position is not 0. -------- .. method:: GetChildrenCount(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:** * `item` (`wx.TreeItemId `_) * `recursively` (bool) | **Returns:** `int` -------- .. method:: GetCount() Returns the number of items in the control. | **Returns:** `int` -------- .. method:: GetEditControl() Returns the edit control being currently used to edit a label. Returns ``None`` if no label is being edited. | **Returns:** `wx.TextCtrl `_ .. note:: It is currently only implemented for wxMSW. -------- .. method:: GetFirstChild(item) Returns the first child; call `GetNextChild <#GetNextChild>`_ for the next child. Returns an invalid tree item (i.e. `IsOk() `_ returns ``False``) if there are no further children. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ .. seealso:: `GetNextChild <#GetNextChild>`_, `GetNextSibling <#GetNextSibling>`_ -------- .. method:: GetFirstVisibleItem() Returns the first visible item. | **Returns:** `wx.TreeItemId `_ -------- .. method:: GetImageList() Returns the normal image list. | **Returns:** `wx.ImageList `_ -------- .. method:: GetIndent() Returns the current tree control indentation. | **Returns:** `int` -------- .. method:: GetItemBackgroundColour(item) Returns the background colour of the item. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.Colour `_ -------- .. method:: GetItemFont(item) Returns the font of the item. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.Font `_ -------- .. method:: GetItemImage(item, which=wx.TreeItemIcon_Normal) Gets the specified item image. The value of `which` may be: * `wx.TreeItemIcon_Normal` to get the normal item image * `wx.TreeItemIcon_Selected` to get the selected item image (i.e. the image which is shown when the item is currently selected) * `wx.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) * `wx.TreeItemIcon_SelectedExpanded` to get the selected expanded image (which is shown when an expanded item is currently selected) **Parameters:** * `item` (`wx.TreeItemId `_) * `which` (int) | **Returns:** `int` -------- .. method:: GetItemParent(item) Returns the item's parent. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ -------- .. method:: GetItemPyData(item) Returns the tree item data associated with the item. Same as `GetPyData <#GetPyData>`_ **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `PyObject` -------- .. method:: GetItemText(item) Returns the item label. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `string` -------- .. method:: GetItemTextColour(item) Returns the colour of the item label. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.Colour `_ -------- .. method:: GetLastChild(item) Returns the last child of the item (or an invalid tree item if this item has no children). **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ .. seealso:: `GetFirstChild <#GetFirstChild>`_, `GetNextSibling <#GetNextSibling>`_, `GetLastChild <#GetLastChild>`_ -------- .. method:: GetNextChild(item, cookie) Returns the next child; call `GetFirstChild <#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 returned by `GetFirstChild` and passed to `GetNextChild` should be the same. Returns an invalid tree item if there are no further children. **Parameters:** * `item` (`wx.TreeItemId `_) * `cookie` (int) | **Returns:** `wx.TreeItemId `_ .. seealso:: `GetFirstChild <#GetFirstChild>`_ -------- .. method:: GetNextSibling(item) Returns the next sibling of the specified item; call `GetPrevSibling <#GetPrevSibling>`_ for the previous sibling. Returns an invalid tree item if there are no further siblings. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ .. seealso:: `GetPrevSibling <#GetPrevSibling>`_ -------- .. method:: GetNextVisible(item) Returns the next visible item. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ -------- .. method:: GetPrevSibling(item) Returns the previous sibling of the specified item; call `GetNextSibling <#GetNextSibling>`_ for the next sibling. Returns an invalid tree item if there are no further children. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ .. seealso:: `wx.TreeCtrl.GetNextSibling `_ -------- .. method:: GetPrevVisible(item) Returns the previous visible item. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `wx.TreeItemId `_ -------- .. method:: GetPyData(item) Returns the tree item data associated with the item. Same as `GetItemPyData <#GetItemPyData>`_. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `PyObject` -------- .. method:: GetQuickBestSize() 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``. | **Returns:** `bool` .. seealso:: `SetQuickBestSize <#SetQuickBestSize>`_ -------- .. method:: GetRootItem() Returns the root item for the tree control. | **Returns:** `wx.TreeItemId `_ -------- .. method:: GetSelection() Returns the selection, or an invalid item if there is no selection. This function only works with the controls without ``wx.TR_MULTIPLE`` style, use `GetSelections <#GetSelections>`_ for the controls which do have this style. | **Returns:** `wx.TreeItemId `_ -------- .. method:: GetSelections() Returns an array of tree items passed in with the currently selected items. This function can be called only if the control has the ``wx.TR_MULTIPLE`` style. | **Returns:** `list of wx.TreeItemIds` -------- .. method:: GetSpacing() `No docstrings available for this method.` -------- .. method:: GetState(node) | **Parameters:** * `node` (`wx.TreeItemId `_) **Returns:** `int` -------- .. method:: GetStateImageList() Returns the state image list (from which application-defined state images are taken). | **Returns:** `wx.ImageList `_ -------- .. method:: HitTest(pt): 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: =========================================== ========================================== HitTest Flag Description =========================================== ========================================== ``wx.TREE_HITTEST_ABOVE`` Above the client area. ``wx.TREE_HITTEST_BELOW`` Below the client area. ``wx.TREE_HITTEST_NOWHERE`` In the client area but below the last item. ``wx.TREE_HITTEST_ONITEMBUTTON`` On the button associated with an item. ``wx.TREE_HITTEST_ONITEMICON`` On the bitmap associated with an item. ``wx.TREE_HITTEST_ONITEMINDENT`` In the indentation associated with an item. ``wx.TREE_HITTEST_ONITEMLABEL`` On the label (string) associated with an item. ``wx.TREE_HITTEST_ONITEMRIGHT`` In the area to the right of an item. ``wx.TREE_HITTEST_ONITEMSTATEICON`` On the state icon for a tree view item that is in a user-defined state. ``wx.TREE_HITTEST_TOLEFT`` To the right of the client area. ``wx.TREE_HITTEST_TORIGHT`` To the left of the client area. =========================================== ========================================== | **Parameters:** `pt` (`wx.Point `_): The point at which perform the `HitTest` calculations | **Returns:** `(wx.TreeItemId, flags)` -------- .. method:: InsertItem(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` (`wx.TreeItemId `_) * `previous` (`wx.TreeItemId `_) * `text` (string) * `image` (int) * `selImage` (int) * `data` (PyObject) | **Returns:** `wx.TreeItemId `_ -------- .. method:: InsertItemBefore(parent, before, text, image=-1, selImage=-1, data=None) Inserts an item after a given one `before`. 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` (`wx.TreeItemId `_) * `before` (int) * `text` (string) * `image` (int) * `selImage` (int) * `data` (PyObject) | **Returns:** `wx.TreeItemId `_ -------- .. method:: IsBold(item) Returns ``True`` if the given item is in bold state. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `bool` .. seealso:: `SetItemBold <#SetItemBold>`_ -------- .. method:: IsEmpty() Returns ``True`` if the control is empty (i.e. has no items, even no root one). | **Returns:** `bool` -------- .. method:: IsExpanded(item) Returns ``True`` if the item is expanded (only makes sense if it has children). **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `bool` -------- .. method:: IsSelected(item) Returns ``True`` if the item is selected. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `bool` -------- .. method:: IsVisible(item) Returns ``True`` if the item is visible (it might be outside the view, or not expanded). **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `bool` -------- .. method:: ItemHasChildren(item) Returns ``True`` if the item has children. **Parameters:** * `item` (`wx.TreeItemId `_) | **Returns:** `bool` -------- .. method:: PrependItem(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` (`wx.TreeItemId `_) * `text` (string) * `image` (int) * `selImage` (int) * `data` (PyObject) | **Returns:** `wx.TreeItemId `_ -------- .. method:: ScrollTo(item) Scrolls the specified item into view. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: SelectItem(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``. **Parameters:** * `item` (`wx.TreeItemId `_) * `select` (bool) -------- .. method:: SetImageList(imageList) Sets the normal image list. Image list assigned with this method will **not** be deleted by `wx.TreeCtrl` destructor, you must delete it yourself. **Parameters:** * `imageList` (`wx.ImageList `_) .. seealso:: `AssignImageList <#AssignImageList>`_ -------- .. method:: SetIndent(indent) Sets the indentation for the tree control. **Parameters:** * `indent` (int) -------- .. method:: SetItemBackgroundColour(item, col) Sets the colour of the item's background. **Parameters:** * `item` (`wx.TreeItemId `_) * `col` (`wx.Colour `_) -------- .. method:: SetItemBold(item, bold=True) Makes item appear in bold font if `bold` parameter is ``True`` or resets it to the normal state. **Parameters:** * `item` (`wx.TreeItemId `_) * `bold` (bool) .. seealso:: `IsBold <#IsBold>`_ -------- .. method:: SetItemDropHighlight(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:** * `item` (`wx.TreeItemId `_) * `highlight` (bool) -------- .. method:: SetItemFont(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:** * `item` (`wx.TreeItemId `_) * `font` (`wx.Font `_) .. seealso:: `SetItemBold <#SetItemBold>`_ -------- .. method:: SetItemHasChildren(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:** * `item` (`wx.TreeItemId `_) * `hasChildren` (bool) -------- .. method:: SetItemImage(item, image, which=wx.TreeItemIcon_Normal) Sets the specified item image. See `GetItemImage <#GetItemImage>`_ for the description of the `which` parameter. **Parameters:** * `item` (`wx.TreeItemId `_) * `image` (int) * `which` (int) .. seealso:: `GetItemImage <#GetItemImage>`_ -------- .. method:: SetItemPyData(item, data) Sets the item client data. Same as `SetPyData <#SetPyData>`_. **Parameters:** * `item` (`wx.TreeItemId `_) * `data` (PyObject) -------- .. method:: SetItemText(item, text) Sets the item label. **Parameters:** * `item` (`wx.TreeItemId `_) * `text` (string) -------- .. method:: SetItemTextColour(item, col) Sets the colour of the item's text. **Parameters:** * `item` (`wx.TreeItemId `_) * `col` (`wx.Colour `_) -------- .. method:: SetPyData(item, data) Sets the item client data. Same as `SetItemPyData <#SetItemPyData>`_. **Parameters:** * `item` (`wx.TreeItemId `_) * `data` (PyObject) -------- .. method:: SetQuickBestSize(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) .. seealso:: `GetQuickBestSize <#GetQuickBestSize>`_ -------- .. method:: SetSpacing(spacing) Sets the spacing for the tree control items. **Parameters:** * `spacing` (int) -------- .. method:: SetState(node, state) | **Parameters:** * `node` (`wx.TreeItemId `_) * `state` (int) -------- .. method:: SetStateImageList(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 `wx.TreeCtrl` destructor, you must delete it yourself. **Parameters:** * `imageList` (`wx.ImageList `_) .. seealso:: `AssignStateImageList <#AssignStateImageList>`_ -------- .. method:: SortChildren(item) Sorts the children of the given item using `OnCompareItems` method of `wx.TreeCtrl`. You should override that method to change the sort order (the default is ascending case-sensitive alphabetical order). A simple example of a `OnCompareItems` method may be:: def OnCompareItems(self, item1, item2): """ Overrides OnCompareItems in wx.TreeCtrl. Used by the SortChildren method. """ # Get the item data data1 = GetSomeData(item1) data2 = GetSomeData(item2) # Compare the item data if data1 < data2: return -1 elif data1 > data2: return 1 else: return 0 | **Parameters:** * `item` (`wx.TreeItemId `_) .. seealso:: `wx.TreeItemData `_ -------- .. method:: Toggle(item) Toggles the given item between collapsed and expanded states. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: ToggleItemSelection(item) Toggles the given item between selected and unselected states. For multiselection controls only. **Parameters:** * `item` (`wx.TreeItemId `_) -------- .. method:: Unselect(item) Removes the selection from the currently selected item (if any). **Parameters:** * `item` (TreeItemId) -------- .. method:: UnselectAll() This function either behaves the same as `Unselect <#Unselect>`_ if the control doesn't have ``wx.TR_MULTIPLE`` style, or removes the selection from all items if it does have this style. -------- .. method:: UnselectItem(item) Unselects the given item. This works in multiselection controls only. **Parameters:** * `item` (`wx.TreeItemId `_) -------- Properties ^^^^^^^^^^ .. attribute:: Count See `GetCount <#GetCount>`_ .. attribute:: EditControl See `GetEditControl <#GetEditControl>`_ .. attribute:: FirstVisibleItem See `GetFirstVisibleItem <#GetFirstVisibleItem>`_ .. attribute:: ImageList See `GetImageList <#GetImageList>`_ and `SetImageList <#SetImageList>`_ .. attribute:: Indent See `GetIndent <#GetIndent>`_ and `SetIndent <#SetIndent>`_ .. attribute:: QuickBestSize See `GetQuickBestSize <#GetQuickBestSize>`_ and `SetQuickBestSize <#SetQuickBestSize>`_ .. attribute:: RootItem See `GetRootItem <#GetRootItem>`_ .. attribute:: Selection See `GetSelection <#GetSelection>`_ .. attribute:: Selections See `GetSelections <#GetSelections>`_ .. attribute:: Spacing See `GetSpacing <#GetSpacing>`_ and `SetSpacing <#SetSpacing>`_ .. attribute:: StateImageList See `GetStateImageList <#GetStateImageList>`_ and `SetStateImageList <#SetStateImageList>`_