i want to make a treelist by using Boa Constructor.
first, i make a new frame, and then add a new treelist in the frame, but i can not find any key or table to let me add items in the treelist.
so i typed several Python code in the source.

However, a error message came out when i came to "Frame Designer" as this:
"Name error: name 'root' is not defined"

this is my whole code

#Boa:Frame:Frame1

import wx

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1TREECTRL1,
] = [wx.NewId() for _init_ctrls in range(2)]

class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(561, 187), size=wx.Size(400, 492),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 458))

self.treeCtrl1 = wx.TreeCtrl(id=wxID_FRAME1TREECTRL1, name='treeCtrl1',
parent=self, pos=wx.Point(224, 104), size=wx.Size(100, 80),
style=wx.TR_HAS_BUTTONS)
root = self.tree.AddRoot("Example")
items = ["test1","test2","test3"]
self.AddTreeNodes(root, items)

def __init__(self, parent):
self._init_ctrls(parent)

I don't have BOA, but I quickly created a sample program using the wxGlade designer and the SPE editor. It shows you how to set up a tree ...

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.2 on Fri Feb 19 05:43:46 2010

import wx

# begin wxGlade: extracode
# end wxGlade



class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.tree = wx.TreeCtrl(self, -1)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.selected, self.tree)
        # end wxGlade

        self.mystuff()
        
    def mystuff(self):    
        # --- the following code is added by the programmer --->
        # you can only have one root
        root = self.tree.AddRoot("Computer")
        
        # these form subroots
        os = self.tree.AppendItem(root, 'Systems')
        tk = self.tree.AppendItem(root, 'Toolkits')

        # add 3 items to subroot os
        os_items = ["Windows", "Solaris", "Linux"]
        for item in os_items:
            self.tree.AppendItem(os, item)

        # add 3 items to subroot tk
        tk_items = ["Tkinter", "wxPython", "Qt"]
        for item in tk_items:
            self.tree.AppendItem(tk, item)
            
        # start with root expanded to show subroots
        self.tree.Expand(root)   

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("frame")
        self.SetSize((400, 300))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.tree, 1, wx.EXPAND, 0)
        self.SetSizer(sizer)
        self.Layout()
        # end wxGlade

    def selected(self, event): # wxGlade: MyFrame.<event_handler>
        # --- the following code is added by the programmer --->
        item_text = self.tree.GetItemText(event.GetItem())
        sf = "selection changed: %s" %item_text
        self.SetTitle(sf)

# end of class MyFrame


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame = MyFrame(None, -1, "")
    app.SetTopWindow(frame)
    frame.Show()
    app.MainLoop()

Note:
For Python26 I am using PortablePython 1.1 from:
http://www.portablepython.com/releases/
which comes with the SPE editor. SPE in turn has wxGlade incorporated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.