]>
Commit | Line | Data |
---|---|---|
611dc22c RD |
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) | |
68673975 | 12 | ##self.SetBackgroundColour("LIGHT BLUE") |
611dc22c RD |
13 | |
14 | # make an image list | |
68673975 RD |
15 | im1 = im2 = -1 |
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) | |
611dc22c RD |
20 | |
21 | # Add some items | |
22 | root = self.AddRoot("Root") | |
23 | for i in range(30): | |
24 | item = self.AppendItem(root, "Item %d" % i, im1) | |
25 | for j in range(10): | |
26 | self.AppendItem(item, "Child %d" % j, im2) | |
27 | ||
28 | self.Expand(root) | |
29 | ||
30 | ||
31 | ||
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 | ||
37 | # This method is called to draw each item in the value window | |
38 | def DrawItem(self, dc, itemId, rect): | |
39 | tree = self.GetTreeCtrl() | |
40 | if tree: | |
41 | text = "This is " | |
42 | parent = tree.GetItemParent(itemId) | |
43 | if parent.IsOk(): | |
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) | |
50 | x = 5 | |
51 | y = rect.y + max(0, (rect.height - th) / 2) | |
52 | dc.DrawText(text, x, y) | |
53 | ||
54 | ||
55 | ||
56 | class TestPanel(wxPanel): | |
57 | def __init__(self, parent, log): | |
58 | wxPanel.__init__(self, parent, -1) | |
59 | self.log = log | |
60 | ||
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) | |
67 | ||
68 | splitter.SplitVertically(self.tree, valueWindow) | |
69 | splitter.SetSashPosition(150) | |
70 | scroller.SetTargetWindow(self.tree) | |
71 | scroller.EnableScrolling(FALSE, FALSE) | |
72 | ||
73 | valueWindow.SetTreeCtrl(self.tree) | |
74 | self.tree.SetCompanionWindow(valueWindow) | |
75 | ||
76 | ||
77 | ||
78 | #---------------------------------------------------------------------- | |
79 | ||
80 | def runTest(frame, nb, log): | |
81 | win = TestPanel(nb, log) | |
82 | return win | |
83 | ||
84 | ||
85 | #---------------------------------------------------------------------- | |
86 | ||
87 | ||
88 | ||
89 | ||
90 | ||
91 | overview = """\ | |
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. | |
97 | """ | |
98 | ||
99 |