2003-07-02 19:13:10 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
|
|
|
import wx.gizmos as gizmos
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import images
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2003-07-02 19:13:10 -04:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
|
|
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE
|
|
|
|
#| wx.TR_ROW_LINES
|
|
|
|
#| wx.TR_NO_LINES
|
|
|
|
#| wx.TR_TWIST_BUTTONS
|
2003-07-02 19:13:10 -04:00
|
|
|
)
|
|
|
|
isz = (16,16)
|
2003-12-08 20:23:28 -05:00
|
|
|
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_REPORT_VIEW, wx.ART_OTHER, isz))
|
2003-07-02 19:13:10 -04:00
|
|
|
smileidx = il.Add(images.getSmilesBitmap())
|
|
|
|
|
|
|
|
self.tree.SetImageList(il)
|
|
|
|
self.il = il
|
|
|
|
|
|
|
|
# create some columns
|
|
|
|
self.tree.AddColumn("Main column")
|
|
|
|
self.tree.AddColumn("Column 1")
|
|
|
|
self.tree.AddColumn("Column 2")
|
|
|
|
self.tree.SetMainColumn(0) # the one with the tree in it...
|
|
|
|
self.tree.SetColumnWidth(0, 175)
|
|
|
|
|
|
|
|
|
|
|
|
self.root = self.tree.AddRoot("The Root Item")
|
|
|
|
self.tree.SetItemText(self.root, "col 1 root", 1)
|
|
|
|
self.tree.SetItemText(self.root, "col 2 root", 2)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal)
|
|
|
|
self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
for x in range(15):
|
|
|
|
txt = "Item %d" % x
|
|
|
|
child = self.tree.AppendItem(self.root, txt)
|
|
|
|
self.tree.SetItemText(child, txt + "(c1)", 1)
|
|
|
|
self.tree.SetItemText(child, txt + "(c2)", 2)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal)
|
|
|
|
self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
for y in range(5):
|
|
|
|
txt = "item %d-%s" % (x, chr(ord("a")+y))
|
|
|
|
last = self.tree.AppendItem(child, txt)
|
|
|
|
self.tree.SetItemText(last, txt + "(c1)", 1)
|
|
|
|
self.tree.SetItemText(last, txt + "(c2)", 2)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal)
|
|
|
|
self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
for z in range(5):
|
|
|
|
txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z)
|
|
|
|
item = self.tree.AppendItem(last, txt)
|
|
|
|
self.tree.SetItemText(item, txt + "(c1)", 1)
|
|
|
|
self.tree.SetItemText(item, txt + "(c2)", 2)
|
2003-12-08 20:23:28 -05:00
|
|
|
self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal)
|
|
|
|
self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
self.tree.Expand(self.root)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
2003-10-06 12:53:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnRightUp(self, evt):
|
|
|
|
# Convert the position from being relative to the subwindow to
|
|
|
|
# being relative to the outer treelist window so HitTest will
|
|
|
|
# have the point it is expecting.
|
|
|
|
pos = evt.GetPosition()
|
|
|
|
pos = self.tree.GetMainWindow().ClientToScreen(pos)
|
|
|
|
pos = self.tree.ScreenToClient(pos)
|
|
|
|
item, flags, col = self.tree.HitTest(pos)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-10-06 12:53:31 -04:00
|
|
|
if item:
|
|
|
|
print flags, col, self.tree.GetItemText(item, col)
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
def OnSize(self, evt):
|
|
|
|
self.tree.SetSize(self.GetSize())
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
2004-01-12 22:17:17 -05:00
|
|
|
<h2><center>TreeListCtrl</center></h2>
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
The TreeListCtrl is essentially a wx.TreeCtrl with extra columns,
|
2003-12-08 20:23:28 -05:00
|
|
|
such that the look is similar to a wx.ListCtrl.
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
#raw_input("Press enter...")
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|