AGW Logo

agw_title GenericTreeItem

This class holds all the information and methods for every single item in CustomTreeCtrl. This is a generic implementation of wx.TreeItem.

hierarchy Inheritance Diagram

Inheritance diagram for: GenericTreeItem

Inheritance diagram of GenericTreeItem


subclasses Known Subclasses


method_summary Methods Summary

__init__Default class constructor.
AssignAttributesAssigns the item attributes (font, colours, etc...) for this item.
AttrCreates a new attribute (font, colours, etc...) for this item.
CheckChecks/unchecks an item.
CollapseCollapses the item.
DeleteChildrenDeletes the item children.
DeleteWindowDeletes the window associated to the item (if any).
EnableEnables/disables the item.
ExpandExpands the item.
Get3StateValueGets the state of a 3-state checkbox item.
GetAttributesReturns the item attributes (font, colours, etc...).
GetCheckedImageReturns the item check image.
GetChildrenReturns the item’s children.
GetChildrenCountGets the number of children of this item.
GetCurrentCheckedImageReturns the current item check image.
GetCurrentImageReturns the current item image.
GetDataReturns the data associated to this item.
GetHeightReturns the height of the item, in pixels.
GetImageReturns the item image for a particular item state.
GetLeftImageReturns the leftmost image associated to this item, i.e.
GetParentGets the item parent (another instance of GenericTreeItem or None for
GetSizeReturns the item size.
GetTextReturns the item text.
GetTypeReturns the item type.
GetValueReturns whether the item is checked or not.
GetVisitedReturns whether an hypertext item was visited or not.
GetWidthReturns the width of the item, in pixels.
GetWindowReturns the window associated to the item (if any).
GetWindowEnabledReturns whether the associated window is enabled or not.
GetWindowSizeReturns the associated window size.
GetXReturns the x position on an item, in logical coordinates.
GetYReturns the y position on an item, in logical coordinates.
HasChildrenReturns whether the item has children or not.
HasPlusReturns whether the item has the plus button or not.
HitTestHitTest method for an item. Called from the main window CustomTreeCtrl.HitTest().
InsertInserts an item in the item children list for this item.
Is3StateReturns whether or not the checkbox item is a 3-state checkbox.
IsBoldReturns whether the item font is bold or not.
IsCheckedThis is just a maybe more readable synonym for GetValue.
IsEnabledReturns whether the item is enabled or not.
IsExpandedReturns whether the item is expanded or not.
IsHyperTextReturns whether the item is hypetext or not.
IsItalicReturns whether the item font is italic or not.
IsOkReturns whether the item is ok or not.
IsSelectedReturns whether the item is selected or not.
IsSeparatorReturns whether the item is meant to be an horizontal line separator or not.
OnSetFocusHandles the wx.EVT_SET_FOCUS event for the window associated with the item.
Set3StateSets whether the item has a 3-state value checkbox assigned to it or not.
Set3StateValueSets the checkbox item to the given state.
SetAttributesSets the item attributes (font, colours, etc...).
SetBoldSets the item font bold.
SetDataSets the data associated to this item.
SetHasPlusSets whether an item has the ‘plus’ button.
SetHeightSets the item’s height.
SetHilightSets the item focus/unfocus.
SetHyperTextSets whether the item is hypertext or not.
SetImageSets the item image.
SetItalicSets the item font italic.
SetLeftImageSets the item leftmost image, i.e.
SetTextSets the item text.
SetTypeSets the item type.
SetVisitedSets whether an hypertext item was visited or not.
SetWidthSets the item’s width.
SetWindowSets the window associated to the item.
SetWindowEnabledSets whether the associated window is enabled or not.
SetXSets the x position on an item, in logical coordinates.
SetYSets the y position on an item, in logical coordinates.

API Class API

class GenericTreeItem(object)[source]

This class holds all the information and methods for every single item in CustomTreeCtrl. This is a generic implementation of wx.TreeItem.



__init__(parent, text='', ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False)[source]

Default class constructor. For internal use: do not call it in your code!

Parameters:
  • parent – the tree item parent, an instance of GenericTreeItem (may be None for root items);
  • text (string) – the tree item text;
  • ct_type (integer) – the tree item kind. May be one of the following integers:


    integer parameter settings
    ct_type Value Description
    0 A normal item
    1 A checkbox-like item
    2 A radiobutton-type item
  • wnd – if not None, a non-toplevel window to be displayed next to the item, an instance of wx.Window;
  • image (integer) – an index within the normal image list specifying the image to use for the item in unselected state;
  • selImage (integer) – an index within the normal image list specifying the image to use for the item in selected state; if image > -1 and selImage is -1, the same image is used for both selected and unselected items;
  • data (object) – associate the given Python object data with the item;
  • separator (bool) – True if the item is a separator, False otherwise.

Note

Regarding radiobutton-type items (with ct_type = 2), the following approach is used:

  • All peer-nodes that are radiobuttons will be mutually exclusive. In other words, only one of a set of radiobuttons that share a common parent can be checked at once. If a radiobutton node becomes checked, then all of its peer radiobuttons must be unchecked.
  • If a radiobutton node becomes unchecked, then all of its child nodes will become inactive.

Note

Separator items should not have children, labels, data or an associated window. Other issues/features associated to separator items:



AssignAttributes(attr)[source]

Assigns the item attributes (font, colours, etc...) for this item.

Parameters:attr – an instance of TreeItemAttr.


Attr()[source]

Creates a new attribute (font, colours, etc...) for this item.

Returns:An instance of TreeItemAttr.


Check(checked=True)[source]

Checks/unchecks an item.

Parameters:checked (bool) – True to check an item, False to uncheck it.

Note

This is meaningful only for checkbox-like and radiobutton-like items.



Collapse()[source]

Collapses the item.



DeleteChildren(tree)[source]

Deletes the item children.

Parameters:tree – the main CustomTreeCtrl instance.


DeleteWindow()[source]

Deletes the window associated to the item (if any).



Enable(enable=True)[source]

Enables/disables the item.

Parameters:enable (bool) – True to enable the item, False to disable it.


Expand()[source]

Expands the item.



Get3StateValue()[source]

Gets the state of a 3-state checkbox item.

Returns:wx.CHK_UNCHECKED when the checkbox is unchecked, wx.CHK_CHECKED when it is checked and wx.CHK_UNDETERMINED when it’s in the undetermined state.
Raise :Exception when the item is not a 3-state checkbox item.

Note

This method raises an exception when the function is used with a 2-state checkbox item.

Note

This method is meaningful only for checkbox-like items.



GetAttributes()[source]

Returns the item attributes (font, colours, etc...).

Returns:An instance of TreeItemAttr.


GetCheckedImage(which=TreeItemIcon_Checked)[source]

Returns the item check image.

Parameters:which (integer) – can be one of the following bits:


integer parameter settings
Item State Description
TreeItemIcon_Checked To get the checkbox checked item image
TreeItemIcon_NotChecked To get the checkbox unchecked item image
TreeItemIcon_Undetermined To get the checkbox undetermined state item image
TreeItemIcon_Flagged To get the radiobutton checked image
TreeItemIcon_NotFlagged To get the radiobutton unchecked image
Returns:An integer index that can be used to retrieve the item check image inside a wx.ImageList.

Note

This method is meaningful only for radio & check items.



GetChildren()[source]

Returns the item’s children.

Returns:A Python list containing instances of GenericTreeItem, representing this item’s children.


GetChildrenCount(recursively=True)[source]

Gets the number of children of this item.

Parameters:recursively (bool) – if True, returns the total number of descendants, otherwise only one level of children is counted.


GetCurrentCheckedImage()[source]

Returns the current item check image.

Returns:An integer index that can be used to retrieve the item check image inside a wx.ImageList.


GetCurrentImage()[source]

Returns the current item image.

Returns:An integer index that can be used to retrieve the item image inside a wx.ImageList.


GetData()[source]

Returns the data associated to this item.

Returns:A Python object representing the item data, or None if no data has been assigned to this item.


GetHeight()[source]

Returns the height of the item, in pixels.



GetImage(which=TreeItemIcon_Normal)[source]

Returns the item image for a particular item state.

Parameters:which (integer) – can be one of the following bits:


integer parameter settings
Item State Description
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)
Returns:An integer index that can be used to retrieve the item image inside a wx.ImageList.


