]>
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 | 15 | im1 = im2 = -1 |
78e8819c RD |
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): | |
78e8819c | 26 | child = self.AppendItem(item, "Child %d" % j, im2) |
611dc22c RD |
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") | |
78e8819c RD |
36 | EVT_ERASE_BACKGROUND(self, self.OEB) |
37 | ||
38 | def OEB(self, evt): | |
39 | pass | |
611dc22c RD |
40 | |
41 | # This method is called to draw each item in the value window | |
42 | def DrawItem(self, dc, itemId, rect): | |
43 | tree = self.GetTreeCtrl() | |
44 | if tree: | |
45 | text = "This is " | |
46 | parent = tree.GetItemParent(itemId) | |
47 | if parent.IsOk(): | |
48 | ptext = tree.GetItemText(parent) | |
49 | text = text + ptext + " --> " | |
50 | text = text + tree.GetItemText(itemId) | |
78e8819c RD |
51 | pen = wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID) |
52 | dc.SetPen(pen) | |
53 | dc.SetBrush(wxBrush(self.GetBackgroundColour(), wxSOLID)) | |
54 | dc.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height) | |
611dc22c RD |
55 | dc.SetTextForeground("BLACK") |
56 | dc.SetBackgroundMode(wxTRANSPARENT) | |
57 | tw, th = dc.GetTextExtent(text) | |
58 | x = 5 | |
59 | y = rect.y + max(0, (rect.height - th) / 2) | |
60 | dc.DrawText(text, x, y) | |
61 | ||
62 | ||
63 | ||
64 | class TestPanel(wxPanel): | |
65 | def __init__(self, parent, log): | |
66 | wxPanel.__init__(self, parent, -1) | |
67 | self.log = log | |
68 | ||
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) | |
07c99b26 RD |
73 | self.tree = TestTree(splitter, -1, style = |
74 | wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxTR_ROW_LINES | wxNO_BORDER ) | |
611dc22c RD |
75 | valueWindow = TestValueWindow(splitter, -1, style=wxNO_BORDER) |
76 | ||
77 | splitter.SplitVertically(self.tree, valueWindow) | |
78 | splitter.SetSashPosition(150) | |
79 | scroller.SetTargetWindow(self.tree) | |
80 | scroller.EnableScrolling(FALSE, FALSE) | |
81 | ||
82 | valueWindow.SetTreeCtrl(self.tree) | |
83 | self.tree.SetCompanionWindow(valueWindow) | |
84 | ||
85 | ||
86 | ||
87 | #---------------------------------------------------------------------- | |
88 | ||
89 | def runTest(frame, nb, log): | |
90 | win = TestPanel(nb, log) | |
91 | return win | |
92 | ||
93 | ||
94 | #---------------------------------------------------------------------- | |
95 | ||
96 | ||
97 | ||
98 | ||
99 | ||
100 | overview = """\ | |
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. | |
106 | """ | |
107 | ||
108 |