]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/customtreectrl.py
Remove const bool
[wxWidgets.git] / wxPython / wx / lib / customtreectrl.py
index ae7b8cd69e6d73c9837cfa14f119026b6e30a03c..a33b8574ce7e6c22ae45afab45ad1cc63e6317a2 100644 (file)
@@ -3,7 +3,7 @@
 # Inspired By And Heavily Based On wxGenericTreeCtrl.
 #
 # Andrea Gavana, @ 17 May 2006
-# Latest Revision: 26 May 2006, 22.30 CET
+# Latest Revision: 16 Apr 2007, 11.00 CET
 #
 #
 # TODO List
@@ -95,8 +95,9 @@ 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:
+Plus it has 3 more styles to handle checkbox-type items:
   - TR_AUTO_CHECK_CHILD : automatically checks/unchecks the item children;
+  - TR_AUTO_CHECK_PARENT : automatically checks/unchecks the item parent;
   - TR_AUTO_TOGGLE_CHILD: automatically toggles the item children.
 
 All the methods available in wx.TreeCtrl are also available in CustomTreeCtrl.
@@ -133,8 +134,8 @@ CustomTreeCtrl has been tested on the following platforms:
   * Mac OS (Thanks to John Jackson).
 
 
-Latest Revision: Andrea Gavana @ 26 May 2006, 22.30 CET
-Version 0.8
+Latest Revision: Andrea Gavana @ 16 Apr 2007, 11.00 CET
+Version 1.0
 
 """
 
@@ -190,8 +191,9 @@ TR_HIDE_ROOT = wx.TR_HIDE_ROOT                                 # don't display r
 
 TR_FULL_ROW_HIGHLIGHT = wx.TR_FULL_ROW_HIGHLIGHT               # highlight full horz space
 
-TR_AUTO_CHECK_CHILD = 0x4000                                   # only meaningful for checkboxes
-TR_AUTO_TOGGLE_CHILD = 0x8000                                  # only meaningful for checkboxes
+TR_AUTO_CHECK_CHILD = 0x04000                                   # only meaningful for checkboxes
+TR_AUTO_TOGGLE_CHILD = 0x08000                                  # only meaningful for checkboxes
+TR_AUTO_CHECK_PARENT = 0x10000                                   # only meaningful for checkboxes
 
 TR_DEFAULT_STYLE = wx.TR_DEFAULT_STYLE                         # default style for the tree control
 
@@ -492,9 +494,9 @@ class DragImage(wx.DragImage):
         text = item.GetText()
         font = item.Attr().GetFont()
         colour = item.Attr().GetTextColour()
-        if colour is None:
+        if not colour:
             colour = wx.BLACK
-        if font is None:
+        if not font:
             font = treeCtrl._normalFont
     
         backcolour = treeCtrl.GetBackgroundColour()
@@ -922,7 +924,7 @@ class TreeTextCtrl(wx.TextCtrl):
         
             else:
         
-                raise "\n ERROR: You Must Create An Image List To Use Images!"
+                raise Exception("\n ERROR: You Must Create An Image List To Use Images!")
 
         checkimage = item.GetCurrentCheckedImage()
 
@@ -942,16 +944,12 @@ class TreeTextCtrl(wx.TextCtrl):
         x += image_w + wcheck
         w -= image_w + 4 + wcheck
 
-        if wx.Platform == "__WXMAC__":
-            bs = self.DoGetBestSize() 
-            # edit control height
-            if h > bs.y - 8:
-                diff = h - ( bs.y - 8 ) 
-                h -= diff 
-                y += diff / 2 
-
         wx.TextCtrl.__init__(self, self._owner, wx.ID_ANY, self._startValue,
                              wx.Point(x - 4, y), wx.Size(w + 15, h))
+        if wx.Platform == "__WXMAC__":
+            self.SetFont(owner.GetFont())
+            bs = self.GetBestSize()
+            self.SetSize((-1, bs.height))
         
         self.Bind(wx.EVT_CHAR, self.OnChar)
         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
@@ -1166,28 +1164,7 @@ class GenericTreeItem:
         self._wnd = wnd             # are we holding a window?
 
         if wnd:
-            if wnd.GetSizer():      # the window is a complex one hold by a sizer
-                size = wnd.GetBestSize()
-            else:                   # simple window, without sizers
-                size = wnd.GetSize()
-
-            # We have to bind the wx.EVT_SET_FOCUS for the associated window
-            # No other solution to handle the focus changing from an item in
-            # CustomTreeCtrl and the window associated to an item
-            # Do better strategies exist?
-            self._wnd.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
-            
-            self._height = size.GetHeight() + 2
-            self._width = size.GetWidth()
-            self._windowsize = size
-            
-            # We don't show the window if the item is collapsed
-            if self._isCollapsed:
-                self._wnd.Show(False)
-
-            # The window is enabled only if the item is enabled                
-            self._wnd.Enable(self._enabled)
-            self._windowenabled = self._enabled
+            self.SetWindow(wnd)
         
 
     def IsOk(self):
@@ -1312,6 +1289,29 @@ class GenericTreeItem:
 
         self._wnd = wnd
 
+        if wnd.GetSizer():      # the window is a complex one hold by a sizer
+            size = wnd.GetBestSize()
+        else:                   # simple window, without sizers
+            size = wnd.GetSize()
+
+        # We have to bind the wx.EVT_SET_FOCUS for the associated window
+        # No other solution to handle the focus changing from an item in
+        # CustomTreeCtrl and the window associated to an item
+        # Do better strategies exist?
+        self._wnd.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
+        
+        self._height = size.GetHeight() + 2
+        self._width = size.GetWidth()
+        self._windowsize = size
+        
+        # We don't show the window if the item is collapsed
+        if self._isCollapsed:
+            self._wnd.Show(False)
+
+        # The window is enabled only if the item is enabled                
+        self._wnd.Enable(self._enabled)
+        self._windowenabled = self._enabled
+
 
     def GetWindow(self):
         """Returns the window associated to the item."""
@@ -1319,11 +1319,19 @@ class GenericTreeItem:
         return self._wnd        
 
 
+    def DeleteWindow(self):
+        """Deletes the window associated to the item (if any)."""
+
+        if self._wnd:
+            self._wnd.Destroy()
+            self._wnd = None
+        
+
     def GetWindowEnabled(self):
         """Returns whether the associated window is enabled or not."""
 
         if not self._wnd:
-            raise "\nERROR: This Item Has No Window Associated"
+            raise Exception("\nERROR: This Item Has No Window Associated")
 
         return self._windowenabled
 
@@ -1332,7 +1340,7 @@ class GenericTreeItem:
         """Sets whether the associated window is enabled or not."""
 
         if not self._wnd:
-            raise "\nERROR: This Item Has No Window Associated"
+            raise Exception("\nERROR: This Item Has No Window Associated")
 
         self._windowenabled = enable
         self._wnd.Enable(enable)
@@ -1735,10 +1743,10 @@ def EventFlagsToSelType(style, shiftDown=False, ctrlDown=False):
 # This Is The Main Class.
 # -----------------------------------------------------------------------------
 
-class CustomTreeCtrl(wx.ScrolledWindow):
+class CustomTreeCtrl(wx.PyScrolledWindow):
 
     def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
-                 style=0, ctstyle=TR_DEFAULT_STYLE, validator=wx.DefaultValidator,
+                 style=TR_DEFAULT_STYLE, ctstyle=0, validator=wx.DefaultValidator,
                  name="CustomTreeCtrl"):
         """
         Default class constructor.
