1 from wxPython
.wx
import *
2 from wxPython
.gizmos
import *
6 #----------------------------------------------------------------------
8 class TestTree(wxRemotelyScrolledTreeCtrl
):
9 def __init__(self
, parent
, ID
, pos
=wxDefaultPosition
, size
=wxDefaultSize
,
10 style
=wxTR_HAS_BUTTONS
):
11 wxRemotelyScrolledTreeCtrl
.__init
__(self
, parent
, ID
, pos
, size
, style
)
12 ##self.SetBackgroundColour("LIGHT BLUE")
16 ##self.il = wxImageList(16, 16)
17 ##im1 = self.il.Add(images.getFolder1Bitmap())
18 ##im2 = self.il.Add(images.getFile1Bitmap())
19 ##self.SetImageList(self.il)
22 root
= self
.AddRoot("Root")
24 item
= self
.AppendItem(root
, "Item %d" % i
, im1
)
26 self
.AppendItem(item
, "Child %d" % j
, im2
)
32 class TestValueWindow(wxTreeCompanionWindow
):
33 def __init__(self
, parent
, ID
, pos
=wxDefaultPosition
, size
=wxDefaultSize
, style
=0):
34 wxTreeCompanionWindow
.__init
__(self
, parent
, ID
, pos
, size
, style
)
35 self
.SetBackgroundColour("WHITE")
37 # This method is called to draw each item in the value window
38 def DrawItem(self
, dc
, itemId
, rect
):
39 tree
= self
.GetTreeCtrl()
42 parent
= tree
.GetItemParent(itemId
)
44 ptext
= tree
.GetItemText(parent
)
45 text
= text
+ ptext
+ " --> "
46 text
= text
+ tree
.GetItemText(itemId
)
47 dc
.SetTextForeground("BLACK")
48 dc
.SetBackgroundMode(wxTRANSPARENT
)
49 tw
, th
= dc
.GetTextExtent(text
)
51 y
= rect
.y
+ max(0, (rect
.height
- th
) / 2)
52 dc
.DrawText(text
, x
, y
)
56 class TestPanel(wxPanel
):
57 def __init__(self
, parent
, log
):
58 wxPanel
.__init
__(self
, parent
, -1)
61 scroller
= wxSplitterScrolledWindow(self
, -1, (50,50), (350, 250),
62 style
=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL
)
63 splitter
= wxThinSplitterWindow(scroller
, -1, style
=wxSP_3DBORDER | wxCLIP_CHILDREN
)
64 splitter
.SetSashSize(2)
65 self
.tree
= TestTree(splitter
, -1, style
=wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER
)
66 valueWindow
= TestValueWindow(splitter
, -1, style
=wxNO_BORDER
)
68 splitter
.SplitVertically(self
.tree
, valueWindow
)
69 splitter
.SetSashPosition(150)
70 scroller
.SetTargetWindow(self
.tree
)
71 scroller
.EnableScrolling(FALSE
, FALSE
)
73 valueWindow
.SetTreeCtrl(self
.tree
)
74 self
.tree
.SetCompanionWindow(valueWindow
)
78 #----------------------------------------------------------------------
80 def runTest(frame
, nb
, log
):
81 win
= TestPanel(nb
, log
)
85 #----------------------------------------------------------------------
92 This demo shows a collection of classes that were designed to operate
93 together and provide a tree control with additional columns for each
94 item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
95 wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
96 also be useful by themselves.