radio buttons in customtreectrl

Can someone provide a simple example on how to use radio buttons with
customtreectrl?
thanks

Hi Carlos,

2010/1/16 Carlos Grohmann:

Can someone provide a simple example on how to use radio buttons with
customtreectrl?

Do you want the CustomTreeCtrl items to have a radiobutton icon on the
left and behave as radiobuttons or do you want to attach a
wx.RadioButton window on the right of each item?

The first case:

treeCtrl.AppendItem(parentItem, "MyText", ct_type=2)

The second case:

item = treeCtrl.AppendItem(parentItem, "MyText", ct_type=2)
treeCtrl.SetItemWindow(item, wx.RadioButton(treeCtrl, -1, "MyText"))

Andrea.

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

Thanks Andrea.

I added this ti my tree:

        CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style,
ctstyle)

        self.mainframe = wx.GetTopLevelParent(self)

        self.root = self.AddRoot("The Root Item")
        self.itemStereo = self.AppendItem (self.root, 'Stereonet' ,0)

        self.spin = wx.SpinCtrl(self, -1, '10', size=(60, -1), min=1,
max=45)
        self.itemGrid = self.AppendItem (self.itemStereo, 'grid' ,
ct_type=1, wnd=self.spin)
        self.SetItemPyData(self.itemGrid, [0,'grid'])
        self.CheckItem(self.itemGrid, checked=True)

        subitem = self.AppendItem (self.itemStereo, 'equal-area' ,
ct_type=2)
        self.SetItemPyData(subitem, [0,'schmidt'])
        self.CheckItem(subitem, checked=True)
        subitem = self.AppendItem (self.itemStereo, 'equal-angle' ,
ct_type=2)
        self.SetItemPyData(subitem, [0,'wulff'])
        self.Expand(self.itemGrid)

So I have a checkbox (grid) and two radio buttons (equal-area and
equal-angle) as children of 'Stereonet'. As I understand, if one of
the radio buttons is checked the other won't.

I am using this function to retrieve the checked items:
(from http://groups.google.com/group/wxPython-users/browse_thread/thread/e29af467cfe6dfa?hl=en)

   def GetCheckedItems(self, itemParent=None, checkedItems=None):

        if itemParent is None:
            itemParent = self.GetRootItem()
        if checkedItems is None:
            checkedItems =

        child, cookie = self.GetFirstChild(itemParent)

        while child:
            if self.IsItemChecked(child):
                checkedItems.append(child)

            checkedItems = self.GetCheckedItems(child, checkedItems)
            child, cookie = self.GetNextChild(itemParent, cookie)

        return checkedItems

And this to get which are the checked ones:

# action on check/uncheck items - returns list of checked items via
pubsub
    def OnItemCheck(self, event):

        checked = self.GetCheckedItems()
        namesList = # checked files - names
        itemsList = # checked files - memory adresses

        for i in checked: # get the data files that are checked
            itemName = self.GetItemText(i)
            pdata = self.GetItemPyData(i)

            if self.GetItemParent(i) == self.GetRootItem() and pdata
[0] == 1: # 1 == self.itemPlanar:
                namesList.append([pdata[1],1]) #itemIdx = pdata[1]
                itemsList.append(i)

            elif self.GetItemParent(i) == self.GetRootItem() and pdata
[0] == 2: # 2 == self.itemLinear:
                namesList.append([pdata[1],2])
                itemsList.append(i)

            elif self.GetItemParent(i) == self.itemStereo:
                namesList.append([pdata[1],0])
                itemsList.append(i)

        print namesList

My problem is that checking/unchecking the radiobuttons is not working
as I wanted. If I change the radiobutton from equal-area to equal-
angle (or vice-versa), I get this:

[['grid', 0], ['schmidt', 0], ['wulff', 0]]

but I want to get this

[['grid', 0], ['wulff', 0]]

or this

[['grid', 0], ['schmidt', 0]

I can only get them when I check/uncheck the 'grid' checkbox... Any
idea why?

many thanks

Carlos

ยทยทยท

On Jan 17, 2:03 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:

Hi Carlos,

2010/1/16 Carlos Grohmann:

> Can someone provide a simple example on how to use radio buttons with
> customtreectrl?

Do you want the CustomTreeCtrl items to have a radiobutton icon on the
left and behave as radiobuttons or do you want to attach a
wx.RadioButton window on the right of each item?

The first case:

treeCtrl.AppendItem(parentItem, "MyText", ct_type=2)

The second case:

item = treeCtrl.AppendItem(parentItem, "MyText", ct_type=2)
treeCtrl.SetItemWindow(item, wx.RadioButton(treeCtrl, -1, "MyText"))

Andrea.

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