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
|
|
|
|
2004-06-28 22:06:16 -04:00
|
|
|
self.tree = gizmos.TreeListCtrl(self, -1, style =
|
|
|
|
wx.TR_DEFAULT_STYLE
|
2006-09-18 11:26:09 -04:00
|
|
|
#| wx.TR_HAS_BUTTONS
|
|
|
|
#| wx.TR_TWIST_BUTTONS
|
2004-06-28 22:06:16 -04:00
|
|
|
#| wx.TR_ROW_LINES
|
2006-09-12 17:05:20 -04:00
|
|
|
#| wx.TR_COLUMN_LINES
|
2004-06-28 22:06:16 -04:00
|
|
|
#| wx.TR_NO_LINES
|
2004-06-28 22:58:19 -04:00
|
|
|
| wx.TR_FULL_ROW_HIGHLIGHT
|
2003-07-02 19:13:10 -04:00
|
|
|
)
|
2004-06-28 22:58:19 -04:00
|
|
|
|
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))
|
2005-06-03 17:39:04 -04:00
|
|
|
fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, 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)
|
2007-04-11 20:35:36 -04:00
|
|
|
self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate)
|
2003-10-06 12:53:31 -04:00
|
|
|
|
|
|
|
|
2007-04-11 20:35:36 -04:00
|
|
|
def OnActivate(self, evt):
|
|
|
|
self.log.write('OnActivate: %s' % self.tree.GetItemText(evt.GetItem()))
|
|
|
|
|
|
|
|
|
2003-10-06 12:53:31 -04:00
|
|
|
def OnRightUp(self, evt):
|
|
|
|
pos = evt.GetPosition()
|
|
|
|
item, flags, col = self.tree.HitTest(pos)
|
|
|
|
if item:
|
2004-08-11 18:24:47 -04:00
|
|
|
self.log.write('Flags: %s, Col:%s, Text: %s' %
|
|
|
|
(flags, col, self.tree.GetItemText(item, col)))
|
2003-10-06 12:53:31 -04:00
|
|
|
|
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
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-07-02 19:13:10 -04:00
|
|
|
|