Simple intro to CustomTreeCtrl?

Hello all -

I’m writing a little app to display and optionally download audiobook files from this site: http://audiobooks.ulitka.com I’m using urllib2 and BeautifulSoup to navigate the site and populate a TreeCtrl; however, I want the nodes to have checkboxes, and to carry enough information that I can easily download selected files. Looking at my options, it looks like the CustomTreeCtrl is my friend… Unfortunately, I’m having some difficulty understanding the demo: it’s HUGE. The longer I look at it, the dumber I feel.

So I decided to swallow my pride and ask if anyone can tell me what I need to do to add a checkbox to each node (and track whether it’s checked or not), and how to associate non-displayed data with each node - for example, the “content” of anchor elements is nice human-readable UTF-8 Cyrillic, but the “href” looks like this:

“%d0%90%d0%b2%d0%b5%d1%80%d1%87%d0%b5%d0%bd%d0%ba%d0%be%20%d0%90%d1%80%d0%ba%d0%b0%d0%b4%d0%b8%d0%b9/”

so I want to hide it.

I gather that I need to store two images, for checked and unchecked states, but that's about as far as I got. I know that everything I need to know is in the demo somewhere, but my head hurts...

Alternatively, can someone point me to documentation?
Even more alternatively, is there a better way to do what I need to do?

Thanks!

···


www.fsrtechnologies.com

Hello all -

I'm writing a little app to display and optionally download audiobook files
from this site: http://audiobooks.ulitka.com I'm using urllib2 and
BeautifulSoup to navigate the site and populate a TreeCtrl; however, I want
the nodes to have checkboxes, and to carry enough information that I can
easily download selected files. Looking at my options, it looks like the
CustomTreeCtrl is my friend... Unfortunately, I'm having some difficulty
understanding the demo: it's HUGE. The longer I look at it, the dumber I
feel.

I know that feeling!

Sometimes (but not always) I find it better to look at the actual class API:

http://www.wxpython.org/docs/api/wx.lib.customtreectrl.CustomTreeCtrl-class.html

In that, it mentions how to append an item:

AppendItem(self, parentId, text, ct_type=0, wnd=None, image=-1,
selImage=-1, data=None)

Appends an item as a last child of its parent.

When I saw this, I wasn't sure what ct_type was or what I should choose,
so I went through the class itself:

C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\customtreectrl

Somewhere down in the actual class is this:

    def GetType(self):
        """
        Returns the item type. It should be one of:
        0: normal items
        1: checkbox item
        2: radiobutton item
        """
So for a checkbox, ct_type has to be 1. OK. So then we can add a root and
then an item with a checkbox, like this:

value = 'node name'
ct_type = 1
root = self.tree.AddRoot(rootname, wnd= self.Button)
item = self.tree.AppendItem(root, value, ct_type)

So I decided to swallow my pride and ask if anyone can tell me what I need
to do to add a checkbox to each node (and track whether it's checked or
not), and how to associate non-displayed data with each node - for example,
the "content" of anchor elements is nice human-readable UTF-8 Cyrillic, but
the "href" looks like this:

If you can extract the content and make it be the value above, you're all set.

Best,
Che

···

On Tue, Jan 20, 2009 at 6:03 PM, Marc Tompkins <marc.tompkins@gmail.com> wrote:

You can also use SetPyData:

   tree.SetPyData(item, "your data here")

and then later retrieve it:

   data = tree.GetPyData(item)

Also be sure to check out the CT.EVT_TREE_ITEM_CHECKED event:

   tree.Bind(CT.EVT_TREE_ITEM_CHECKED, YourEventHandler)

Hope that helps.

-Kyle Rickey
From:
wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidgets.org
[mailto:wxpython-users-bounces+kyle.rickey=bakerhughes.com@lists.wxwidge
ts.org] On Behalf Of C M

···

-----Original Message-----
Sent: Tuesday, January 20, 2009 6:10 PM
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Simple intro to CustomTreeCtrl?

On Tue, Jan 20, 2009 at 6:03 PM, Marc Tompkins <marc.tompkins@gmail.com> wrote:

Hello all -

I'm writing a little app to display and optionally download audiobook

files

from this site: http://audiobooks.ulitka.com I'm using urllib2 and
BeautifulSoup to navigate the site and populate a TreeCtrl; however, I

want

the nodes to have checkboxes, and to carry enough information that I

can

easily download selected files. Looking at my options, it looks like

the

CustomTreeCtrl is my friend... Unfortunately, I'm having some

difficulty

understanding the demo: it's HUGE. The longer I look at it, the

dumber I

feel.

I know that feeling!

Sometimes (but not always) I find it better to look at the actual class
API:

http://www.wxpython.org/docs/api/wx.lib.customtreectrl.CustomTreeCtrl-cl
ass.html

In that, it mentions how to append an item:

AppendItem(self, parentId, text, ct_type=0, wnd=None, image=-1,
selImage=-1, data=None)

Appends an item as a last child of its parent.

When I saw this, I wasn't sure what ct_type was or what I should choose,
so I went through the class itself:

C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\customtreectrl

Somewhere down in the actual class is this:

    def GetType(self):
        """
        Returns the item type. It should be one of:
        0: normal items
        1: checkbox item
        2: radiobutton item
        """
So for a checkbox, ct_type has to be 1. OK. So then we can add a root
and
then an item with a checkbox, like this:

value = 'node name'
ct_type = 1
root = self.tree.AddRoot(rootname, wnd= self.Button)
item = self.tree.AppendItem(root, value, ct_type)

So I decided to swallow my pride and ask if anyone can tell me what I

need

to do to add a checkbox to each node (and track whether it's checked

or

not), and how to associate non-displayed data with each node - for

example,

the "content" of anchor elements is nice human-readable UTF-8

Cyrillic, but

the "href" looks like this:

If you can extract the content and make it be the value above, you're
all set.

Best,
Che
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Thanks! I also like to read the API, but my Google-fu was weak…

I added the “ct_type=1” and “data=hRef” and in the limited testing I’ve done so far it seems great. I’ve been crazy busy (and this is a side project), so haven’t been able to actually USE it (i.e. move ahead with the downloading part) but so far it’s good.

Again, thanks for the pointers!

···

On Tue, Jan 20, 2009 at 4:10 PM, C M cmpython@gmail.com wrote:

Sometimes (but not always) I find it better to look at the actual class API:

http://www.wxpython.org/docs/api/wx.lib.customtreectrl.CustomTreeCtrl-class.html

In that, it mentions how to append an item:

AppendItem(self, parentId, text, ct_type=0, wnd=None, image=-1,

selImage=-1, data=None)

Appends an item as a last child of its parent.

When I saw this, I wasn’t sure what ct_type was or what I should choose,

so I went through the class itself:

C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\customtreectrl

Somewhere down in the actual class is this:

def GetType(self):

    """

    Returns the item type. It should be one of:

    0: normal items

    1: checkbox item

    2: radiobutton item

    """

So for a checkbox, ct_type has to be 1. OK. So then we can add a root and

then an item with a checkbox, like this:

value = ‘node name’

ct_type = 1

root = self.tree.AddRoot(rootname, wnd= self.Button)

item = self.tree.AppendItem(root, value, ct_type)


www.fsrtechnologies.com