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")
13 EVT_PAINT(self
, self
.OnPaint
)
17 self
.il
= wxImageList(16, 16)
18 im1
= self
.il
.Add(images
.getFolder1Bitmap())
19 im2
= self
.il
.Add(images
.getFile1Bitmap())
20 self
.SetImageList(self
.il
)
23 root
= self
.AddRoot("Root")
25 item
= self
.AppendItem(root
, "Item %d" % i
, im1
)
27 child
= self
.AppendItem(item
, "Child %d" % j
, im2
)
31 def OnPaint(self
, evt
):
34 self
.base_OnPaint(evt
)
36 # Reset the device origin since it may have been set
37 dc
.SetDeviceOrigin(0, 0)
39 pen
= wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
)
41 dc
.SetBrush(wxTRANSPARENT_BRUSH
)
43 clientSize
= self
.GetClientSize()
45 h
= self
.GetFirstVisibleItem()
47 rect
= self
.GetBoundingRect(h
)
50 dc
.DrawLine(0, cy
, clientSize
.x
, cy
)
52 h
= self
.GetNextVisible(h
)
54 rect
= self
.GetBoundingRect(lastH
)
57 dc
.DrawLine(0, cy
, clientSize
.x
, cy
)
61 class TestValueWindow(wxTreeCompanionWindow
):
62 def __init__(self
, parent
, ID
, pos
=wxDefaultPosition
, size
=wxDefaultSize
, style
=0):
63 wxTreeCompanionWindow
.__init
__(self
, parent
, ID
, pos
, size
, style
)
64 self
.SetBackgroundColour("WHITE")
65 EVT_ERASE_BACKGROUND(self
, self
.OEB
)
70 # This method is called to draw each item in the value window
71 def DrawItem(self
, dc
, itemId
, rect
):
72 tree
= self
.GetTreeCtrl()
75 parent
= tree
.GetItemParent(itemId
)
77 ptext
= tree
.GetItemText(parent
)
78 text
= text
+ ptext
+ " --> "
79 text
= text
+ tree
.GetItemText(itemId
)
80 pen
= wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
)
82 dc
.SetBrush(wxBrush(self
.GetBackgroundColour(), wxSOLID
))
83 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+1, rect
.height
)
84 dc
.SetTextForeground("BLACK")
85 dc
.SetBackgroundMode(wxTRANSPARENT
)
86 tw
, th
= dc
.GetTextExtent(text
)
88 y
= rect
.y
+ max(0, (rect
.height
- th
) / 2)
89 dc
.DrawText(text
, x
, y
)
93 class TestPanel(wxPanel
):
94 def __init__(self
, parent
, log
):
95 wxPanel
.__init
__(self
, parent
, -1)
98 scroller
= wxSplitterScrolledWindow(self
, -1, (50,50), (350, 250),
99 style
=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL
)
100 splitter
= wxThinSplitterWindow(scroller
, -1, style
=wxSP_3DBORDER | wxCLIP_CHILDREN
)
101 splitter
.SetSashSize(2)
102 self
.tree
= TestTree(splitter
, -1, style
=wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER
)
103 valueWindow
= TestValueWindow(splitter
, -1, style
=wxNO_BORDER
)
105 splitter
.SplitVertically(self
.tree
, valueWindow
)
106 splitter
.SetSashPosition(150)
107 scroller
.SetTargetWindow(self
.tree
)
108 scroller
.EnableScrolling(FALSE
, FALSE
)
110 valueWindow
.SetTreeCtrl(self
.tree
)
111 self
.tree
.SetCompanionWindow(valueWindow
)
115 #----------------------------------------------------------------------
117 def runTest(frame
, nb
, log
):
118 win
= TestPanel(nb
, log
)
122 #----------------------------------------------------------------------
129 This demo shows a collection of classes that were designed to operate
130 together and provide a tree control with additional columns for each
131 item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
132 wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
133 also be useful by themselves.