Binding events to check boxes in HyperTreeList?

I'm having some trouble trying to bind events to check boxes that I
created using HyperTreeList. I setup my check boxes using ct_type = 1,
and the basic structure of my code is the following:

# Create root
self.root = self.AddRoot("Root")

# Create branch for climb tests
branch = self.AppendItem(self.root, "branch")
cb_subbranch = self.AppendItem(branch, "sub-branch", ct_type=1)

# Bind event to sub-branch
self.Bind(wx.EVT_CHECKBOX, CheckBox_subbranch, cb_subbranch)

def CheckBox_subbranch (self, event):
self.log.write("Box is checked. \n")

The error that I'm getting on Eclipse is
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 3917, in Bind
    id = source.GetId()
AttributeError: 'TreeListItem' object has no attribute 'GetId'

Any ideas as to what am I'm doing wrong?

cb_subbranch does not derive from wx.EvtHandler so you can't use it to specify the source of the event. IIRC there isn't even a real checkbox widget in the items with ct_type=1 so trying to bind a EVT_CHECKBOX event wouldn't work anyway. Instead the tree widget just uses bitmaps that look like the checkbox or radio button and it sends a tree event when it is checked or unchecked. Looks like wx.lib.agw.customtreectrl.EVT_TREE_ITEM_CHECKED is probably the one that is sent in that case.

···

On 9/7/10 6:50 AM, Reverie wrote:

I'm having some trouble trying to bind events to check boxes that I
created using HyperTreeList. I setup my check boxes using ct_type = 1,
and the basic structure of my code is the following:

# Create root
self.root = self.AddRoot("Root")

# Create branch for climb tests
branch = self.AppendItem(self.root, "branch")
cb_subbranch = self.AppendItem(branch, "sub-branch", ct_type=1)

# Bind event to sub-branch
self.Bind(wx.EVT_CHECKBOX, CheckBox_subbranch, cb_subbranch)

def CheckBox_subbranch (self, event):
self.log.write("Box is checked. \n")

The error that I'm getting on Eclipse is
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 3917, in Bind
     id = source.GetId()
AttributeError: 'TreeListItem' object has no attribute 'GetId'

Any ideas as to what am I'm doing wrong?

--
Robin Dunn
Software Craftsman

I was also looking into using EVT_TREE_ITEM_CHECKED. I had it setup as

import wx.lib.agw.hypertreelist as HTL
(...code...)
self.Bind(HTL.EVT_TREE_ITEM_CHECKED, CheckBox_subbranch, cb_subbranch)

This yields an attribute error, too. (AttributeError: 'module' object
has no attribute 'EVT_TREE_ITEM_CHECKED')

Unfortunately I would've thought that that would work...

···

On Sep 7, 4:50 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 9/7/10 6:50 AM, Reverie wrote:

> I'm having some trouble trying to bind events to check boxes that I
> created using HyperTreeList. I setup my check boxes using ct_type = 1,
> and the basic structure of my code is the following:

> # Create root
> self.root = self.AddRoot("Root")

> # Create branch for climb tests
> branch = self.AppendItem(self.root, "branch")
> cb_subbranch = self.AppendItem(branch, "sub-branch", ct_type=1)

> # Bind event to sub-branch
> self.Bind(wx.EVT_CHECKBOX, CheckBox_subbranch, cb_subbranch)

> def CheckBox_subbranch (self, event):
> self.log.write("Box is checked. \n")

> The error that I'm getting on Eclipse is
> File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
> line 3917, in Bind
> id = source.GetId()
> AttributeError: 'TreeListItem' object has no attribute 'GetId'

> Any ideas as to what am I'm doing wrong?

cb_subbranch does not derive from wx.EvtHandler so you can't use it to
specify the source of the event. IIRC there isn't even a real checkbox
widget in the items with ct_type=1 so trying to bind a EVT_CHECKBOX
event wouldn't work anyway. Instead the tree widget just uses bitmaps
that look like the checkbox or radio button and it sends a tree event
when it is checked or unchecked. Looks like
wx.lib.agw.customtreectrl.EVT_TREE_ITEM_CHECKED is probably the one that
is sent in that case.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Yeah, hypertreelist should probably import those items from the customtreectl module.

BTW, it's still going to give you the error about using cb_subbranch. You'll need to get the item where the event happened in the event handler function and then decide what to do about it from there.

···

On 9/7/10 2:04 PM, Reverie wrote:

I was also looking into using EVT_TREE_ITEM_CHECKED. I had it setup as

import wx.lib.agw.hypertreelist as HTL
(...code...)
self.Bind(HTL.EVT_TREE_ITEM_CHECKED, CheckBox_subbranch, cb_subbranch)

This yields an attribute error, too. (AttributeError: 'module' object
has no attribute 'EVT_TREE_ITEM_CHECKED')

Unfortunately I would've thought that that would work...

--
Robin Dunn
Software Craftsman

Could you give an example on how to do this? I apologize, I'm a bit
confused..

···

On Sep 7, 5:13 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 9/7/10 2:04 PM, Reverie wrote:

> I was also looking into using EVT_TREE_ITEM_CHECKED. I had it setup as

> import wx.lib.agw.hypertreelist as HTL
> (...code...)
> self.Bind(HTL.EVT_TREE_ITEM_CHECKED, CheckBox_subbranch, cb_subbranch)

> This yields an attribute error, too. (AttributeError: 'module' object
> has no attribute 'EVT_TREE_ITEM_CHECKED')

> Unfortunately I would've thought that that would work...

Yeah, hypertreelist should probably import those items from the
customtreectl module.

BTW, it's still going to give you the error about using cb_subbranch.
You'll need to get the item where the event happened in the event
handler function and then decide what to do about it from there.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

def OnWhatever(self, evt):
    item = evt.GetItem()
    
You can then use the item (check item.GetText(), compare it to specific item objects you saved when adding things to the tree, or whatever you need) to decide what to do about the event.

···

On 9/8/10 2:02 PM, Reverie wrote:

BTW, it's still going to give you the error about using cb_subbranch.
You'll need to get the item where the event happened in the event
handler function and then decide what to do about it from there.

Could you give an example on how to do this? I apologize, I'm a bit
confused..

--
Robin Dunn
Software Craftsman

Hi All,

I was also looking into using EVT_TREE_ITEM_CHECKED. I had it setup as

import wx.lib.agw.hypertreelist as HTL
(...code...)
self.Bind(HTL.EVT_TREE_ITEM_CHECKED, CheckBox_subbranch, cb_subbranch)

This yields an attribute error, too. (AttributeError: 'module' object
has no attribute 'EVT_TREE_ITEM_CHECKED')

Unfortunately I would've thought that that would work...

Yeah, hypertreelist should probably import those items from the
customtreectl module.

I just modified the code of HyperTreeList to import the
EVT_TREE_ITEM_CHECKING/CHECKED/HYPERLINK from CustomTreeCtrl. It is
now in SVN and this part of the code should now work correctly.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
The Doomed City: Removal Group: the nightmare <==

···

On 8 September 2010 00:13, Robin Dunn wrote:

On 9/7/10 2:04 PM, Reverie wrote: