]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/SplitTree.py
5de68027e432f2386f7abfc8abaa882587b9e06d
[wxWidgets.git] / wxPython / demo / SplitTree.py
1 from wxPython.wx import *
2 from wxPython.gizmos import *
3
4 import images
5
6 #----------------------------------------------------------------------
7
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)
14
15 # make an image list
16 im1 = im2 = -1
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)
21
22 # Add some items
23 root = self.AddRoot("Root")
24 for i in range(30):
25 item = self.AppendItem(root, "Item %d" % i, im1)
26 for j in range(10):
27 child = self.AppendItem(item, "Child %d" % j, im2)
28
29 self.Expand(root)
30
31 def OnPaint(self, evt):
32 dc = wxPaintDC(self)
33
34 self.base_OnPaint(evt)
35
36 # Reset the device origin since it may have been set
37 dc.SetDeviceOrigin(0, 0)
38
39 pen = wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID)
40 dc.SetPen(pen)
41 dc.SetBrush(wxTRANSPARENT_BRUSH)
42
43 clientSize = self.GetClientSize()
44 cy = 0
45 h = self.GetFirstVisibleItem()
46 while h.Ok():
47 rect = self.GetBoundingRect(h)
48 if rect is not None:
49 cy = rect.GetTop()
50 dc.DrawLine(0, cy, clientSize.x, cy)
51 lastH = h
52 h = self.GetNextVisible(h)
53
54 rect = self.GetBoundingRect(lastH)
55 if rect is not None:
56 cy = rect.GetBottom()
57 dc.DrawLine(0, cy, clientSize.x, cy)
58
59
60
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)
66
67 def OEB(self, evt):
68 pass
69
70 # This method is called to draw each item in the value window
71 def DrawItem(self, dc, itemId, rect):
72 tree = self.GetTreeCtrl()
73 if tree:
74 text = "This is "
75 parent = tree.GetItemParent(itemId)
76 if parent.IsOk():
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)
81 dc.SetPen(pen)
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)
87 x = 5
88 y = rect.y + max(0, (rect.height - th) / 2)
89 dc.DrawText(text, x, y)
90
91
92
93 class TestPanel(wxPanel):
94 def __init__(self, parent, log):
95 wxPanel.__init__(self, parent, -1)
96 self.log = log
97
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)
104
105 splitter.SplitVertically(self.tree, valueWindow)
106 splitter.SetSashPosition(150)
107 scroller.SetTargetWindow(self.tree)
108 scroller.EnableScrolling(FALSE, FALSE)
109
110 valueWindow.SetTreeCtrl(self.tree)
111 self.tree.SetCompanionWindow(valueWindow)
112
113
114
115 #----------------------------------------------------------------------
116
117 def runTest(frame, nb, log):
118 win = TestPanel(nb, log)
119 return win
120
121
122 #----------------------------------------------------------------------
123
124
125
126
127
128 overview = """\
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.
134 """
135
136