@@ -1751,15 +1759,14 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
         size: window size. If the default size (-1, -1) is specified then the window is sized appropriately.
 
-        style: the underlying wx.ScrolledWindow style
+        style: the underlying wx.ScrolledWindow style + CustomTreeCtrl window style. This can be one of:
         
-        ctstyle: CustomTreeCtrl window style. This can be one of:
             TR_NO_BUTTONS
             TR_HAS_BUTTONS                          # draw collapsed/expanded btns
             TR_NO_LINES                             # don't draw lines at all
             TR_LINES_AT_ROOT                        # connect top-level nodes
             TR_TWIST_BUTTONS                        # draw mac-like twist buttons
-            TR_SINGLE                               # single selection mode                           
+            TR_SINGLE                               # single selection mode     
             TR_MULTIPLE                             # can select multiple items
             TR_EXTENDED                             # todo: allow extended selection
             TR_HAS_VARIABLE_ROW_HEIGHT              # allows rows to have variable height
@@ -1768,12 +1775,17 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             TR_HIDE_ROOT                            # don't display root node
             TR_FULL_ROW_HIGHLIGHT                   # highlight full horizontal space
             TR_AUTO_CHECK_CHILD                     # only meaningful for checkboxes
+            TR_AUTO_CHECK_PARENT                    # only meaningful for checkboxes
             TR_AUTO_TOGGLE_CHILD                    # only meaningful for checkboxes
 
+        ctstyle: kept for backward compatibility.
+        
         validator: window validator.
 
         name: window name.
         """
+
+        style = style | ctstyle
         
         self._current = self._key_current = self._anchor = self._select_me = None
         self._hasFocus = False
@@ -1791,7 +1803,9 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         btnshadow = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
         self._hilightUnfocusedBrush = wx.Brush(btnshadow)
         r, g, b = btnshadow.Red(), btnshadow.Green(), btnshadow.Blue()
-        backcolour = ((r >> 1) - 20, (g >> 1) - 20, (b >> 1) - 20)
+        backcolour = (max((r >> 1) - 20, 0),
+                      max((g >> 1) - 20, 0),
+                      max((b >> 1) - 20, 0))
         backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2])
         self._hilightUnfocusedBrush2 = wx.Brush(backcolour)
 
@@ -1856,12 +1870,13 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self._vistaselection = False        
 
         # Connection lines style
+        grey = (160,160,160)
         if wx.Platform != "__WXMAC__":
-            self._dottedPen = wx.Pen("grey", 1, wx.USER_DASH)
+            self._dottedPen = wx.Pen(grey, 1, wx.USER_DASH)
             self._dottedPen.SetDashes([1,1])
             self._dottedPen.SetCap(wx.CAP_BUTT)
         else:
-            self._dottedPen = wx.Pen("grey", 1)
+            self._dottedPen = wx.Pen(grey, 1)
 
         # Pen Used To Draw The Border Around Selected Items
         self._borderPen = wx.BLACK_PEN
@@ -1872,16 +1887,12 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self._itemWithWindow = []
         
         if wx.Platform == "__WXMAC__":
+            style &= ~TR_LINES_AT_ROOT
+            style |= TR_NO_LINES
             
             platform, major, minor = wx.GetOsVersion()
-
-            ctstyle &= ~TR_LINES_AT_ROOT
-            ctstyle |= TR_NO_LINES
-            
             if major < 10:
-                ctstyle |= TR_ROW_LINES
-
-        self._windowStyle = ctstyle
+                style |= TR_ROW_LINES
 
         # Create the default check image list        
         self.SetImageListCheck(13, 13)
@@ -1894,7 +1905,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             self._drawingfunction = wx.RendererNative.Get().DrawTreeItemButton
 
         # Create our container... at last!    
-        wx.ScrolledWindow.__init__(self, parent, id, pos, size, style|wx.HSCROLL|wx.VSCROLL, name)
+        wx.PyScrolledWindow.__init__(self, parent, id, pos, size, style|wx.HSCROLL|wx.VSCROLL, name)
 
         # If the tree display has no buttons, but does have
         # connecting lines, we can use a narrower layout.
@@ -1922,7 +1933,6 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
         self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
         self.Bind(EVT_TREE_ITEM_GETTOOLTIP, self.OnGetToolTip)
-        self.Bind(wx.EVT_IDLE, self.OnInternalIdle)
         self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
 
         # Sets the focus to ourselves: this is useful if you have items
@@ -1930,6 +1940,12 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self.SetFocus()
 
 
+    def AcceptsFocus(self):
+        # overridden base class method, allows this ctrl to
+        # participate in the tab-order, etc.  It's overridable because
+        # of deriving this class from wx.PyScrolledWindow...
+        return True
+    
 
     def OnDestroy(self, event):
         """Handles the wx.EVT_WINDOW_DESTROY event."""
@@ -1991,7 +2007,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Toggles the item selection."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self.SelectItem(item, not self.IsSelected(item))
 
@@ -2021,7 +2037,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Enables/disables an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if item.IsEnabled() == enable:
             return
@@ -2048,11 +2064,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             self.RefreshLine(item)
                 
 
-    def IsEnabled(self, item):
+    def IsItemEnabled(self, item):
         """Returns whether an item is enabled or disabled."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         return item.IsEnabled()        
 
