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 child
= 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")
36 EVT_ERASE_BACKGROUND(self
, self
.OEB
)
41 # This method is called to draw each item in the value window
42 def DrawItem(self
, dc
, itemId
, rect
):
43 tree
= self
.GetTreeCtrl()
46 parent
= tree
.GetItemParent(itemId
)
48 ptext
= tree
.GetItemText(parent
)
49 text
= text
+ ptext
+ " --> "
50 text
= text
+ tree
.GetItemText(itemId
)
51 pen
= wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
)
53 dc
.SetBrush(wxBrush(self
.GetBackgroundColour(), wxSOLID
))
54 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+1, rect
.height
)
55 dc
.SetTextForeground("BLACK")
56 dc
.SetBackgroundMode(wxTRANSPARENT
)
57 tw
, th
= dc
.GetTextExtent(text
)
59 y
= rect
.y
+ max(0, (rect
.height
- th
) / 2)
60 dc
.DrawText(text
, x
, y
)
64 class TestPanel(wxPanel
):
65 def __init__(self
, parent
, log
):
66 wxPanel
.__init
__(self
, parent
, -1)
69 scroller
= wxSplitterScrolledWindow(self
, -1, (50,50), (350, 250),
70 style
=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL
)
71 splitter
= wxThinSplitterWindow(scroller
, -1, style
=wxSP_3DBORDER | wxCLIP_CHILDREN
)
72 splitter
.SetSashSize(2)
73 self
.tree
= TestTree(splitter
, -1, style
=
74 wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxTR_ROW_LINES | wxNO_BORDER
)
75 valueWindow
= TestValueWindow(splitter
, -1, style
=wxNO_BORDER
)
77 splitter
.SplitVertically(self
.tree
, valueWindow
)
78 splitter
.SetSashPosition(150)
79 scroller
.SetTargetWindow(self
.tree
)
80 scroller
.EnableScrolling(FALSE
, FALSE
)
82 valueWindow
.SetTreeCtrl(self
.tree
)
83 self
.tree
.SetCompanionWindow(valueWindow
)
87 #----------------------------------------------------------------------
89 def runTest(frame
, nb
, log
):
90 win
= TestPanel(nb
, log
)
94 #----------------------------------------------------------------------
101 This demo shows a collection of classes that were designed to operate
102 together and provide a tree control with additional columns for each
103 item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
104 wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
105 also be useful by themselves.