Phoenix Logo

phoenix_title wx.lib.mixins.treemixin.VirtualTree

This is a mixin class that can be used to allow for virtual tree controls. It can be mixed in with wx.TreeCtrl, wx.gizmos.TreeListCtrl, wx.lib.customtree.CustomTreeCtrl.

To use it derive a new class from this class and one of the tree controls, e.g.:

class MyTree(VirtualTree, wx.TreeCtrl):
    # Other code here

VirtualTree uses several callbacks (such as OnGetItemText) to retrieve information needed to construct the tree and render the items. To specify what item the callback needs information about, the callback passes an item index. Whereas for list controls a simple integer index can be used, for tree controls indicating a specific item is a little bit more complicated. See below for a more detailed explanation of the how index works.

Note that VirtualTree forces the wx.TR_HIDE_ROOT style.

In your subclass you must override OnGetItemText and OnGetChildrenCount. These two methods are the minimum needed to construct the tree and render the item labels. If you want to add images, change fonts our colours, etc., you need to override the appropriate OnGetXXX method as well.

About indices: your callbacks are passed a tuple of integers that identifies the item the VirtualTree wants information about. An empty tuple, i.e. (), represents the hidden root item. A tuple with one integer, e.g. (3,), represents a visible root item, in this case the fourth one. A tuple with two integers, e.g. (3,0), represents a child of a visible root item, in this case the first child of the fourth root item.


class_hierarchy Class Hierarchy

Inheritance diagram for class VirtualTree:

method_summary Methods Summary

__init__  
ChildIndices  
DoRefreshItem Refresh one item.
OnGetChildrenCount This function must be overloaded in the derived class.
OnGetItemBackgroundColour This function may be overloaded in the derived class. It
OnGetItemChecked This function may be overloaded in the derived class, but
OnGetItemFont This function may be overloaded in the derived class. It
OnGetItemImage This function may be overloaded in the derived class. It
OnGetItemText This function must be overloaded in the derived class. It
OnGetItemTextColour This function may be overloaded in the derived class. It
OnGetItemType This function may be overloaded in the derived class, but
OnItemCollapsed  
OnItemExpanding  
RefreshBackgroundColour  
RefreshCheckedState  
RefreshChildrenRecursively Refresh the children of item, reusing as much of the
RefreshColumns  
RefreshItem Redraws the item with the specified index.
RefreshItemFont  
RefreshItemImage  
RefreshItemRecursively Refresh the item and its children recursively.
RefreshItems Redraws all visible items.
RefreshItemText  
RefreshItemType  
RefreshTextColour  

api Class API



class VirtualTree(TreeAPIHarmonizer, TreeHelper)

This is a mixin class that can be used to allow for virtual tree controls. It can be mixed in with wx.TreeCtrl, wx.gizmos.TreeListCtrl, wx.lib.customtree.CustomTreeCtrl.

To use it derive a new class from this class and one of the tree controls, e.g.:

class MyTree(VirtualTree, wx.TreeCtrl):
    # Other code here

VirtualTree uses several callbacks (such as OnGetItemText) to retrieve information needed to construct the tree and render the items. To specify what item the callback needs information about, the callback passes an item index. Whereas for list controls a simple integer index can be used, for tree controls indicating a specific item is a little bit more complicated. See below for a more detailed explanation of the how index works.

Note that VirtualTree forces the wx.TR_HIDE_ROOT style.

In your subclass you must override OnGetItemText and OnGetChildrenCount. These two methods are the minimum needed to construct the tree and render the item labels. If you want to add images, change fonts our colours, etc., you need to override the appropriate OnGetXXX method as well.

About indices: your callbacks are passed a tuple of integers that identifies the item the VirtualTree wants information about. An empty tuple, i.e. (), represents the hidden root item. A tuple with one integer, e.g. (3,), represents a visible root item, in this case the fourth one. A tuple with two integers, e.g. (3,0), represents a child of a visible root item, in this case the first child of the fourth root item.


Methods



__init__(self, *args, **kwargs)


ChildIndices(self, itemIndex)


DoRefreshItem(self, item, index, hasChildren)

Refresh one item.



OnGetChildrenCount(self, index)

This function must be overloaded in the derived class. It should return the number of child items of the item with the provided index. If index == () it should return the number of root items.



OnGetItemBackgroundColour(self, index)

This function may be overloaded in the derived class. It should return the wx.Colour to be used as background colour for the specified item.



OnGetItemChecked(self, index)

This function may be overloaded in the derived class, but that only makes sense when this class is mixed in with a tree control that supports checkable items, i.e. CustomTreeCtrl. This method should return whether the item is to be checked. Note that OnGetItemType should return 1 (checkbox) or 2 (radiobutton) for this item.



OnGetItemFont(self, index)

This function may be overloaded in the derived class. It should return the wx.Font to be used for the specified item.



OnGetItemImage(self, index, which=wx.TreeItemIcon_Normal, column=0)

This function may be overloaded in the derived class. It should return the index of the image to be used. Don’t forget to associate an ImageList with the tree control.



OnGetItemText(self, index, column=0)

This function must be overloaded in the derived class. It should return the string containing the text of the specified item.



OnGetItemTextColour(self, index)

This function may be overloaded in the derived class. It should return the wx.Colour to be used as text colour for the specified item.



OnGetItemType(self, index)

This function may be overloaded in the derived class, but that only makes sense when this class is mixed in with a tree control that supports checkable items, i.e. CustomTreeCtrl. This method should return whether the item is to be normal (0, the default), a checkbox (1) or a radiobutton (2). Note that OnGetItemChecked needs to be implemented as well; it should return whether the item is actually checked.



OnItemCollapsed(self, event)


OnItemExpanding(self, event)


RefreshBackgroundColour(self, item, index)


RefreshCheckedState(self, item, index)


RefreshChildrenRecursively(self, item, itemIndex=None)

Refresh the children of item, reusing as much of the existing items in the tree as possible.



RefreshColumns(self, item, index)


RefreshItem(self, index)

Redraws the item with the specified index.



RefreshItemFont(self, item, index)


RefreshItemImage(self, item, index, hasChildren)


RefreshItemRecursively(self, item, itemIndex)

Refresh the item and its children recursively.



RefreshItems(self)

Redraws all visible items.



RefreshItemText(self, item, index)


RefreshItemType(self, item, index)


RefreshTextColour(self, item, index)