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()
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.
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)
(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 "\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."""
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:
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()