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.
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
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()
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()
"""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
"""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)
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
validator: window validator.
"""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))
"""Enables/disables an item."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
if item.IsEnabled() == enable:
return
"""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()
"""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()
"""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
# Should we raise an error here?!?
if item.GetType() == 0:
if self._windowStyle & TR_AUTO_CHECK_CHILD:
ischeck = self.IsItemChecked(item)
self.AutoCheckChild(item, ischeck)
+ if self._windowStyle & TR_AUTO_CHECK_PARENT:
+ ischeck = self.IsItemChecked(item)
+ self.AutoCheckParent(item, ischeck)
elif self._windowStyle & TR_AUTO_TOGGLE_CHILD:
self.AutoToggleChild(item)
"""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)
"""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)
(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)
"""Starts editing an item label."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
self.Edit(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
"""Gets the item children count."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.GetChildrenCount(recursively)
"""Returns the item text."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.GetText()
"""Returns the item image."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.GetImage(which)
"""Returns the data associated to an item."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.GetData()
"""Returns the item text colour."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.Attr().GetTextColour()
"""Returns the item background colour."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.Attr().GetBackgroundColour()
"""Returns the item font."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.Attr().GetFont()
"""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()
"""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)
"""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)
"""Sets the data associated to an item."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
item.SetData(data)
"""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)
"""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:
"""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)
"""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
if highlight:
bg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
"""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
"""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)
"""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)
"""Sets the item font."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
if self.GetItemFont(item) == font:
return
"""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)
"""Returns whether an hypertext item was visited."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.GetVisited()
"""Returns the window associated to the item (if any)."""
if not item:
- raise "\nERROR: Invalid Item"
+ raise Exception("\nERROR: Invalid Item")
return item.GetWindow()
"""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()
"""Enables/disables the window associated to the item."""
if not item:
- raise "\nERROR: Invalid Item"
+ raise Exception("\nERROR: Invalid Item")
item.SetWindowEnabled(enable)
"""
if not item:
- raise "\nERROR: Invalid Item"
+ raise Exception("\nERROR: Invalid Item")
return item.GetType()
"""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()
"""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
"""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()
"""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()
"""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()
"""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()
"""Gets the item parent."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
return item.GetParent()
"""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)
"""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
children = item.GetChildren()
"""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]
"""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()
"""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()
"""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
"""Returns the next visible item."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
id = item
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
"""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
"""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
"""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)
"""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
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)
"""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
"""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)
"""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
"""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
"""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
"""
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
"""Expands all the items."""
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
"""
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
"""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
"""Selects/deselects an item."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
if select:
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)
"""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()
"""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
children = item.GetChildren()
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:
-
- 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
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,
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()
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:
"""Gets the bounding rectangle of the item."""
if not item:
- raise "\nERROR: Invalid Tree Item. "
+ raise Exception("\nERROR: Invalid Tree Item. ")
i = item
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:
"""Thaw CustomTreeCtrl."""
if self._freezeCount == 0:
- raise "\nERROR: Thawing Unfrozen Tree Control?"
+ raise Exception("\nERROR: Thawing Unfrozen Tree Control?")
self._freezeCount = self._freezeCount - 1