GetLeftImage()[source]

Returns the leftmost image associated to this item, i.e. the image on the leftmost part of the client area of CustomTreeCtrl.

Returns:An integer index that can be used to retrieve the item leftmost image inside a wx.ImageList.


GetParent()[source]

Gets the item parent (another instance of GenericTreeItem or None for root items.

Returns:An instance of GenericTreeItem or None for root items.


GetSize(x, y, theButton)[source]

Returns the item size.

Parameters:
  • x (integer) – the current item’s x position;
  • y (integer) – the current item’s y position;
  • theButton – an instance of the main CustomTreeCtrl.
Returns:

A tuple of (x, y) dimensions, in pixels, representing the item’s width and height.



GetText()[source]

Returns the item text.

Returns:A string containing the item text.


GetType()[source]

Returns the item type.

See also

SetType and __init__ for a description of valid item types.



GetValue()[source]

Returns whether the item is checked or not.

Note

This is meaningful only for checkbox-like and radiobutton-like items.



GetVisited()[source]

Returns whether an hypertext item was visited or not.



GetWidth()[source]

Returns the width of the item, in pixels.



GetWindow()[source]

Returns the window associated to the item (if any).

Returns:An instance of any wx.Window derived class, excluding top-level windows.


GetWindowEnabled()[source]

Returns whether the associated window is enabled or not.

Returns:True if the associated window is enabled, False if it is disabled.
Raise :Exception when the item has no associated window.


GetWindowSize()[source]

Returns the associated window size.



GetX()[source]

Returns the x position on an item, in logical coordinates.



GetY()[source]

Returns the y position on an item, in logical coordinates.



HasChildren()[source]

Returns whether the item has children or not.

Returns:True if the item has children, False otherwise.


HasPlus()[source]

Returns whether the item has the plus button or not.

Returns:True if the item has a ‘plus’ mark, False otherwise.


HitTest(point, theCtrl, flags=0, level=0)[source]

HitTest method for an item. Called from the main window CustomTreeCtrl.HitTest().

Parameters:
  • point – the point to test for the hit (an instance of wx.Point);
  • theCtrl – the main CustomTreeCtrl tree;
  • flags (integer) – a bitlist of hit locations;
  • level (integer) – the item’s level inside the tree hierarchy.

See also

CustomTreeCtrl.HitTest() method for the flags explanation.



Insert(child, index)[source]

Inserts an item in the item children list for this item.

Parameters:
  • child – an instance of GenericTreeItem;
  • index (integer) – the index at which we should insert the new child.


Is3State()[source]

Returns whether or not the checkbox item is a 3-state checkbox.

Returns:True if this checkbox is a 3-state checkbox, False if it’s a 2-state checkbox item.

Note

This method is meaningful only for checkbox-like items.



IsBold()[source]

Returns whether the item font is bold or not.

Returns:True if the item has bold text, False otherwise.


IsChecked()[source]

This is just a maybe more readable synonym for GetValue. Returns whether the item is checked or not.

Note

This is meaningful only for checkbox-like and radiobutton-like items.



IsEnabled()[source]

Returns whether the item is enabled or not.

Returns:True if the item is enabled, False if it is disabled.


IsExpanded()[source]

Returns whether the item is expanded or not.

Returns:True if the item is expanded, False if it is collapsed.


IsHyperText()[source]

Returns whether the item is hypetext or not.



IsItalic()[source]

Returns whether the item font is italic or not.

Returns:True if the item has italic text, False otherwise.


IsOk()[source]

Returns whether the item is ok or not.

Note

This method always returns True, it has been added for backward compatibility with the wxWidgets C++ implementation.



IsSelected()[source]

Returns whether the item is selected or not.

Returns:True if the item is selected, False otherwise.


IsSeparator()[source]

Returns whether the item is meant to be an horizontal line separator or not.

Returns:True if this item is a separator, False otherwise.


OnSetFocus(event)[source]

Handles the wx.EVT_SET_FOCUS event for the window associated with the item.

Parameters:event – a wx.FocusEvent event to be processed.


Set3State(allow)[source]

Sets whether the item has a 3-state value checkbox assigned to it or not.

Parameters:allow (bool) – True to set an item as a 3-state checkbox, False to set it to a 2-state checkbox.
Returns:True if the change was successful, False otherwise.

Note

This method is meaningful only for checkbox-like items.



Set3StateValue(state)[source]

Sets the checkbox item to the given state.

Parameters:state (integer) – can be one of: wx.CHK_UNCHECKED (check is off), wx.CHK_CHECKED (check is on) or wx.CHK_UNDETERMINED (check is mixed).
Raise :Exception when the item is not a 3-state checkbox item.

Note

This method raises an exception when the checkbox item is a 2-state checkbox and setting the state to wx.CHK_UNDETERMINED.

Note

This method is meaningful only for checkbox-like items.



SetAttributes(attr)[source]

Sets the item attributes (font, colours, etc...).

Parameters:attr – an instance of TreeItemAttr.


SetBold(bold)[source]

Sets the item font bold.

Parameters:bold (bool) – True to have a bold font item, False otherwise.


SetData(data)[source]

Sets the data associated to this item.

Parameters:data (object) – can be any Python object.


SetHasPlus(has=True)[source]

Sets whether an item has the ‘plus’ button.

Parameters:has (bool) – True to set the ‘plus’ button on the item, False otherwise.


SetHeight(h)[source]

Sets the item’s height.

Parameters:h (integer) – an integer specifying the item’s height, in pixels.


SetHilight(set=True)[source]

Sets the item focus/unfocus.

Parameters:set (bool) – True to set the focus to the item, False otherwise.


SetHyperText(hyper=True)[source]

Sets whether the item is hypertext or not.

Parameters:hyper (bool) – True to set hypertext behaviour, False otherwise.


SetImage(image, which)[source]

Sets the item image.

Parameters:
  • image (integer) – an index within the normal image list specifying the image to use;
  • which (integer) – the image kind.

See also

GetImage for a description of the which parameter.



SetItalic(italic)[source]

Sets the item font italic.

Parameters:italic (bool) – True to have an italic font item, False otherwise.


SetLeftImage(image)[source]

Sets the item leftmost image, i.e. the image associated to the item on the leftmost part of the CustomTreeCtrl client area.

Parameters:image (integer) – an index within the left image list specifying the image to use for the item in the leftmost part of the client area.


SetText(text)[source]

Sets the item text.

Parameters:text (string) – the new item label.
Raise :Exception if the item is a separator.


SetType(ct_type)[source]

Sets the item type.

Parameters:ct_type (integer) – may be one of the following integers:


integer parameter settings
ct_type Value Description
0 A normal item
1 A checkbox-like item
2 A radiobutton-type item

Note

Regarding radiobutton-type items (with ct_type = 2), the following approach is used:

  • All peer-nodes that are radiobuttons will be mutually exclusive. In other words, only one of a set of radiobuttons that share a common parent can be checked at once. If a radiobutton node becomes checked, then all of its peer radiobuttons must be unchecked.
  • If a radiobutton node becomes unchecked, then all of its child nodes will become inactive.


SetVisited(visited=True)[source]

Sets whether an hypertext item was visited or not.

Parameters:visited (bool) – True to set a hypertext item as visited, False otherwise.


SetWidth(w)[source]

Sets the item’s width.

Parameters:w (integer) – an integer specifying the item’s width, in pixels.


SetWindow(wnd)[source]

Sets the window associated to the item.

Parameters:wnd – a non-toplevel window to be displayed next to the item, any subclass of wx.Window.

Raise :Exception if the input item is a separator and wnd is not None.


SetWindowEnabled(enable=True)[source]

Sets whether the associated window is enabled or not.

Parameters:enable (bool) – True to enable the associated window, False to disable it.
Raise :Exception when the item has no associated window.


SetX(x)[source]

Sets the x position on an item, in logical coordinates.

Parameters:x (integer) – an integer specifying the x position of the item.


SetY(y)[source]

Sets the y position on an item, in logical coordinates.

Parameters:y (integer) – an integer specifying the y position of the item.
Tree

Table Of Contents

Previous topic

DragImage

Next topic

TreeEditTimer