import string import wx #--------------------------------------------------------------------------- class MyTreeCtrl(wx.TreeCtrl): def __init__(self, parent, id, pos, size, style, log): wx.TreeCtrl.__init__(self, parent, id, pos, size, style) self.log = log def OnCompareItems(self, item1, item2): t1 = self.GetItemText(item1) t2 = self.GetItemText(item2) self.log.WriteText('compare: ' + t1 + ' <> ' + t2 + '\n') if t1 < t2: return -1 if t1 == t2: return 0 return 1 #--------------------------------------------------------------------------- class TestTreeCtrlPanel(wx.Panel): def __init__(self, parent, log): # Use the WANTS_CHARS style so the panel doesn't eat the Return key. wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.log = log isz = (16,16) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) self.tree.SetImageList(il) self.il = il from wxcode import codeTreeListCtrl as TreeList self.tree = TreeList(self, size=(200,300)) self.tree.AddColumn('MainColumn') self.root = self.tree.AddRoot("root item") self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemText(self.root,'col 1',1) self.tree.SetItemText(self.root, 'col 2', 2) item1 = self.tree.AppendItem(self.root, 'item1') item2 = self.tree.AppendItem(self.root, 'item2') self.tree.SetItemImage(item1, fldropenidx, which = wx.TreeItemIcon_Expanded) item21 = self.tree.AppendItem(item2, 'item21') self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate) self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp) #### def OnActivate(self, evt): self.log.write('OnActivate: %s' % self.tree.GetItemText(evt.GetItem())) def runTest(frame, nb, log): win = TestTreeCtrlPanel(nb, log) return win #--------------------------------------------------------------------------- overview = """\ A TreeCtrl presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wx.TreeItemId handles. """ if __name__ == '__main__': import sys,os import run run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
test wxtreelistctrl
最新推荐文章于 2017-01-12 17:51:20 发布