Module CustomTreeCtrl
[hide private]
[frames] | no frames]

Module CustomTreeCtrl
source code


Description
===========

CustomTreeCtrl is a class that mimics the behaviour of wx.TreeCtrl, with almost the
same base functionalities plus some more enhancements. This class does not rely on
the native control, as it is a full owner-drawn tree control.
Apart of the base functionalities of CustomTreeCtrl (described below), in addition
to the standard wx.TreeCtrl behaviour this class supports:

* CheckBox-type items: checkboxes are easy to handle, just selected or unselected
  state with no particular issues in handling the item's children;

* RadioButton-type items: since I elected to put radiobuttons in CustomTreeCtrl, I
  needed some way to handle them, that made sense. So, I used the following approach:
     - 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.

* Hyperlink-type items: they look like an hyperlink, with the proper mouse cursor on
  hovering.

* Multiline text items.

* Enabling/disabling items (together with their plain or grayed out icons).

* Whatever non-toplevel widget can be attached next to an item.

* Default selection style, gradient (horizontal/vertical) selection style and Windows
  Vista selection style.

* Customized drag and drop images built on the fly.

* Setting the CustomTreeCtrl item buttons to a personalized imagelist.

* Setting the CustomTreeCtrl check/radio item icons to a personalized imagelist.

* Changing the style of the lines that connect the items (in terms of wx.Pen styles).

* Using an image as a CustomTreeCtrl background (currently only in "tile" mode).

And a lot more. Check the demo for an almost complete review of the functionalities.


Base Functionalities
====================

CustomTreeCtrl supports all the wx.TreeCtrl styles, except:
  - TR_EXTENDED: supports for this style is on the todo list (Am I sure of this?).

Plus it has 2 more styles to handle checkbox-type items:
  - TR_AUTO_CHECK_CHILD : automatically checks/unchecks the item children;
  - TR_AUTO_TOGGLE_CHILD: automatically toggles the item children.

All the methods available in wx.TreeCtrl are also available in CustomTreeCtrl.


Events
======