@@ -2074,7 +2090,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an item is checked or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "        
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsChecked()
 
@@ -2104,7 +2120,6 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             return False
 
         item.Check(checked)
-        dc = wx.ClientDC(self)
         self.RefreshLine(item)
         self.EnableChildren(item, checked)
         e = TreeEvent(wxEVT_TREE_ITEM_CHECKED, self.GetId())
@@ -2122,7 +2137,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # Should we raise an error here?!?        
         if item.GetType() == 0:
@@ -2153,10 +2168,13 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         dc = wx.ClientDC(self)
         self.RefreshLine(item)
 
-        if self._windowStyle & TR_AUTO_CHECK_CHILD:
+        if self.HasFlag(TR_AUTO_CHECK_CHILD):
             ischeck = self.IsItemChecked(item)
             self.AutoCheckChild(item, ischeck)
-        elif self._windowStyle & TR_AUTO_TOGGLE_CHILD:
+        if self.HasFlag(TR_AUTO_CHECK_PARENT):
+            ischeck = self.IsItemChecked(item)
+            self.AutoCheckParent(item, ischeck)
+        elif self.HasFlag(TR_AUTO_TOGGLE_CHILD):
             self.AutoToggleChild(item)
 
         e = TreeEvent(wxEVT_TREE_ITEM_CHECKED, self.GetId())
@@ -2169,7 +2187,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Transverses the tree and toggles the items. Meaningful only for check items."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         child, cookie = self.GetFirstChild(item)
 
@@ -2189,7 +2207,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Transverses the tree and checks/unchecks the items. Meaningful only for check items."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         (child, cookie) = self.GetFirstChild(item)
 
@@ -2204,11 +2222,33 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             (child, cookie) = self.GetNextChild(item, cookie)
 
 
+    def AutoCheckParent(self, item, checked):
+        """Traverses up the tree and checks/unchecks parent items.
+        Meaningful only for check items."""
+
+        if not item:
+            raise Exception("\nERROR: Invalid Tree Item. ")
+
+        parent = item.GetParent()
+        if not parent or parent.GetType() != 1:
+            return
+
+        (child, cookie) = self.GetFirstChild(parent)
+        while child:
+            if child.GetType() == 1 and child.IsEnabled():
+                if checked != child.IsChecked():
+                    return
+            (child, cookie) = self.GetNextChild(parent, cookie)
+
+        self.CheckItem2(parent, checked, torefresh=True)
+        self.AutoCheckParent(parent, checked)
+
+
     def CheckChilds(self, item, checked=True):
         """Programatically check/uncheck item children. Does not generate EVT_TREE_CHECK* events."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if checked == None:
             self.AutoToggleChild(item)
@@ -2244,7 +2284,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Starts editing an item label."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self.Edit(item)
 
@@ -2269,17 +2309,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self._dirty = True
 
 
-    def HasFlag(self, flag):
-        """Returns whether CustomTreeCtrl has a flag."""
-
-        return self._windowStyle & flag
-    
-
     def HasChildren(self, item):
         """Returns whether an item has children or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         return len(item.GetChildren()) > 0
 
@@ -2288,7 +2322,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item children count."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetChildrenCount(recursively)
 
@@ -2308,19 +2342,19 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         # want to update the inherited styles, but right now
         # none of the parents has updatable styles
 
-        if self._windowStyle & TR_MULTIPLE and not (styles & TR_MULTIPLE):
+        if self.HasFlag(TR_MULTIPLE) and not (styles & TR_MULTIPLE):
             selections = self.GetSelections()
             for select in selections[0:-1]:
                 self.SelectItem(select, False)
 
-        self._windowStyle = styles
+        self.SetWindowStyle(styles)
         self._dirty = True
 
 
     def GetTreeStyle(self):
         """Returns the CustomTreeCtrl style."""
 
-        return self._windowStyle
+        return self.GetWindowStyle()
     
 
     def HasButtons(self):
