CustomTreeCtrl feature request and patch
Frank Niessink
frank at niessink.com
Thu Nov 2 12:35:51 PST 2006
Hi Andrea, Robin,
CustomTreeCtrl is great. I'm using the TR_AUTO_CHECK_CHILD style so that =
subcategories are checked automatically when a parent category is =
checked. What would also be handy is an additional style that (un)checks =
a parent when all children are (un)checked, i.e. TR_AUTO_CHECK_PARENT. =
The patch attached is my proposal for that additional style.
Please let me know what you think.
Cheers, Frank
-------------- next part --------------
Index: customtreectrl.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/wxPython/wx/lib/customtreectrl=
.py,v
retrieving revision 1.5
diff -r1.5 customtreectrl.py
98c98
< Plus it has 2 more styles to handle checkbox-type items:
---
> Plus it has 3 more styles to handle checkbox-type items:
99a100
> - TR_AUTO_CHECK_PARENT : automatically checks/unchecks the item parent;
193,194c194,196
< TR_AUTO_CHECK_CHILD =3D 0x4000 # only m=
eaningful for checkboxes
< TR_AUTO_TOGGLE_CHILD =3D 0x8000 # only m=
eaningful for checkboxes
---
> TR_AUTO_CHECK_CHILD =3D 0x04000 # only =
meaningful for checkboxes
> TR_AUTO_TOGGLE_CHILD =3D 0x08000 # only =
meaningful for checkboxes
> TR_AUTO_CHECK_PARENT =3D 0x10000 # only=
meaningful for checkboxes
1766a1769
> TR_AUTO_CHECK_PARENT # only meaningful for=
checkboxes
2156a2160,2162
> if self._windowStyle & TR_AUTO_CHECK_PARENT:
> ischeck =3D self.IsItemChecked(item)
> self.AutoCheckParent(item, ischeck)
2202a2209,2230
> =
> =
> 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 =3D item.GetParent()
> if not parent or parent.GetType() !=3D 1:
> return
> =
> (child, cookie) =3D self.GetFirstChild(parent)
> while child:
> if child.GetType() =3D=3D 1 and child.IsEnabled():
> if checked !=3D child.IsChecked():
> return
> (child, cookie) =3D self.GetNextChild(parent, cookie)
> =
> self.CheckItem2(parent, checked, torefresh=3DTrue)
> self.AutoCheckParent(parent, checked)
More information about the wxpython-users
mailing list