All the events supported by wx.TreeCtrl are also available in CustomTreeCtrl, with
a few exceptions:

  - EVT_TREE_GET_INFO (don't know what this means);
  - EVT_TREE_SET_INFO (don't know what this means);
  - EVT_TREE_ITEM_MIDDLE_CLICK (not implemented, but easy to add);
  - EVT_TREE_STATE_IMAGE_CLICK: no need for that, look at the checking events below.

Plus, CustomTreeCtrl supports the events related to the checkbutton-type items:

  - EVT_TREE_ITEM_CHECKING: an item is being checked;
  - EVT_TREE_ITEM_CHECKED: an item has been checked.

And to hyperlink-type items:

  - EVT_TREE_ITEM_HYPERLINK: an hyperlink item has been clicked (this event is sent
    after the EVT_TREE_SEL_CHANGED event).


Supported Platforms
===================

CustomTreeCtrl has been tested on the following platforms:
  * Windows (Windows XP);
  * GTK (Thanks to Michele Petrazzo);
  * Mac OS (Thanks to John Jackson).


Latest Revision: Andrea Gavana @ 26 May 2006, 11.30 CET
Version 0.7



Classes [hide private]
CommandTreeEvent CommandTreeEvent is a special subclassing of wx.PyCommandEvent.
CustomTreeCtrl  
DragImage This class handles the creation of a custom image in case of item drag and drop.
GenericTreeItem This class holds all the information and methods for every single item in CustomTreeCtrl.
TreeEvent  
TreeFindTimer Timer used to clear CustomTreeCtrl._findPrefix if no key was pressed for a sufficiently long time.
TreeItemAttr Creates the item attributes (text colour, background colour and font).
TreeRenameTimer Timer used for enabling in-place edit.
TreeTextCtrl Control used for in-place edit.

Functions [hide private]
  DrawTreeItemButton(win, dc, rect, flags)
A simple replacement of wx.RendererNative.DrawTreeItemButton.
  EventFlagsToSelType(style, shiftDown=False, ctrlDown=False)
Translate the key or mouse event flag to the type of selection we are dealing with.
  GetCheckedBitmap()
  GetCheckedData()
  GetCheckedImage()
  GetFlaggedBitmap()
  GetFlaggedData()
  GetFlaggedImage()
  GetNotCheckedBitmap()
  GetNotCheckedData()
  GetNotCheckedImage()
  GetNotFlaggedBitmap()
  GetNotFlaggedData()
  GetNotFlaggedImage()
  GrayOut(anImage)
Convert the given image (in place) to a grayed-out version, appropriate for a 'disabled' appearance.
  MakeGray((r, g, b), factor, maskColor)
Make a pixel grayed-out.

Variables [hide private]
EVT_TREE_BEGIN_DRAG  
EVT_TREE_BEGIN_LABEL_EDIT  
EVT_TREE_BEGIN_RDRAG  
EVT_TREE_DELETE_ITEM  
EVT_TREE_END_DRAG  
EVT_TREE_END_LABEL_EDIT  
EVT_TREE_GET_INFO  
EVT_TREE_ITEM_ACTIVATED  
EVT_TREE_ITEM_CHECKED  
EVT_TREE_ITEM_CHECKING  
EVT_TREE_ITEM_COLLAPSED  
EVT_TREE_ITEM_COLLAPSING  
EVT_TREE_ITEM_EXPANDED  
EVT_TREE_ITEM_EXPANDING  
EVT_TREE_ITEM_GETTOOLTIP  
EVT_TREE_ITEM_HYPERLINK  
EVT_TREE_ITEM_MENU  
EVT_TREE_ITEM_MIDDLE_CLICK  
EVT_TREE_ITEM_RIGHT_CLICK  
EVT_TREE_KEY_DOWN  
EVT_TREE_SEL_CHANGED  
EVT_TREE_SEL_CHANGING  
EVT_TREE_SET_INFO  
EVT_TREE_STATE_IMAGE_CLICK  
TREE_HITTEST_ABOVE  
TREE_HITTEST_BELOW  
TREE_HITTEST_NOWHERE  
TREE_HITTEST_ONITEM  
TREE_HITTEST_ONITEMBUTTON  
TREE_HITTEST_ONITEMCHECKICON  
TREE_HITTEST_ONITEMICON  
TREE_HITTEST_ONITEMINDENT  
TREE_HITTEST_ONITEMLABEL  
TREE_HITTEST_ONITEMLOWERPART  
TREE_HITTEST_ONITEMRIGHT  
TREE_HITTEST_ONITEMSTATEICON  
TREE_HITTEST_ONITEMUPPERPART  
TREE_HITTEST_TOLEFT  
TREE_HITTEST_TORIGHT  
TR_AUTO_CHECK_CHILD  
TR_AUTO_TOGGLE_CHILD  
TR_DEFAULT_STYLE  
TR_EDIT_LABELS  
TR_EXTENDED  
TR_FULL_ROW_HIGHLIGHT  
TR_HAS_BUTTONS  
TR_HAS_VARIABLE_ROW_HEIGHT  
TR_HIDE_ROOT  
TR_LINES_AT_ROOT  
TR_MULTIPLE  
TR_NO_BUTTONS  
TR_NO_LINES  
TR_ROW_LINES  
TR_SINGLE  
TR_TWIST_BUTTONS  
TreeItemIcon_Checked  
TreeItemIcon_Expanded  
TreeItemIcon_Flagged  
TreeItemIcon_Normal  
TreeItemIcon_NotChecked  
TreeItemIcon_NotFlagged  
TreeItemIcon_Selected  
TreeItemIcon_SelectedExpanded  
_CONTROL_CURRENT  
_CONTROL_EXPANDED  
_DELAY  
_NO_IMAGE  
_PIXELS_PER_UNIT  
_StyleStretch  
_StyleTile  
__version__  
_rgbNoFocusBottom  
_rgbNoFocusInner  
_rgbNoFocusOuter  
_rgbNoFocusTop  
_rgbSelectBottom  
_rgbSelectInner  
_rgbSelectOuter  
_rgbSelectTop  
wxEVT_TREE_BEGIN_DRAG  
wxEVT_TREE_BEGIN_LABEL_EDIT  
wxEVT_TREE_BEGIN_RDRAG  
wxEVT_TREE_DELETE_ITEM  
wxEVT_TREE_END_DRAG  
wxEVT_TREE_END_LABEL_EDIT  
wxEVT_TREE_GET_INFO  
wxEVT_TREE_ITEM_ACTIVATED  
wxEVT_TREE_ITEM_CHECKED  
wxEVT_TREE_ITEM_CHECKING  
wxEVT_TREE_ITEM_COLLAPSED  
wxEVT_TREE_ITEM_COLLAPSING  
wxEVT_TREE_ITEM_EXPANDED  
wxEVT_TREE_ITEM_EXPANDING  
wxEVT_TREE_ITEM_GETTOOLTIP  
wxEVT_TREE_ITEM_HYPERLINK  
wxEVT_TREE_ITEM_MENU  
wxEVT_TREE_ITEM_MIDDLE_CLICK  
wxEVT_TREE_ITEM_RIGHT_CLICK  
wxEVT_TREE_KEY_DOWN  
wxEVT_TREE_SEL_CHANGED  
wxEVT_TREE_SEL_CHANGING  
wxEVT_TREE_SET_INFO  
wxEVT_TREE_STATE_IMAGE_CLICK  

Function Details [hide private]

DrawTreeItemButton(win, dc, rect, flags)

source code 
A simple replacement of wx.RendererNative.DrawTreeItemButton.

EventFlagsToSelType(style, shiftDown=False, ctrlDown=False)

source code 
Translate the key or mouse event flag to the type of selection we are dealing with.

GetCheckedBitmap()

source code 

GetCheckedData()

source code 

GetCheckedImage()

source code 

GetFlaggedBitmap()

source code 

GetFlaggedData()

source code 

GetFlaggedImage()

source code 

GetNotCheckedBitmap()

source code 

GetNotCheckedData()

source code 

GetNotCheckedImage()

source code 

GetNotFlaggedBitmap()

source code 

GetNotFlaggedData()

source code 

GetNotFlaggedImage()

source code 

GrayOut(anImage)

source code 
Convert the given image (in place) to a grayed-out version, appropriate for a 'disabled' appearance.

MakeGray((r, g, b), factor, maskColor)

source code 
Make a pixel grayed-out. If the pixel matches the maskcolor, it won't be changed.

Variables Details [hide private]

EVT_TREE_BEGIN_DRAG

Value:
<wx._core.PyEventBinder object at 0x01A28D10>                          
      

EVT_TREE_BEGIN_LABEL_EDIT

Value:
<wx._core.PyEventBinder object at 0x01A28D50>                          
      

EVT_TREE_BEGIN_RDRAG

Value:
<wx._core.PyEventBinder object at 0x01A28D30>                          
      

EVT_TREE_DELETE_ITEM

Value:
<wx._core.PyEventBinder object at 0x01A28D90>                          
      

EVT_TREE_END_DRAG

Value:
<wx._core.PyEventBinder object at 0x01A28F30>                          
      

EVT_TREE_END_LABEL_EDIT

Value:
<wx._core.PyEventBinder object at 0x01A28D70>                          
      

EVT_TREE_GET_INFO

Value:
<wx._core.PyEventBinder object at 0x01A28DB0>                          
      

EVT_TREE_ITEM_ACTIVATED

Value:
<wx._core.PyEventBinder object at 0x01A28ED0>                          
      

EVT_TREE_ITEM_CHECKED

Value:
<wx._core.PyEventBinder object at 0x00C965F0>                          
      

EVT_TREE_ITEM_CHECKING

Value:
<wx._core.PyEventBinder object at 0x00C96430>                          
      

EVT_TREE_ITEM_COLLAPSED

Value:
<wx._core.PyEventBinder object at 0x01A28E30>                          
      

EVT_TREE_ITEM_COLLAPSING

Value:
<wx._core.PyEventBinder object at 0x01A28E50>                          
      

EVT_TREE_ITEM_EXPANDED

Value:
<wx._core.PyEventBinder object at 0x01A28DF0>                          
      

EVT_TREE_ITEM_EXPANDING

Value:
<wx._core.PyEventBinder object at 0x01A28E10>                          
      

EVT_TREE_ITEM_GETTOOLTIP

Value:
<wx._core.PyEventBinder object at 0x01A28F70>                          
      

EVT_TREE_ITEM_HYPERLINK

Value:
<wx._core.PyEventBinder object at 0x00C96730>                          
      

EVT_TREE_ITEM_MENU

Value:
<wx._core.PyEventBinder object at 0x01A28F90>                          
      

EVT_TREE_ITEM_MIDDLE_CLICK

Value:
<wx._core.PyEventBinder object at 0x01A28F10>                          
      

EVT_TREE_ITEM_RIGHT_CLICK

Value:
<wx._core.PyEventBinder object at 0x01A28EF0>                          
      

EVT_TREE_KEY_DOWN

Value:
<wx._core.PyEventBinder object at 0x01A28EB0>                          
      

EVT_TREE_SEL_CHANGED

Value:
<wx._core.PyEventBinder object at 0x01A28E70>                          
      

EVT_TREE_SEL_CHANGING

Value:
<wx._core.PyEventBinder object at 0x01A28E90>                          
      

EVT_TREE_SET_INFO

Value:
<wx._core.PyEventBinder object at 0x01A28DD0>                          
      

EVT_TREE_STATE_IMAGE_CLICK

Value:
<wx._core.PyEventBinder object at 0x01A28F50>                          
      

TREE_HITTEST_ABOVE

Value:
1                                                                     
      

TREE_HITTEST_BELOW

Value:
2                                                                     
      

TREE_HITTEST_NOWHERE

Value:
4                                                                     
      

TREE_HITTEST_ONITEM

Value:
16464                                                                 
      

TREE_HITTEST_ONITEMBUTTON

Value:
8                                                                     
      

TREE_HITTEST_ONITEMCHECKICON

Value:
16384                                                                 
      

TREE_HITTEST_ONITEMICON

Value:
16                                                                    
      

TREE_HITTEST_ONITEMINDENT

Value:
32                                                                    
      

TREE_HITTEST_ONITEMLABEL

Value:
64                                                                    
      

TREE_HITTEST_ONITEMLOWERPART

Value:
4096                                                                  
      

TREE_HITTEST_ONITEMRIGHT

Value:
128                                                                   
      

TREE_HITTEST_ONITEMSTATEICON

Value:
256                                                                   
      

TREE_HITTEST_ONITEMUPPERPART

Value:
2048                                                                  
      

TREE_HITTEST_TOLEFT

Value:
512                                                                   
      

TREE_HITTEST_TORIGHT

Value:
1024                                                                  
      

TR_AUTO_CHECK_CHILD

Value:
16384                                                                 
      

TR_AUTO_TOGGLE_CHILD

Value:
32768                                                                 
      

TR_DEFAULT_STYLE

Value:
9                                                                     
      

TR_EDIT_LABELS

Value:
512                                                                   
      

TR_EXTENDED

Value:
64                                                                    
      

TR_FULL_ROW_HIGHLIGHT

Value:
8192                                                                  
      

TR_HAS_BUTTONS

Value:
1                                                                     
      

TR_HAS_VARIABLE_ROW_HEIGHT

Value:
128                                                                   
      

TR_HIDE_ROOT

Value:
2048                                                                  
      

TR_LINES_AT_ROOT

Value:
8                                                                     
      

TR_MULTIPLE

Value:
32                                                                    
      

TR_NO_BUTTONS

Value:
0                                                                     
      

TR_NO_LINES

Value:
4                                                                     
      

TR_ROW_LINES

Value:
1024                                                                  
      

TR_SINGLE

Value:
0                                                                     
      

TR_TWIST_BUTTONS

Value:
16                                                                    
      

TreeItemIcon_Checked

Value:
0                                                                     
      

TreeItemIcon_Expanded

Value:
2                                                                     
      

TreeItemIcon_Flagged

Value:
2                                                                     
      

TreeItemIcon_Normal

Value:
0                                                                     
      

TreeItemIcon_NotChecked

Value:
1                                                                     
      

TreeItemIcon_NotFlagged

Value:
3                                                                     
      

TreeItemIcon_Selected

Value:
1                                                                     
      

TreeItemIcon_SelectedExpanded

Value:
3                                                                     
      

_CONTROL_CURRENT

Value:
16                                                                    
      

_CONTROL_EXPANDED

Value:
8                                                                     
      

_DELAY

Value:
500                                                                   
      

_NO_IMAGE

Value:
-1                                                                    
      

_PIXELS_PER_UNIT

Value:
10                                                                    
      

_StyleStretch

Value:
1                                                                     
      

_StyleTile

Value:
0                                                                     
      

__version__

Value:
'0.7'                                                                  
      

_rgbNoFocusBottom

Value:
wx.Colour(235, 235, 235)                                               
      

_rgbNoFocusInner

Value:
wx.Colour(245, 245, 245)                                               
      

_rgbNoFocusOuter

Value:
wx.Colour(220, 220, 220)                                               
      

_rgbNoFocusTop

Value:
wx.Colour(250, 250, 250)                                               
      

_rgbSelectBottom

Value:
wx.Colour(185, 215, 250)                                               
      

_rgbSelectInner

Value:
wx.Colour(230, 250, 250)                                               
      

_rgbSelectOuter

Value:
wx.Colour(170, 200, 245)                                               
      

_rgbSelectTop

Value:
wx.Colour(210, 240, 250)                                               
      

wxEVT_TREE_BEGIN_DRAG

Value:
10158                                                                 
      

wxEVT_TREE_BEGIN_LABEL_EDIT

Value:
10160                                                                 
      

wxEVT_TREE_BEGIN_RDRAG

Value:
10159                                                                 
      

wxEVT_TREE_DELETE_ITEM

Value:
10162                                                                 
      

wxEVT_TREE_END_DRAG

Value:
10175                                                                 
      

wxEVT_TREE_END_LABEL_EDIT

Value:
10161                                                                 
      

wxEVT_TREE_GET_INFO

Value:
10163                                                                 
      

wxEVT_TREE_ITEM_ACTIVATED

Value:
10172                                                                 
      

wxEVT_TREE_ITEM_CHECKED

Value:
10230                                                                 
      

wxEVT_TREE_ITEM_CHECKING

Value:
10229                                                                 
      

wxEVT_TREE_ITEM_COLLAPSED

Value:
10167                                                                 
      

wxEVT_TREE_ITEM_COLLAPSING

Value:
10168                                                                 
      

wxEVT_TREE_ITEM_EXPANDED

Value:
10165                                                                 
      

wxEVT_TREE_ITEM_EXPANDING

Value:
10166                                                                 
      

wxEVT_TREE_ITEM_GETTOOLTIP

Value:
10177                                                                 
      

wxEVT_TREE_ITEM_HYPERLINK

Value:
10231                                                                 
      

wxEVT_TREE_ITEM_MENU

Value:
10178                                                                 
      

wxEVT_TREE_ITEM_MIDDLE_CLICK

Value:
10174                                                                 
      

wxEVT_TREE_ITEM_RIGHT_CLICK

Value:
10173                                                                 
      

wxEVT_TREE_KEY_DOWN

Value:
10171                                                                 
      

wxEVT_TREE_SEL_CHANGED

Value:
10169                                                                 
      

wxEVT_TREE_SEL_CHANGING

Value:
10170                                                                 
      

wxEVT_TREE_SET_INFO

Value:
10164                                                                 
      

wxEVT_TREE_STATE_IMAGE_CLICK

Value:
10176