@@ -2337,16 +2371,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item text."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetText()
     
 
-    def GetItemImage(self, item, which):
+    def GetItemImage(self, item, which=TreeItemIcon_Normal):
         """Returns the item image."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetImage(which)
 
@@ -2355,7 +2389,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the data associated to an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetData()
 
@@ -2366,7 +2400,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item text colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetTextColour()
 
@@ -2375,7 +2409,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item background colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetBackgroundColour()
 
@@ -2384,7 +2418,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item font."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetFont()
 
@@ -2393,7 +2427,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an item is hypertext or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         return item.IsHyperText()
 
@@ -2402,7 +2436,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item text."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         dc = wx.ClientDC(self)
         item.SetText(text)
@@ -2414,7 +2448,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item image, depending on the item state."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetImage(image, which)
 
@@ -2427,7 +2461,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the data associated to an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetData(data)
 
@@ -2438,7 +2472,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Forces the appearance of the button next to the item."""
         
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetHasPlus(has)
         self.RefreshLine(item)
@@ -2448,7 +2482,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item font bold/unbold."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         # avoid redrawing the tree if no real change
         if item.IsBold() != bold:
@@ -2460,7 +2494,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item font italic/non-italic."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if item.IsItalic() != italic:
             itemFont = self.GetItemFont(item)
@@ -2482,7 +2516,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if highlight:
             bg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
@@ -2497,7 +2531,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item text colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if self.GetItemTextColour(item) == col:
             return
@@ -2510,7 +2544,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item background colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.Attr().SetBackgroundColour(col)
         self.RefreshLine(item)
@@ -2520,7 +2554,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets whether the item is hypertext or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "        
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetHyperText(hyper)
         self.RefreshLine(item)
@@ -2530,7 +2564,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item font."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if self.GetItemFont(item) == font:
             return
@@ -2595,7 +2629,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets whether an hypertext item was visited."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         item.SetVisited(visited)
         self.RefreshLine(item)
@@ -2605,7 +2639,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an hypertext item was visited."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetVisited()            
 
@@ -2777,7 +2811,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the window associated to the item (if any)."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetWindow()
 
@@ -2786,7 +2820,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the window associated to the item is enabled."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetWindowEnabled()
 
@@ -2795,7 +2829,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Enables/disables the window associated to the item."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         item.SetWindowEnabled(enable)
 
@@ -2809,7 +2843,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetType()
 
@@ -2821,7 +2855,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item is visible or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # An item is only visible if it's not a descendant of a collapsed item
         parent = item.GetParent()
@@ -2854,7 +2888,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item has children or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # consider that the item does have children if it has the "+" button: it
         # might not have them (if it had never been expanded yet) but then it
@@ -2868,7 +2902,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item is expanded or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsExpanded()
 
@@ -2877,7 +2911,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item is selected or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsSelected()
 
@@ -2886,7 +2920,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item font is bold or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsBold()
 
@@ -2895,7 +2929,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item font is italic or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsItalic()
 
@@ -2908,7 +2942,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item parent."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetParent()
 
@@ -2917,7 +2951,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item first child."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         cookie = 0
         return self.GetNextChild(item, cookie)
@@ -2930,7 +2964,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
 
@@ -2951,7 +2985,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item last child."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
         return (len(children) == 0 and [None] or [children[-1]])[0]
@@ -2961,7 +2995,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the next sibling of an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         i = item
         parent = i.GetParent()
@@ -2982,7 +3016,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the previous sibling of an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         i = item
         parent = i.GetParent()
@@ -3002,7 +3036,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the next item. Only for internal use right now."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         i = item
 
@@ -3040,7 +3074,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the next visible item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         id = item
 
@@ -3055,9 +3089,9 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def GetPrevVisible(self, item):
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
-        raise "\nERROR: Not Implemented"
+        raise Exception("\nERROR: Not Implemented")
 
         return None
 
