Hi Glenn,
2009/9/17 Glenn Thobe:
Thanks to Andrea Gavana for the most helpful information, which worked like
a charm. There are some additional features of the HyperTreeList, which I
would like to use. I figured out how to do some things, but am having
difficulty doing others. The setup is Python 2.6.2, wxPython 2.8.10.1, and
HyperTreeList.py Revision 61618 of 05 Aug 2009 on Windows Vista.
The wxPython demo for HyperTreeList shows examples of a check box being
attached to a tree item, but none involving a list item. The check box is
attached by means of the keyword argument ct_type=1 in the method call
tree.AppendItem or tree.AddRoot, which is the constructor for the tree item
in question.
• Is it possible to create the tree item and attached check box in
separate steps?
Yes, it will be possible when I will be able to commit a small change
I made right now to HyperTreeList and CustomTreeCtrl. At the moment
SVN looks down (or I am unable to connect), but basically you will be
able to do this:
self.tree.SetItemType(item, ct_type)
Where ct_type is either 0 (normal item), 1 (checkbox) or 2 (radiobutton)
• How does one programmatically set the state of the check box?
Use self.tree.CheckItem2(item, check_status)
One detects a change in the state of the check box after the user clicks on
it, by binding a handler to the event
wx.lib.agw.hypertreelist.EVT_TREE_ITEM_CHECKED. The state is then
determined by state=evt.GetItem().GetCurrentCheckedImage(). Perversely, a 0
is returned if the box is checked and a 1 is returned if it is not.
• Is this the preferred way to read the check box state?
No, you should use:
state = item.IsChecked()
• A bug shows up when editing a list item in the same row as the
checkbox. Selecting the cell to be edited causes a second copy of it to
appear shifted to the right of the original and with a box drawn around it.
This looks like a bug, I'll try to hunt it down if I get some time...
please enter a bug report on wxTrac so that the bug doesn't get lost.
• Is it possible for the list columns to contain checkboxes, choice
boxes, etc. instead of merely text controls? If so, how? According to the
documentation: “Whatever non-toplevel widget can be attached next to a list
item.” Also, how does one initialize check boxes, detect changes, and read
the state for list items?
To attach whatever non-toplevel widget to an item, you simply do this:
# Create a wx.Choice, which is a child of the MAIN WINDOW
choice = wx.Choice(self.tree.GetMainWindow(), -1, choices=your_choices)
choice.Bind(wx.EVT_CHOICE, self.OnChoice)
# Assign the wx.Choice to this item on column 1
self.tree.SetItemWindow(item, choice, 1)
• The method wx.gizmos.TreeListCtrl.GetCurrentItem() has no counterpart
in HyperTreeList.
Uhm, I have never used this method myself, I don't even know what
"current" item means... what is it supposed to mean when you have
multiple selections enabled and you have selected 10 items? Which is
the "current" one? But anyway, I've added the method to return
"self._current"...
• Can a list item be a Choice box?
Yes, you simply enter an empty string for the item and attach a window
to that item, i.e.:
item = self.tree.AppendItem(parent, "B")
self.tree.SetItemText(item, "" , 1)
# Create a wx.Choice, which is a child of the MAIN WINDOW
choice = wx.Choice(self.tree.GetMainWindow(), -1, choices=your_choices)
# Assign the wx.Choice to this item on column 1
self.tree.SetItemWindow(item, choice, 1)
A modified sample is attached to this message.
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
treelisttest_minimal_3.py (3.03 KB)