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
)
15 self
.il
= wxImageList(16, 16)
16 im1
= self
.il
.Add(images
.getFolder1Bitmap())
17 im2
= self
.il
.Add(images
.getFile1Bitmap())
18 self
.SetImageList(self
.il
)
21 root
= self
.AddRoot("Root")
23 item
= self
.AppendItem(root
, "Item %d" % i
, im1
)
25 child
= self
.AppendItem(item
, "Child %d" % j
, im2
)
31 class TestValueWindow(wxTreeCompanionWindow
):
32 def __init__(self
, parent
, ID
, pos
=wxDefaultPosition
, size
=wxDefaultSize
, style
=0):
33 wxTreeCompanionWindow
.__init
__(self
, parent
, ID
, pos
, size
, style
)
34 self
.SetBackgroundColour("WHITE")
35 EVT_ERASE_BACKGROUND(self
, self
.OEB
)
40 # This method is called to draw each item in the value window
41 def DrawItem(self
, dc
, itemId
, rect
):
42 tree
= self
.GetTreeCtrl()
45 parent
= tree
.GetItemParent(itemId
)
47 ptext
= tree
.GetItemText(parent
)
48 text
= text
+ ptext
+ " --> "
49 text
= text
+ tree
.GetItemText(itemId
)
50 pen
= wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
)
52 dc
.SetBrush(wxBrush(self
.GetBackgroundColour(), wxSOLID
))
53 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+1, rect
.height
+1)
54 dc
.SetTextForeground("BLACK")
55 dc
.SetBackgroundMode(wxTRANSPARENT
)
56 tw
, th
= dc
.GetTextExtent(text
)
58 y
= rect
.y
+ max(0, (rect
.height
- th
) / 2)
59 dc
.DrawText(text
, x
, y
)
63 class TestPanel(wxPanel
):
64 def __init__(self
, parent
, log
):
65 wxPanel
.__init
__(self
, parent
, -1)
68 scroller
= wxSplitterScrolledWindow(self
, -1, #(50,50), (350, 250),
69 style
=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL
)
70 splitter
= wxThinSplitterWindow(scroller
, -1, style
=wxSP_3DBORDER | wxCLIP_CHILDREN
)
71 splitter
.SetSashSize(2)
72 tree
= TestTree(splitter
, -1, style
= wxTR_HAS_BUTTONS |
77 valueWindow
= TestValueWindow(splitter
, -1, style
=wxNO_BORDER
)
79 splitter
.SplitVertically(tree
, valueWindow
)
80 splitter
.SetSashPosition(150)
81 scroller
.SetTargetWindow(tree
)
82 scroller
.EnableScrolling(FALSE
, FALSE
)
84 valueWindow
.SetTreeCtrl(tree
)
85 tree
.SetCompanionWindow(valueWindow
)
87 sizer
= wxBoxSizer(wxVERTICAL
)
88 sizer
.Add(scroller
, 1, wxEXPAND|wxALL
, 25)
89 self
.SetAutoLayout(true
)
93 #----------------------------------------------------------------------
95 def runTest(frame
, nb
, log
):
96 win
= TestPanel(nb
, log
)
100 #----------------------------------------------------------------------
107 This demo shows a collection of classes that were designed to operate
108 together and provide a tree control with additional columns for each
109 item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
110 wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
111 also be useful by themselves.
116 if __name__
== '__main__':
119 run
.main(['', os
.path
.basename(sys
.argv
[0])])