]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/customtreectrl.py
removed contrib files from the scripts
[wxWidgets.git] / wxPython / wx / lib / customtreectrl.py
index 8d6ad6b4d43c6d02b54ed6530622c91317368f68..3b93746092aa900b36902706c823b0ed174f01b9 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: 01 Apr 2007, 22.30 CET
 #
 #
 # TODO List
@@ -134,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 @ 01 Apr 2007, 22.30 CET
+Version 1.0
 
 """
 
@@ -924,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()
 
@@ -1321,7 +1321,7 @@ class GenericTreeItem:
         """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
 
@@ -1330,7 +1330,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)
@@ -1736,7 +1736,7 @@ def EventFlagsToSelType(style, shiftDown=False, ctrlDown=False):
 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.
@@ -1749,9 +1749,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
 
         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
@@ -1769,10 +1768,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             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
@@ -1790,7 +1793,9 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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)
 
@@ -1871,14 +1876,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._itemWithWindow = []
         
         if wx.Platform == "__WXMAC__":
-            ctstyle &= ~TR_LINES_AT_ROOT
-            ctstyle |= TR_NO_LINES
+            style &= ~TR_LINES_AT_ROOT
+            style |= TR_NO_LINES
             
             platform, major, minor = wx.GetOsVersion()
             if major < 10:
-                ctstyle |= TR_ROW_LINES
+                style |= TR_ROW_LINES
 
-        self._windowStyle = ctstyle
+        self._windowStyle = style
 
         # Create the default check image list        
         self.SetImageListCheck(13, 13)
@@ -1993,7 +1998,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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))
 
@@ -2023,7 +2028,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Enables/disables an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if item.IsEnabled() == enable:
             return
@@ -2054,7 +2059,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()        
 
@@ -2076,7 +2081,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2123,7 +2128,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # Should we raise an error here?!?        
         if item.GetType() == 0:
@@ -2173,7 +2178,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
 
@@ -2193,7 +2198,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
 
@@ -2213,7 +2218,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         Meaningful only for check items."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         parent = item.GetParent()
         if not parent or parent.GetType() != 1:
@@ -2234,7 +2239,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2270,7 +2275,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Starts editing an item label."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self.Edit(item)
 
@@ -2305,7 +2310,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
 
@@ -2314,7 +2319,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Gets the item children count."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetChildrenCount(recursively)
 
@@ -2363,16 +2368,16 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
 
@@ -2381,7 +2386,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns the data associated to an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetData()
 
@@ -2392,7 +2397,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns the item text colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetTextColour()
 
@@ -2401,7 +2406,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns the item background colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetBackgroundColour()
 
@@ -2410,7 +2415,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns the item font."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetFont()
 
@@ -2419,7 +2424,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2428,7 +2433,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2440,7 +2445,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
 
@@ -2453,7 +2458,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Sets the data associated to an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetData(data)
 
@@ -2464,7 +2469,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2474,7 +2479,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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:
@@ -2486,7 +2491,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2508,7 +2513,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if highlight:
             bg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
@@ -2523,7 +2528,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
@@ -2536,7 +2541,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2546,7 +2551,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2556,7 +2561,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Sets the item font."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if self.GetItemFont(item) == font:
             return
@@ -2621,7 +2626,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2631,7 +2636,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns whether an hypertext item was visited."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetVisited()            
 
@@ -2803,7 +2808,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns the window associated to the item (if any)."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetWindow()
 
@@ -2812,7 +2817,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2821,7 +2826,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Enables/disables the window associated to the item."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         item.SetWindowEnabled(enable)
 
@@ -2835,7 +2840,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetType()
 
@@ -2847,7 +2852,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
@@ -2880,7 +2885,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
@@ -2894,7 +2899,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2903,7 +2908,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2912,7 +2917,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2921,7 +2926,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
 
@@ -2934,7 +2939,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Gets the item parent."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetParent()
 
@@ -2943,7 +2948,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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)
@@ -2956,7 +2961,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
 
@@ -2977,7 +2982,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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]
@@ -2987,7 +2992,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
@@ -3008,7 +3013,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
@@ -3028,7 +3033,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
 
@@ -3066,7 +3071,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Returns the next visible item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         id = item
 
@@ -3081,9 +3086,9 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     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
 
@@ -3141,13 +3146,13 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            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
         
@@ -3173,16 +3178,16 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            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
 
@@ -3212,10 +3217,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            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)
 
@@ -3224,10 +3229,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            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,7 +3246,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             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)
 
@@ -3250,10 +3255,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
         
@@ -3268,10 +3273,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            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)
@@ -3283,10 +3288,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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"
+            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"
+            raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
         
@@ -3303,7 +3308,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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):
@@ -3344,7 +3349,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
 
@@ -3356,7 +3361,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
 
@@ -3433,10 +3438,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         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
@@ -3448,7 +3453,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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
     
@@ -3462,14 +3467,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             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 != self.GetRootItem():
             self.Expand(item)
@@ -3479,10 +3484,17 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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
@@ -3490,10 +3502,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         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
@@ -3501,7 +3513,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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
     
@@ -3515,7 +3527,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_COLLAPSED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def CollapseAndReset(self, item):
@@ -3576,7 +3588,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         # 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
@@ -3644,7 +3657,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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
 
@@ -3725,7 +3738,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Selects/deselects an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if select:
         
@@ -3749,7 +3762,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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)
         
@@ -3776,7 +3789,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """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()
@@ -3860,7 +3873,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
         
@@ -3956,21 +3969,22 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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):
@@ -4296,7 +4310,12 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 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)
 
         else:
 
@@ -4324,7 +4343,12 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 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,
@@ -4382,12 +4406,15 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             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 not wnd.IsShown():
                 wnd.Show()
             if wnd.GetPosition() != (wndx, ya):
@@ -4426,7 +4453,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                     # 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
         
@@ -4843,7 +4873,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                         current = self.GetItemParent(current)
                         if current:
                             next = self.GetNextSibling(current)
-                            if not self.IsEnabled(next):
+                            if not next or not self.IsEnabled(next):
                                 next = None
 
                 else:
@@ -5013,7 +5043,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Gets the bounding rectangle of the item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
     
         i = item
 
@@ -5118,7 +5148,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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:
@@ -5651,7 +5681,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         """Thaw CustomTreeCtrl."""
 
         if self._freezeCount == 0:
-            raise "\nERROR: Thawing Unfrozen Tree Control?"
+            raise Exception("\nERROR: Thawing Unfrozen Tree Control?")
 
         self._freezeCount = self._freezeCount - 1
         
@@ -5719,4 +5749,6 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         attr.font  = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
         return attr
 
+    GetClassDefaultAttributes = classmethod(GetClassDefaultAttributes)
 
+