]>
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
23 il
= wx
.ImageList(isz
[0], isz
[1])
24 fldridx
= il
.Add(wx
.ArtProvider_GetBitmap(wx
.ART_FOLDER
, wx
.ART_OTHER
, isz
))
25 fldropenidx
= il
.Add(wx
.ArtProvider_GetBitmap(wx
.ART_FILE_OPEN
, wx
.ART_OTHER
, isz
))
26 fileidx
= il
.Add(wx
.ArtProvider_GetBitmap(wx
.ART_REPORT_VIEW
, wx
.ART_OTHER
, isz
))
27 smileidx
= il
.Add(images
.getSmilesBitmap())
29 self
.tree
.SetImageList(il
)
33 self
.tree
.AddColumn("Main column")
34 self
.tree
.AddColumn("Column 1")
35 self
.tree
.AddColumn("Column 2")
36 self
.tree
.SetMainColumn(0) # the one with the tree in it...
37 self
.tree
.SetColumnWidth(0, 175)
40 self
.root
= self
.tree
.AddRoot("The Root Item")
41 self
.tree
.SetItemText(self
.root
, "col 1 root", 1)
42 self
.tree
.SetItemText(self
.root
, "col 2 root", 2)
43 self
.tree
.SetItemImage(self
.root
, fldridx
, which
= wx
.TreeItemIcon_Normal
)
44 self
.tree
.SetItemImage(self
.root
, fldropenidx
, which
= wx
.TreeItemIcon_Expanded
)
49 child
= self
.tree
.AppendItem(self
.root
, txt
)
50 self
.tree
.SetItemText(child
, txt
+ "(c1)", 1)
51 self
.tree
.SetItemText(child
, txt
+ "(c2)", 2)
52 self
.tree
.SetItemImage(child
, fldridx
, which
= wx
.TreeItemIcon_Normal
)
53 self
.tree
.SetItemImage(child
, fldropenidx
, which
= wx
.TreeItemIcon_Expanded
)
56 txt
= "item %d-%s" % (x
, chr(ord("a")+y
))
57 last
= self
.tree
.AppendItem(child
, txt
)
58 self
.tree
.SetItemText(last
, txt
+ "(c1)", 1)
59 self
.tree
.SetItemText(last
, txt
+ "(c2)", 2)
60 self
.tree
.SetItemImage(last
, fldridx
, which
= wx
.TreeItemIcon_Normal
)
61 self
.tree
.SetItemImage(last
, fldropenidx
, which
= wx
.TreeItemIcon_Expanded
)
64 txt
= "item %d-%s-%d" % (x
, chr(ord("a")+y
), z
)
65 item
= self
.tree
.AppendItem(last
, txt
)
66 self
.tree
.SetItemText(item
, txt
+ "(c1)", 1)
67 self
.tree
.SetItemText(item
, txt
+ "(c2)", 2)
68 self
.tree
.SetItemImage(item
, fileidx
, which
= wx
.TreeItemIcon_Normal
)
69 self
.tree
.SetItemImage(item
, smileidx
, which
= wx
.TreeItemIcon_Selected
)
72 self
.tree
.Expand(self
.root
)
74 self
.tree
.GetMainWindow().Bind(wx
.EVT_RIGHT_UP
, self
.OnRightUp
)
77 def OnRightUp(self
, evt
):
78 # Convert the position from being relative to the subwindow to
79 # being relative to the outer treelist window so HitTest will
80 # have the point it is expecting.
81 pos
= evt
.GetPosition()
82 pos
= self
.tree
.GetMainWindow().ClientToScreen(pos
)
83 pos
= self
.tree
.ScreenToClient(pos
)
84 item
, flags
, col
= self
.tree
.HitTest(pos
)
87 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:])