@@ -3114,14 +3148,14 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def DoInsertItem(self, parentId, previous, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Actually inserts an item in the tree."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
         if ct_type < 0 or ct_type > 2:
-            raise "\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). "
+            raise Exception("\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). ")
         
         parent = parentId
         
@@ -3147,16 +3181,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Adds a root to the CustomTreeCtrl. Only one root must exist."""
 
         if self._anchor:
-            raise "\nERROR: Tree Can Have Only One Root"
+            raise Exception("\nERROR: Tree Can Have Only One Root")
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
         if ct_type < 0 or ct_type > 2:
-            raise "\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). "
+            raise Exception("\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). ")
 
         self._dirty = True     # do this first so stuff below doesn't cause flicker
 
@@ -3185,11 +3219,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def PrependItem(self, parent, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Appends an item as a first child of parent."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         return self.DoInsertItem(parent, 0, text, ct_type, wnd, image, selImage, data)
 
@@ -3197,11 +3231,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def InsertItemByItem(self, parentId, idPrevious, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Auxiliary function to cope with the C++ hideous multifunction."""
         
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
         
@@ -3215,7 +3249,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             try:
                 index = parent.GetChildren().index(idPrevious)
             except:
-                raise "ERROR: Previous Item In CustomTreeCtrl.InsertItem() Is Not A Sibling"
+                raise Exception("ERROR: Previous Item In CustomTreeCtrl.InsertItem() Is Not A Sibling")
 
         return self.DoInsertItem(parentId, index+1, text, ct_type, wnd, image, selImage, data)
 
@@ -3223,11 +3257,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def InsertItemByIndex(self, parentId, before, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Auxiliary function to cope with the C++ hideous multifunction."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
         
@@ -3241,11 +3275,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def InsertItem(self, parentId, input, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Inserts an item after the given previous."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         if type(input) == type(1):
             return self.InsertItemByIndex(parentId, input, text, ct_type, wnd, image, selImage, data)
@@ -3256,11 +3290,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def AppendItem(self, parentId, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Appends an item as a last child of its parent."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT"
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
         
@@ -3277,7 +3311,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         event = TreeEvent(wxEVT_TREE_DELETE_ITEM, self.GetId())
         event._item = item
         event.SetEventObject(self)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def IsDescendantOf(self, parent, item):
@@ -3318,7 +3352,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Delete item children."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self._dirty = True     # do this first so stuff below doesn't cause flicker
 
@@ -3330,7 +3364,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Delete an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self._dirty = True     # do this first so stuff below doesn't cause flicker
 
@@ -3407,10 +3441,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if self.HasFlag(TR_HIDE_ROOT) and item == self.GetRootItem():
-             raise "\nERROR: Can't Expand An Hidden Root. "
+             raise Exception("\nERROR: Can't Expand An Hidden Root. ")
 
         if not item.HasPlus():
             return
@@ -3422,7 +3456,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         event._item = item
         event.SetEventObject(self)
 
-        if self.ProcessEvent(event) and not event.IsAllowed():
+        if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed():
             # cancelled by program
             return
     
@@ -3436,16 +3470,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_EXPANDED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
-    def ExpandAll(self, item):
-        """Expands all the items."""
+    def ExpandAllChildren(self, item):
+        """Expands all the items children of the input item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
-        if not self.HasFlag(TR_HIDE_ROOT) or item != GetRootItem():
+        if not self.HasFlag(TR_HIDE_ROOT) or item != self.GetRootItem():
             self.Expand(item)
             if not self.IsExpanded(item):
                 return
@@ -3453,10 +3487,17 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         child, cookie = self.GetFirstChild(item)
         
         while child:
-            self.ExpandAll(child)
+            self.ExpandAllChildren(child)
             child, cookie = self.GetNextChild(item, cookie)
         
 
+    def ExpandAll(self):
+        """Expands all CustomTreeCtrl items."""
+
+        if self._anchor:
+            self.ExpandAllChildren(self._anchor)
+            
+
     def Collapse(self, item):
         """
         Collapse an item, sending a EVT_TREE_ITEM_COLLAPSING and
@@ -3464,10 +3505,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if self.HasFlag(TR_HIDE_ROOT) and item == self.GetRootItem():
-             raise "\nERROR: Can't Collapse An Hidden Root. "
+             raise Exception("\nERROR: Can't Collapse An Hidden Root. ")
 
         if not item.IsExpanded():
             return
@@ -3475,7 +3516,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         event = TreeEvent(wxEVT_TREE_ITEM_COLLAPSING, self.GetId())
         event._item = item
         event.SetEventObject(self)
-        if self.ProcessEvent(event) and not event.IsAllowed():
+        if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed():
             # cancelled by program
             return
     
@@ -3489,7 +3530,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_COLLAPSED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def CollapseAndReset(self, item):
@@ -3514,7 +3555,8 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         for child in self._itemWithWindow:
             if not self.IsVisible(child):
                 wnd = child.GetWindow()
-                wnd.Hide()
+                if wnd:
+                    wnd.Hide()
             
 
     def Unselect(self):
@@ -3550,7 +3592,8 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         # the tree might not have the root item at all
         if rootItem:
             self.UnselectAllChildren(rootItem)
-        
+
+        self.Unselect()        
 
     # Recursive function !
     # To stop we must have crt_item<last_item
@@ -3618,7 +3661,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Actually selects/unselects an item, sending a EVT_TREE_SEL_CHANGED event."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         self._select_me = None
 
@@ -3699,7 +3742,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Selects/deselects an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if select:
         
@@ -3723,7 +3766,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         if item.IsSelected():
             array.append(item)
 
-        if item.HasChildren():    
+        if item.HasChildren() and item.IsExpanded():
             for child in item.GetChildren():
                 array = self.FillArray(child, array)
         
@@ -3750,7 +3793,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Ensure that an item is visible in CustomTreeCtrl."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # first expand all parent branches
         parent = item.GetParent()
@@ -3834,7 +3877,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
         
@@ -3930,21 +3973,22 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self._imageListNormal = imageList
         self._ownsImageListNormal = False
         self._dirty = True
+        
         # Don't do any drawing if we're setting the list to NULL,
         # since we may be in the process of deleting the tree control.
         if imageList:
             self.CalculateLineHeight()
 
-        # We gray out the image list to use the grayed icons with disabled items
-        self._grayedImageList = wx.ImageList(16, 16, True, 0)
-        
-        for ii in xrange(imageList.GetImageCount()):
-            
-            bmp = imageList.GetBitmap(ii)
-            image = wx.ImageFromBitmap(bmp)
-            image = GrayOut(image)
-            newbmp = wx.BitmapFromImage(image)
-            self._grayedImageList.Add(newbmp)
+            # We gray out the image list to use the grayed icons with disabled items
+            sz = imageList.GetSize(0)
+            self._grayedImageList = wx.ImageList(sz[0], sz[1], True, 0)
+
+            for ii in xrange(imageList.GetImageCount()):
+                bmp = imageList.GetBitmap(ii)
+                image = wx.ImageFromBitmap(bmp)
+                image = GrayOut(image)
+                newbmp = wx.BitmapFromImage(image)
+                self._grayedImageList.Add(newbmp)
         
 
     def SetStateImageList(self, imageList):
@@ -4056,9 +4100,8 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def DrawVerticalGradient(self, dc, rect, hasfocus):
         """Gradient fill from colour 1 to colour 2 from top to bottom."""
 
-        dc.DrawRectangleRect(rect)
-        border = self._borderPen.GetWidth()
-        
+        oldpen = dc.GetPen()
+        oldbrush = dc.GetBrush()
         dc.SetPen(wx.TRANSPARENT_PEN)
 
         # calculate gradient coefficients
@@ -4080,21 +4123,25 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
         rf, gf, bf = 0, 0, 0
         
-        for y in xrange(rect.y+border, rect.y + rect.height-border):
+        for y in xrange(rect.y, rect.y + rect.height):
             currCol = (r1 + rf, g1 + gf, b1 + bf)                
             dc.SetBrush(wx.Brush(currCol, wx.SOLID))
-            dc.DrawRectangle(rect.x+border, y, rect.width-2*border, 1)
+            dc.DrawRectangle(rect.x, y, rect.width, 1)
             rf = rf + rstep
             gf = gf + gstep
             bf = bf + bstep
         
+        dc.SetPen(oldpen)
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.DrawRectangleRect(rect)
+        dc.SetBrush(oldbrush)
+
 
     def DrawHorizontalGradient(self, dc, rect, hasfocus):
         """Gradient fill from colour 1 to colour 2 from left to right."""
 
-        dc.DrawRectangleRect(rect)
-        border = self._borderPen.GetWidth()
-        
+        oldpen = dc.GetPen()
+        oldbrush = dc.GetBrush()
         dc.SetPen(wx.TRANSPARENT_PEN)
 
         # calculate gradient coefficients
@@ -4116,15 +4163,20 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         bstep = float((b2 - b1)) / flrect
 
         rf, gf, bf = 0, 0, 0
-        
-        for x in xrange(rect.x+border, rect.x + rect.width-border):
+
+        for x in xrange(rect.x, rect.x + rect.width):
             currCol = (int(r1 + rf), int(g1 + gf), int(b1 + bf))
             dc.SetBrush(wx.Brush(currCol, wx.SOLID))
-            dc.DrawRectangle(x, rect.y+border, 1, rect.height-2*border)
+            dc.DrawRectangle(x, rect.y, 1, rect.height)
             rf = rf + rstep
             gf = gf + gstep
             bf = bf + bstep
-            
+
+        dc.SetPen(oldpen)
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.DrawRectangleRect(rect)
+        dc.SetBrush(oldbrush)
+        
 
     def DrawVistaRectangle(self, dc, rect, hasfocus):
         """Draw the selected item(s) with the Windows Vista style."""
@@ -4146,18 +4198,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         oldpen = dc.GetPen()
         oldbrush = dc.GetBrush()
 
-        dc.SetBrush(wx.TRANSPARENT_BRUSH)
-        dc.SetPen(wx.Pen(outer))
-        dc.DrawRoundedRectangleRect(rect, 3)
-        rect.Deflate(1, 1)
-        dc.SetPen(wx.Pen(inner))
-        dc.DrawRoundedRectangleRect(rect, 2)
-        rect.Deflate(1, 1)
-
+        bdrRect = wx.Rect(*rect.Get())
+        filRect = wx.Rect(*rect.Get())
+        filRect.Deflate(1,1)
+        
         r1, g1, b1 = int(top.Red()), int(top.Green()), int(top.Blue())
         r2, g2, b2 = int(bottom.Red()), int(bottom.Green()), int(bottom.Blue())
 
-        flrect = float(rect.height)
+        flrect = float(filRect.height)
+        if flrect < 1:
+            flrect = self._lineHeight
 
         rstep = float((r2 - r1)) / flrect
         gstep = float((g2 - g1)) / flrect
@@ -4166,14 +4216,21 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         rf, gf, bf = 0, 0, 0
         dc.SetPen(wx.TRANSPARENT_PEN)
         
-        for y in xrange(rect.y, rect.y + rect.height):
+        for y in xrange(filRect.y, filRect.y + filRect.height):
             currCol = (r1 + rf, g1 + gf, b1 + bf)
             dc.SetBrush(wx.Brush(currCol, wx.SOLID))
-            dc.DrawRectangle(rect.x, y, rect.width, 1)
+            dc.DrawRectangle(filRect.x, y, filRect.width, 1)
             rf = rf + rstep
             gf = gf + gstep
             bf = bf + bstep
         
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.SetPen(wx.Pen(outer))
+        dc.DrawRoundedRectangleRect(bdrRect, 3)
+        bdrRect.Deflate(1, 1)
+        dc.SetPen(wx.Pen(inner))
+        dc.DrawRoundedRectangleRect(bdrRect, 2)
+
         dc.SetPen(oldpen)
         dc.SetBrush(oldbrush)
 
@@ -4193,7 +4250,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 dc.SetTextForeground(self.GetHyperTextVisitedColour())
             else:
                 dc.SetTextForeground(self.GetHyperTextNewColour())
-
+                    
         text_w, text_h, dummy = dc.GetMultiLineTextExtent(item.GetText())
 
         image = item.GetCurrentImage()
@@ -4219,7 +4276,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
         total_h = self.GetLineHeight(item)
         drawItemBackground = False
-
+            
         if item.IsSelected():
         
             # under mac selections are only a rectangle in case they don't have the focus
@@ -4243,13 +4300,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             dc.SetPen(wx.TRANSPARENT_PEN)
         
         offset = (self.HasFlag(TR_ROW_LINES) and [1] or [0])[0]
-
+        
         if self.HasFlag(TR_FULL_ROW_HIGHLIGHT):
-
-            oldpen = dc.GetPen()
-            dc.SetPen(wx.TRANSPARENT_PEN)
             x = 0
-            w, h = self.GetSize()
+            w, h = self.GetClientSize()
 
             itemrect = wx.Rect(x, item.GetY()+offset, w, total_h-offset)
             
@@ -4262,13 +4316,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 elif self._vistaselection:
                     self.DrawVistaRectangle(dc, itemrect, self._hasFocus)
                 else:
-                    dc.DrawRectangleRect(itemrect)
-
-            dc.SetPen(oldpen)
-        
+                    if wx.Platform in ["__WXGTK2__", "__WXMAC__"]:
+                        flags = wx.CONTROL_SELECTED
+                        if self._hasFocus: flags = flags | wx.CONTROL_FOCUSED
+                        wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) 
+                    else:
+                        dc.DrawRectangleRect(itemrect)
+                
         else:
-        
-            if item.IsSelected() and image != _NO_IMAGE:
+
+            if item.IsSelected():
             
                 # If it's selected, and there's an image, then we should
                 # take care to leave the area under the image painted in the
@@ -4279,9 +4336,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 if wnd:
                     wndx, wndy = item.GetWindowSize()
 
-                itemrect = wx.Rect(item.GetX() + wcheck + image_w - 2, item.GetY()+offset,
-                                   item.GetWidth() - image_w - wcheck + 2 - wndx, total_h-offset)
-                
+                itemrect = wx.Rect(item.GetX() + wcheck + image_w - 2,
+                                   item.GetY()+offset,
+                                   item.GetWidth() - image_w - wcheck + 2 - wndx,
+                                   total_h-offset)
+
                 if self._usegradients:
                     if self._gradientstyle == 0:   # Horizontal
                         self.DrawHorizontalGradient(dc, itemrect, self._hasFocus)
@@ -4290,7 +4349,12 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 elif self._vistaselection:
                     self.DrawVistaRectangle(dc, itemrect, self._hasFocus)
                 else:
-                    dc.DrawRectangleRect(itemrect)
+                    if wx.Platform in ["__WXGTK2__", "__WXMAC__"]:
+                        flags = wx.CONTROL_SELECTED
+                        if self._hasFocus: flags = flags | wx.CONTROL_FOCUSED
+                        wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) 
+                    else:
+                        dc.DrawRectangleRect(itemrect)
                             
             # On GTK+ 2, drawing a 'normal' background is wrong for themes that
             # don't allow backgrounds to be customized. Not drawing the background,
@@ -4298,7 +4362,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             elif drawItemBackground:
 
                 minusicon = wcheck + image_w - 2
-                itemrect = wx.Rect(item.GetX()+minusicon, item.GetY()+offset, item.GetWidth()-minusicon, total_h-offset)
+                itemrect = wx.Rect(item.GetX()+minusicon,
+                                   item.GetY()+offset,
+                                   item.GetWidth()-minusicon,
+                                   total_h-offset)
                                 
                 if self._usegradients and self._hasFocus:
                     if self._gradientstyle == 0:   # Horizontal
@@ -4345,12 +4412,18 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             dc.DrawLabel(item.GetText(), textrect)
             dc.SetTextForeground(foreground)
         else:
+            if wx.Platform == "__WXMAC__" and item.IsSelected() and self._hasFocus:
+                dc.SetTextForeground(wx.WHITE)
             dc.DrawLabel(item.GetText(), textrect)
 
         wnd = item.GetWindow()
         if wnd:
             wndx = wcheck + image_w + item.GetX() + text_w + 4
             xa, ya = self.CalcScrolledPosition((0, item.GetY()))
+            wndx += xa
+            if item.GetHeight() > item.GetWindowSize()[1]:
+                ya += (item.GetHeight() - item.GetWindowSize()[1])/2
+                
             if not wnd.IsShown():
                 wnd.Show()
             if wnd.GetPosition() != (wndx, ya):
@@ -4389,7 +4462,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                     # draw line down to last child
                     origY += self.GetLineHeight(children[0])>>1
                     oldY += self.GetLineHeight(children[n-1])>>1
+                    oldPen = dc.GetPen()
+                    dc.SetPen(self._dottedPen)
                     dc.DrawLine(3, origY, 3, oldY)
+                    dc.SetPen(oldPen)
                 
             return y
         
@@ -4483,7 +4559,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                     
                 else: # no custom buttons
 
-                    if self._windowStyle & TR_TWIST_BUTTONS:
+                    if self.HasFlag(TR_TWIST_BUTTONS):
                         # We draw something like the Mac twist buttons
                         
                         dc.SetPen(wx.BLACK_PEN)
@@ -4675,11 +4751,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         keyCode = event.GetKeyCode()
 
         if keyCode in [ord("+"), wx.WXK_ADD]:       # "+"
-            if self._current.HasPlus() and not self.IsExpanded(self._current) and self.IsEnabled(self._current):
+            if self._current.HasPlus() and not self.IsExpanded(self._current) and self.IsItemEnabled(self._current):
                 self.Expand(self._current)
                 
         elif keyCode in [ord("*"), wx.WXK_MULTIPLY]:  # "*"
-            if not self.IsExpanded(self._current) and self.IsEnabled(self._current):
+            if not self.IsExpanded(self._current) and self.IsItemEnabled(self._current):
                 # expand all
                 self.ExpandAll(self._current)
 
@@ -4699,7 +4775,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 
         elif keyCode in [wx.WXK_RETURN, wx.WXK_SPACE]:
 
-            if not self.IsEnabled(self._current):
+            if not self.IsItemEnabled(self._current):
                 event.Skip()
                 return
             
@@ -4732,7 +4808,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 if prev:
                     current = self._key_current
                     # TODO: Huh?  If we get here, we'd better be the first child of our parent.  How else could it be?
-                    if current == self.GetFirstChild(prev)[0] and self.IsEnabled(prev):
+                    if current == self.GetFirstChild(prev)[0] and self.IsItemEnabled(prev):
                         # otherwise we return to where we came from
                         self.DoSelectItem(prev, unselect_others, extended_select)
                         self._key_current = prev
@@ -4748,13 +4824,13 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                         current = prev
                 
                 # Try to get the previous siblings and see if they are active
-                while prev and not self.IsEnabled(prev):
+                while prev and not self.IsItemEnabled(prev):
                     prev = self.GetPrevSibling(prev)
 
                 if not prev:
                     # No previous siblings active: go to the parent and up
                     prev = self.GetItemParent(current)
-                    while prev and not self.IsEnabled(prev):
+                    while prev and not self.IsItemEnabled(prev):
                         prev = self.GetItemParent(prev)
                         
                 if prev:
@@ -4772,7 +4848,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             if self.IsExpanded(self._current):
                 self.Collapse(self._current)
             else:
-                if prev and self.IsEnabled(prev):
+                if prev and self.IsItemEnabled(prev):
                     self.DoSelectItem(prev, unselect_others, extended_select)
                 
         elif keyCode == wx.WXK_RIGHT:
@@ -4780,7 +4856,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             # also expand the item if it wasn't expanded yet
             if self.IsExpanded(self._current) and self.HasChildren(self._current):
                 child, cookie = self.GetFirstChild(self._key_current)
-                if self.IsEnabled(child):
+                if self.IsItemEnabled(child):
                     self.DoSelectItem(child, unselect_others, extended_select)
                     self._key_current = child
             else:
@@ -4806,11 +4882,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                         current = self.GetItemParent(current)
                         if current:
                             next = self.GetNextSibling(current)
-                            if not self.IsEnabled(next):
+                            if not next or not self.IsItemEnabled(next):
                                 next = None
 
                 else:
-                    while next and not self.IsEnabled(next):
+                    while next and not self.IsItemEnabled(next):
                         next = self.GetNext(next)
                     
                 if next:
@@ -4835,7 +4911,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
                 last = lastChild
             
-            if last and self.IsEnabled(last):
+            if last and self.IsItemEnabled(last):
             
                 self.DoSelectItem(last, unselect_others, extended_select)
                 
@@ -4852,7 +4928,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 if not prev:
                     return
 
-            if self.IsEnabled(prev):
+            if self.IsItemEnabled(prev):
                 self.DoSelectItem(prev, unselect_others, extended_select)
         
         else:
@@ -4869,7 +4945,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                     # no such item
                     return
 
-                if self.IsEnabled(id):                
+                if self.IsItemEnabled(id):                
                     self.SelectItem(id)
                 self._findPrefix += ch
 
@@ -4901,7 +4977,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
             while 1:
                 child = sibling(item)
-                if (child and self.IsEnabled(child)) or not child:
+                if (child and self.IsItemEnabled(child)) or not child:
                     break
                 item = child
 
@@ -4909,10 +4985,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             # Tha's not a radiobutton... but some of its children can be
             # inactive
             child, cookie = self.GetFirstChild(item)
-            while child and not self.IsEnabled(child):
+            while child and not self.IsItemEnabled(child):
                 child, cookie = self.GetNextChild(item, cookie)
                 
-        if child and self.IsEnabled(child):
+        if child and self.IsItemEnabled(child):
             return child
             
         return None
@@ -4966,7 +5042,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             flags = TREE_HITTEST_NOWHERE
             return None, flags
 
-        if not self.IsEnabled(hit):
+        if not self.IsItemEnabled(hit):
             return None, flags
 
         return hit, flags
@@ -4976,7 +5052,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the bounding rectangle of the item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
     
         i = item
 
@@ -5081,7 +5157,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         underMouse = thisItem
         underMouseChanged = underMouse != self._underMouse
 
-        if underMouse and (flags & TREE_HITTEST_ONITEMBUTTON) and not event.LeftIsDown() and \
+        if underMouse and (flags & TREE_HITTEST_ONITEM) and not event.LeftIsDown() and \
            not self._isDragging and (not self._renameTimer or not self._renameTimer.IsRunning()):
             underMouse = underMouse
         else:
@@ -5404,7 +5480,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                         self.Toggle(item)
                         
 
-    def OnInternalIdle(self, event):
+    def OnInternalIdle(self):
         """Performs operations in idle time (essentially drawing)."""
 
         # Check if we need to select the root item
@@ -5485,6 +5561,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             item.SetHeight(total_h)
         else:
             item.SetWidth(item.GetWindowSize()[0]+image_w+text_w+wcheck+2)
+            item.SetHeight(max(total_h, item.GetWindowSize()[1]))
 
 
     def CalculateLevel(self, item, dc, level, y):
@@ -5614,7 +5691,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Thaw CustomTreeCtrl."""
 
         if self._freezeCount == 0:
-            raise "\nERROR: Thawing Unfrozen Tree Control?"
+            raise Exception("\nERROR: Thawing Unfrozen Tree Control?")
 
         self._freezeCount = self._freezeCount - 1
         
@@ -5682,4 +5759,6 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         attr.font  = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
         return attr
 
+    GetClassDefaultAttributes = classmethod(GetClassDefaultAttributes)
 
+