]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TreeListCtrl.py
3 import wx
.gizmos
as gizmos
7 #----------------------------------------------------------------------
9 class TestPanel(wx
.Panel
):
10 def __init__(self
, parent
, log
):
12 wx
.Panel
.__init
__(self
, parent
, -1)
13 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
15 self
.tree
= gizmos
.TreeListCtrl(self
, -1, style
=
20 | wx
.TR_FULL_ROW_HIGHLIGHT
22 # By default the style will be adjusted on
23 # Mac to use twisty buttons and no lines. If
24 # you would rather control this yourself then
26 #| wx.TR_DONT_ADJUST_MAC
30 il
= wx
.ImageList(isz
[0], isz
[1])
31 fldridx
= il
.Add(wx
.ArtProvider_GetBitmap(wx
.ART_FOLDER
, wx
.ART_OTHER
, isz
))
32 fldropenidx
= il
.Add(wx
.ArtProvider_GetBitmap(wx
.ART_FILE_OPEN
, wx
.ART_OTHER
, isz
))
33 fileidx
= il
.Add(wx
.ArtProvider_GetBitmap(wx
.ART_REPORT_VIEW
, wx
.ART_OTHER
, isz
))
34 smileidx
= il
.Add(images
.getSmilesBitmap())
36 self
.tree
.SetImageList(il
)
40 self
.tree
.AddColumn("Main column")
41 self
.tree
.AddColumn("Column 1")
42 self
.tree
.AddColumn("Column 2")
43 self
.tree
.SetMainColumn(0) # the one with the tree in it...
44 self
.tree
.SetColumnWidth(0, 175)
47 self
.root
= self
.tree
.AddRoot("The Root Item")
48 self
.tree
.SetItemText(self
.root
, "col 1 root", 1)
49 self
.tree
.SetItemText(self
.root
, "col 2 root", 2)
50 self
.tree
.SetItemImage(self
.root
, fldridx
, which
= wx
.TreeItemIcon_Normal
)
51 self
.tree
.SetItemImage(self
.root
, fldropenidx
, which
= wx
.TreeItemIcon_Expanded
)
56 child
= self
.tree
.AppendItem(self
.root
, txt
)
57 self
.tree
.SetItemText(child
, txt
+ "(c1)", 1)
58 self
.tree
.SetItemText(child
, txt
+ "(c2)", 2)
59 self
.tree
.SetItemImage(child
, fldridx
, which
= wx
.TreeItemIcon_Normal
)
60 self
.tree
.SetItemImage(child
, fldropenidx
, which
= wx
.TreeItemIcon_Expanded
)
63 txt
= "item %d-%s" % (x
, chr(ord("a")+y
))
64 last
= self
.tree
.AppendItem(child
, txt
)
65 self
.tree
.SetItemText(last
, txt
+ "(c1)", 1)
66 self
.tree
.SetItemText(last
, txt
+ "(c2)", 2)
67 self
.tree
.SetItemImage(last
, fldridx
, which
= wx
.TreeItemIcon_Normal
)
68 self
.tree
.SetItemImage(last
, fldropenidx
, which
= wx
.TreeItemIcon_Expanded
)
71 txt
= "item %d-%s-%d" % (x
, chr(ord("a")+y
), z
)
72 item
= self
.tree
.AppendItem(last
, txt
)
73 self
.tree
.SetItemText(item
, txt
+ "(c1)", 1)
74 self
.tree
.SetItemText(item
, txt
+ "(c2)", 2)
75 self
.tree
.SetItemImage(item
, fileidx
, which
= wx
.TreeItemIcon_Normal
)
76 self
.tree
.SetItemImage(item
, smileidx
, which
= wx
.TreeItemIcon_Selected
)
79 self
.tree
.Expand(self
.root
)
81 self
.tree
.GetMainWindow().Bind(wx
.EVT_RIGHT_UP
, self
.OnRightUp
)
84 def OnRightUp(self
, evt
):
85 pos
= evt
.GetPosition()
86 item
, flags
, col
= self
.tree
.HitTest(pos
)
88 print flags
, col
, self
.tree
.GetItemText(item
, col
)
90 def OnSize(self
, evt
):
91 self
.tree
.SetSize(self
.GetSize())
94 #----------------------------------------------------------------------
96 def runTest(frame
, nb
, log
):
97 win
= TestPanel(nb
, log
)
100 #----------------------------------------------------------------------
104 overview
= """<html><body>
105 <h2><center>TreeListCtrl</center></h2>
107 The TreeListCtrl is essentially a wx.TreeCtrl with extra columns,
108 such that the look is similar to a wx.ListCtrl.
114 if __name__
== '__main__':
115 #raw_input("Press enter...")
118 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])