J

self.tree = wx.gizmos.TreeListCtrl(self, style = <1—1 the control wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT) self.tree.AssignImageList(il)

self.tree.AddColumn("Class Name") <— Creating columns self.tree.AddColumn("Description")

self.tree.SetMainColumn(0) # the one with the tree in it... self.tree.SetColumnWidth(0, 2 00) self.tree.SetColumnWidth(1, 2 00)

Adding text to root = self.tree.AddRoot("wx.Object") another column self.tree.SetItemText(root, "A description of wx.Object", 1) <— self.tree.SetItemImage(root, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(root, self.fldropenidx, wx.TreeItemIcon_Expanded) self.AddTreeNodes(root, data.tree)

self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree)

self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree) self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivated, self.tree) self.tree.Expand(root)

def AddTreeNodes(self, parentItem, items): for item in items:

newItem = self.tree.AppendItem(parentItem, item) self.tree.SetItemText(newItem, <1-

"A description of %s" % item, 1) self.tree.SetItemImage(newItem, self.fileidx, Adding text wx.TreeItemIcon_Normal) to another else: column newItem = self.tree.AppendItem(parentItem, item[0]) self.tree.SetItemText(newItem, "A description of %s" % <1-item[0], 1)

self.tree.SetItemImage(newItem, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(newItem, self.fldropenidx, wx.TreeItemIcon_Expanded)

self.AddTreeNodes(newItem, item[1])

def GetItemText(self, item): if item:

return self.tree.GetltemText(item) else:

return ""

def OnItemExpanded(self, evt):

print "OnltemExpanded: ", self.GetItemText(evt.GetItem())

def OnItemCollapsed(self, evt):

print "OnltemCollapsed:", self.GetItemText(evt.GetItem())

def OnSelChanged(self, evt):

print "OnSelChanged: ", self.GetItemText(evt.GetItem())

def OnActivated(self, evt):

print "OnActivated: ", self.GetItemText(evt.GetItem())

app = wx.PySimpleApp(redirect=True)

frame = TestFrame()

frame.Show()

app.MainLoop()

Because of the similarities of the list control for the extra methods, we don't need to list all the methods here. The API for adding and modifying columns is essentially identical to the one in the list control.

Was this article helpful?

0 0

Post a comment