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
.
A similar control with a fully native implementation for GTK+ and macOS as well is wx.dataview.DataViewTreeCtrl.
wx.TreeCtrl inherits from wx.WithImages classes providing the functions for associating images with the control items. Each item refers to its image using an index, which can possibly by wx.WithImages.NO_IMAGE
to indicate that the item doesn’t use any image at all, and the corresponding image is taken either from the vector passed to wx.WithImages.SetImages
or from the image list passed to wx.WithImages.SetImageList
or wx.WithImages.AssignImageList
functions. In addition to normal images, handled with the methods mentioned above, wx.TreeCtrl also provides optional state images that may be used to indicate some additional state of the item, e.g. checked or unchecked status. These images can be set using SetStateImageList
and AssignStateImageList
functions that behave in the same way as the corresponding methods of wx.WithImages. Finally, in the generic version of this control (wxGenericTreeCtrl), also provides SetButtonsImageList
and AssignButtonsImageList
, which can be used to change the images used for the control buttons, used to expand or collapse its branches. These methods are not available in the native wxMSW and Qt implementations.
To intercept events from a tree control, use the event table macros described in wx.TreeEvent. ^^ This class supports the following styles:
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_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 as enabling it is equivalent to using SystemThemedControl.EnableSystemTheme
.
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 TR_NO_LINES
as well.)
wx.TR_LINES_AT_ROOT
: Use this style to show lines leading to the root nodes (unless no TR_NO_LINES
is also used, in which case no lines are shown). Note that in the MSW version, if this style is omitted, not only the lines, but also the button used for expanding the root item is not shown, which can be unexpected, so it is recommended to always use it.
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_DEFAULT_STYLE
: The set of flags that are closest to the defaults for the native control for a particular toolkit. ^^
^^
Handlers bound for the following event types will receive one of the wx.TreeEvent parameters.
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 wx.TreeEvent.Allow
, as it’s vetoed by default. Processes a wxEVT_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 wx.TreeEvent.Allow
, as it’s vetoed by default. Processes a wxEVT_TREE_BEGIN_RDRAG
event type.
EVT_TREE_END_DRAG: End dragging with the left or right mouse button. Processes a wxEVT_TREE_END_DRAG
event type.
EVT_TREE_BEGIN_LABEL_EDIT: Begin editing a label. This can be prevented by calling Veto(). Processes a wxEVT_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_TREE_END_LABEL_EDIT
event type.
EVT_TREE_DELETE_ITEM: An item was deleted. Processes a wxEVT_TREE_DELETE_ITEM
event type.
EVT_TREE_GET_INFO: Request information from the application. Processes a wxEVT_TREE_GET_INFO
event type.
EVT_TREE_SET_INFO: Information is being supplied. Processes a wxEVT_TREE_SET_INFO
event type.
EVT_TREE_ITEM_ACTIVATED: The item has been activated, i.e. chosen by double clicking it with mouse or from keyboard. Processes a wxEVT_TREE_ITEM_ACTIVATED
event type.
EVT_TREE_ITEM_COLLAPSED: The item has been collapsed. Processes a wxEVT_TREE_ITEM_COLLAPSED
event type.
EVT_TREE_ITEM_COLLAPSING: The item is being collapsed. This can be prevented by calling Veto(). Processes a wxEVT_TREE_ITEM_COLLAPSING
event type.
EVT_TREE_ITEM_EXPANDED: The item has been expanded. Processes a wxEVT_TREE_ITEM_EXPANDED
event type.
EVT_TREE_ITEM_EXPANDING: The item is being expanded. This can be prevented by calling Veto(). Processes a wxEVT_TREE_ITEM_EXPANDING
event type.
EVT_TREE_ITEM_RIGHT_CLICK: The user has clicked the item with the right mouse button. Processes a wxEVT_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_TREE_ITEM_MIDDLE_CLICK
event type.
EVT_TREE_SEL_CHANGED: Selection has changed. Processes a wxEVT_TREE_SEL_CHANGED
event type.
EVT_TREE_SEL_CHANGING: Selection is changing. This can be prevented by calling Veto(). Processes a wxEVT_TREE_SEL_CHANGING
event type.
EVT_TREE_KEY_DOWN: A key has been pressed. Processes a wxEVT_TREE_KEY_DOWN
event type.
EVT_TREE_ITEM_GETTOOLTIP: The opportunity to set the item tooltip is being given to the application (call wx.TreeEvent.SetToolTip
). Windows only. Processes a wxEVT_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. Notice that these events always carry a valid tree item and so are not generated when (right) clicking outside of the items area. If you need to handle such events, consider using wxEVT_CONTEXT_MENU
instead. Processes a wxEVT_TREE_ITEM_MENU
event type.
EVT_TREE_STATE_IMAGE_CLICK: The state image has been clicked. Processes a wxEVT_TREE_STATE_IMAGE_CLICK
event type. ^^
See also
See also
wx.dataview.DataViewTreeCtrl, wx.TreeEvent, TreeItemData , TreeCtrl Overview, wx.ListBox, wx.ListCtrl, wx.WithImages
Default Constructor. |
|
Adds the root node to the tree, returning the new item. |
|
Appends an item to the end of the branch identified by parent, return a new item id. |
|
Sets the state image list. |
|
Clears the currently focused item. |
|
Collapses the given item. |
|
Collapses the root item. |
|
Collapses this item and all of its children, recursively. |
|
Collapses the given item and removes all children. |
|
Creates the tree control. |
|
Deletes the specified item. |
|
Deletes all items in the control. |
|
Deletes all children of the given item (but not the item itself). |
|
Starts editing the label of the given item. |
|
Enable or disable a beep if there is no match for the currently entered text when searching for the item from keyboard. |
|
Can be used to disable the system theme of controls using it by default. |
|
Ends label editing. |
|
Scrolls and/or expands items to ensure that the given item is visible. |
|
Expands the given item. |
|
Expands all items in the tree. |
|
Expands the given item and all its children recursively. |
|
Returns the rectangle bounding the item. If textOnly is |
|
Returns the number of items in the branch. |
|
Returns the number of items in the control. |
|
Returns the edit control being currently used to edit a label. |
|
Returns the first child; call |
|
Returns the first visible item. |
|
Returns the item last clicked or otherwise selected. |
|
Returns the current tree control indentation. |
|
Returns the background colour of the item. |
|
Returns the tree item data associated with the item. |
|
Returns the font of the item label. |
|
Gets the specified item image. |
|
Returns the item’s parent. |
|
Gets the specified item state. |
|
Returns the item label. |
|
Returns the colour of the item label. |
|
Returns the last child of the item (or an invalid tree item if this item has no children). |
|
Returns the next child; call |
|
Returns the next sibling of the specified item; call |
|
Returns the next visible item or an invalid item if this item is the last visible one. |
|
Returns the previous sibling of the specified item; call |
|
Returns the previous visible item or an invalid item if this item is the first visible one. |
|
Returns |
|
Returns the root item for the tree control. |
|
Returns the selection, or an invalid item if there is no selection. |
|
Returns a list of currently selected items in the tree. This function can be called only if the control has the wx.``wx.TR_MULTIPLE`` style. |
|
Returns the current tree control spacing. |
|
Returns the state image list (from which application-defined state images are taken). |
|
Calculates which (if any) item is under the given point, returning the tree item id at this point plus extra information flags. |
|
Inserts an item after a given one (previous). |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Override this function in the derived class to change the sort order of the items in the tree control. |
|
Appends an item as the first child of parent, return a new item id. |
|
Scrolls the specified item into view. |
|
Select all the immediate children of the given parent. |
|
Selects the given item. |
|
Sets the currently focused item. |
|
Sets the indentation for the tree control. |
|
Sets the colour of the item’s background. |
|
Makes item appear in bold font if bold parameter is |
|
Sets the item client data. |
|
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). |
|
Sets the item’s font. |
|
Force appearance of the button next to the item. |
|
Sets the specified item’s image. |
|
Sets the specified item state. |
|
Sets the item label. |
|
Sets the colour of the item’s text. |
|
If |
|
Sets the spacing for the tree control. |
|
Sets the state image list (from which application-defined state images are taken). |
|
Sets the mode flags associated with the display of the tree control. |
|
Sorts the children of the given item using |
|
Toggles the given item between collapsed and expanded states. |
|
Toggles the given item between selected and unselected states. |
|
Removes the selection from the currently selected item (if any). |
|
This function either behaves the same as |
|
Unselects the given item. |
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
wx.
TreeCtrl
(Control, WithImages)¶Possible constructors:
TreeCtrl()
TreeCtrl(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
style=TR_DEFAULT_STYLE, validator=DefaultValidator,
name=TreeCtrlNameStr)
A tree control presents information as a hierarchy, with items that may be expanded to show further items.
__init__
(self, *args, **kw)¶__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.
parent (wx.Window) – Parent window. Must not be None
.
id (wx.WindowID) – Window identifier. The value ID_ANY
indicates a default value.
pos (wx.Point) – Window position. If wx.DefaultPosition
is specified then a default position is chosen.
size (wx.Size) – Window size. If wx.DefaultSize
is specified then the window is sized appropriately.
style (long) – Window style. See wx.TreeCtrl.
validator (wx.Validator) – Window validator.
name (string) – Window name.
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.
text (string) –
image (int) –
selImage (int) –
data (TreeItemData) –
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.
parent (wx.TreeItemId) –
text (string) –
image (int) –
selImage (int) –
data (TreeItemData) –
AssignStateImageList
(self, 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).
imageList (wx.ImageList) –
See also
ClearFocusedItem
(self)¶Clears the currently focused item.
New in version 2.9.1.
Collapse
(self, item)¶Collapses the given item.
item (wx.TreeItemId) –
CollapseAllChildren
(self, item)¶Collapses this item and all of its children, recursively.
item (wx.TreeItemId) –
See also
CollapseAndReset
(self, item)¶Collapses the given item and removes all children.
item (wx.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.
parent (wx.Window) –
id (wx.WindowID) –
pos (wx.Point) –
size (wx.Size) –
style (long) –
validator (wx.Validator) –
name (string) –
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.
item (wx.TreeItemId) –
DeleteAllItems
(self)¶Deletes all items in the control.
This function generates wxEVT_TREE_DELETE_ITEM
events for each item being deleted, including the root one if it is shown, i.e. unless wx.TR_HIDE_ROOT
style is used.
DeleteChildren
(self, item)¶Deletes all children of the given item (but not the item itself).
A wxEVT_TREE_DELETE_ITEM
event will be generated for every item being deleted.
If you have called SetItemHasChildren
, you may need to call it again since DeleteChildren
does not automatically clear the setting.
item (wx.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 to prevent the editing from starting.
If it does start, a text control, which can be retrieved using GetEditControl
, allowing the user to edit the label interactively is shown. In wxMSW, this text control is created using textCtrlClass, however this parameter is currently ignored in the other ports where a plain wx.TextCtrl is always used.
When the editing ends, EVT_TREE_END_LABEL_EDIT
event is sent and this event can be vetoed as well to prevent the label from changing. Note that this event is sent both when the user accepts (e.g. by pressing Enter) or cancels (e.g. by pressing Escape) and its handler can use wx.TreeEvent.IsEditCancelled
to distinguish between these situations.
item (wx.TreeItemId) –
See also
EnableBellOnNoMatch
(self, on=True)¶Enable or disable a beep if there is no match for the currently entered text when searching for the item from keyboard.
The default is to not beep in this case except in wxMSW where the beep is always generated by the native control and cannot be disabled, i.e. calls to this function do nothing there.
on (bool) –
New in version 2.9.5.
EnableSystemTheme
(self, enable=True)¶Can be used to disable the system theme of controls using it by default.
On Windows there an alternative theme available for the list and list-like controls since Windows Vista. This theme is used by Windows Explorer list and tree view and so is arguably more familiar to the users than the standard appearance of these controls. This class automatically uses the new theme, but if that is not desired then this method can be used to turn it off.
Please note that this method should be called before the widget is actually created, using the 2-phase create pattern. Something like this:
# This creates the object, but not the window
widget = wx.TreeCtrl()
# Disable the system theme
widget.EnableSystemTheme(False)
# Now create the window
widget.Create(parent, wx.``wx.ID_ANY``)
This method has no effect on other platorms
enable (bool) –
EndEditLabel
(self, item, discardChanges=False)¶Ends label editing.
If cancelEdit is True
, the edit will be cancelled.
item (wx.TreeItemId) –
discardChanges (bool) –
EnsureVisible
(self, item)¶Scrolls and/or expands items to ensure that the given item is visible.
This method can be used, and will work, even while the window is frozen (see wx.Window.Freeze
).
item (wx.TreeItemId) –
Expand
(self, item)¶Expands the given item.
item (wx.TreeItemId) –
ExpandAll
(self)¶Expands all items in the tree.
ExpandAllChildren
(self, item)¶Expands the given item and all its children recursively.
item (wx.TreeItemId) –
GetBoundingRect
(self, item, textOnly=False)¶Returns 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. The return value may be None if the rectangle was not successfully retrieved, such as if the item is currently not visible.
PyObject
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.
item (wx.TreeItemId) –
recursively (bool) –
int
GetClassDefaultAttributes
(variant=WINDOW_VARIANT_NORMAL)¶variant (WindowVariant) –
GetCount
(self)¶Returns the number of items in the control.
int
GetEditControl
(self)¶Returns the edit control being currently used to edit a label.
Returns None
if no label is being edited.
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. wx.TreeItemId.IsOk
returns False
) if there are no further children.
GetFirstVisibleItem
(self)¶Returns the first visible item.
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.
New in version 2.9.1.
GetIndent
(self)¶Returns the current tree control indentation.
int
GetItemBackgroundColour
(self, item)¶Returns the background colour of the item.
item (wx.TreeItemId) –
GetItemData
(self, item)¶Returns the tree item data associated with the item.
GetItemFont
(self, item)¶Returns the font of the item label.
If the font hadn’t been explicitly set for the specified item with SetItemFont
, returns an invalid wx.NullFont
font. GetFont
can be used to retrieve the global tree control font used for the items without any specific font.
item (wx.TreeItemId) –
GetItemImage
(self, item, which=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).
item (wx.TreeItemId) –
which (TreeItemIcon) –
int
GetItemParent
(self, item)¶Returns the item’s parent.
item (wx.TreeItemId) –
GetItemState
(self, item)¶Gets the specified item state.
item (wx.TreeItemId) –
int
GetItemText
(self, item)¶Returns the item label.
item (wx.TreeItemId) –
string
GetItemTextColour
(self, item)¶Returns the colour of the item label.
item (wx.TreeItemId) –
GetLastChild
(self, item)¶Returns the last child of the item (or an invalid tree item if this item has no children).
item (wx.TreeItemId) –
See also
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.
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.
item (wx.TreeItemId) –
See also
GetNextVisible
(self, item)¶Returns the next visible item or an invalid item if this item is the last visible one.
item (wx.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.
item (wx.TreeItemId) –
See also
GetPrevVisible
(self, item)¶Returns the previous visible item or an invalid item if this item is the first visible one.
item (wx.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
.
bool
See also
GetRootItem
(self)¶Returns the root item for the tree control.
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
.
GetSelections
(self)¶Returns a list of currently selected items in the tree. This function can be called only if the control has the wx.``wx.TR_MULTIPLE`` style.
PyObject
GetSpacing
(self)¶Returns the current tree control spacing.
This is the number of horizontal pixels between the buttons and the state images.
int
GetStateImageList
(self)¶Returns the state image list (from which application-defined state images are taken).
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.
InsertItem
(self, *args, **kw)¶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.
parent (wx.TreeItemId) –
previous (wx.TreeItemId) –
text (string) –
image (int) –
selImage (int) –
data (TreeItemData) –
InsertItem (self, parent, pos, text, image=-1, selImage=-1, data=None)
Inserts an item before one identified by its position (pos).
pos must be less than or equal to 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.
parent (wx.TreeItemId) –
pos (int) –
text (string) –
image (int) –
selImage (int) –
data (TreeItemData) –
IsBold
(self, item)¶Returns True
if the given item is in bold state.
item (wx.TreeItemId) –
bool
See also
IsEmpty
(self)¶Returns True
if the control is empty (i.e. has no items, even no root one).
bool
IsExpanded
(self, item)¶Returns True
if the item is expanded (only makes sense if it has children).
item (wx.TreeItemId) –
bool
IsSelected
(self, item)¶Returns True
if the item is selected.
item (wx.TreeItemId) –
bool
IsVisible
(self, item)¶Returns True
if the item is visible on the screen.
item (wx.TreeItemId) –
bool
ItemHasChildren
(self, item)¶Returns True
if the item has children.
item (wx.TreeItemId) –
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.
item1 (wx.TreeItemId) –
item2 (wx.TreeItemId) –
int
See also
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.
parent (wx.TreeItemId) –
text (string) –
image (int) –
selImage (int) –
data (TreeItemData) –
ScrollTo
(self, item)¶Scrolls the specified item into view.
Note that this method doesn’t work while the window is frozen (See wx.Window.Freeze
), at least under MSW.
item (wx.TreeItemId) –
See also
SelectChildren
(self, parent)¶Select all the immediate children of the given parent.
This function can be used with multiselection controls only.
parent (wx.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_TREE_SEL_CHANGING
and wxEVT_TREE_SEL_CHANGED
events and that the change could be vetoed by the former event handler.
item (wx.TreeItemId) –
select (bool) –
SetFocusedItem
(self, item)¶Sets the currently focused item.
item (wx.TreeItemId) – The item to make the current one. It must be valid.
New in version 2.9.1.
SetIndent
(self, indent)¶Sets the indentation for the tree control.
indent (int) –
SetItemBackgroundColour
(self, item, col)¶Sets the colour of the item’s background.
item (wx.TreeItemId) –
col (wx.Colour) –
SetItemBold
(self, item, bold=True)¶Makes item appear in bold font if bold parameter is True
or resets it to the normal state.
item (wx.TreeItemId) –
bold (bool) –
See also
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.
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).
item (wx.TreeItemId) –
highlight (bool) –
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.
item (wx.TreeItemId) –
font (wx.Font) –
See also
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.
item (wx.TreeItemId) –
hasChildren (bool) –
SetItemImage
(self, item, image, which=TreeItemIcon_Normal)¶Sets the specified item’s image.
See GetItemImage
for the description of the which parameter.
item (wx.TreeItemId) –
image (int) –
which (TreeItemIcon) –
SetItemState
(self, item, state)¶Sets the specified item state.
The value of state may be an index into the state image list, or one of the special values:
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.
item (wx.TreeItemId) –
state (int) –
SetItemText
(self, item, text)¶Sets the item label.
item (wx.TreeItemId) –
text (string) –
SetItemTextColour
(self, item, col)¶Sets the colour of the item’s text.
item (wx.TreeItemId) –
col (wx.Colour) –
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
.
quickBestSize (bool) –
See also
SetSpacing
(self, spacing)¶Sets the spacing for the tree control.
Spacing is the number of horizontal pixels between the buttons and the state images. This has no effect under wxMSW.
spacing (int) –
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 wx.TreeCtrl’s destructor, you must delete it yourself.
imageList (wx.ImageList) –
See also
SetWindowStyle
(self, styles)¶Sets the mode flags associated with the display of the tree control.
The new mode takes effect immediately.
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).
item (wx.TreeItemId) –
See also
TreeItemData , OnCompareItems
Toggle
(self, item)¶Toggles the given item between collapsed and expanded states.
item (wx.TreeItemId) –
ToggleItemSelection
(self, item)¶Toggles the given item between selected and unselected states.
For multiselection controls only.
item (wx.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.
item (wx.TreeItemId) –
BoundingRect
¶See GetBoundingRect
EditControl
¶See GetEditControl
FirstVisibleItem
¶FocusedItem
¶See GetFocusedItem
and SetFocusedItem
QuickBestSize
¶See GetQuickBestSize
and SetQuickBestSize
RootItem
¶See GetRootItem
Selection
¶See GetSelection
Selections
¶See GetSelections
Spacing
¶See GetSpacing
and SetSpacing
StateImageList
¶See GetStateImageList
and SetStateImageList