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:
# 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'
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:
# 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'
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:
> # 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...
> 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
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..
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.