]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
5 | # 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
6 | # | |
7 | # o Bigtime errors on startup. Blows up with a program error. | |
8 | # Error: | |
9 | # | |
10 | # 21:04:11: Debug: ..\..\src\msw\treectrl.cpp(1508): assert "IsVisible(item)" | |
11 | # failed: The item you call GetNextVisible() for must be visible itself! | |
12 | # | |
13 | # I suspect this error is in the lib itself. | |
14 | # | |
15 | ||
16 | import wx | |
17 | import wx.gizmos as gizmos | |
18 | ||
19 | import images | |
611dc22c RD |
20 | |
21 | #---------------------------------------------------------------------- | |
22 | ||
8fa876ca RD |
23 | class TestTree(gizmos.RemotelyScrolledTreeCtrl): |
24 | def __init__(self, parent, style=wx.TR_HAS_BUTTONS): | |
25 | gizmos.RemotelyScrolledTreeCtrl.__init__(self, parent, -1, style=style) | |
611dc22c RD |
26 | |
27 | # make an image list | |
68673975 | 28 | im1 = im2 = -1 |
8fa876ca | 29 | self.il = wx.ImageList(16, 16) |
78e8819c RD |
30 | im1 = self.il.Add(images.getFolder1Bitmap()) |
31 | im2 = self.il.Add(images.getFile1Bitmap()) | |
32 | self.SetImageList(self.il) | |
611dc22c RD |
33 | |
34 | # Add some items | |
35 | root = self.AddRoot("Root") | |
8fa876ca | 36 | |
611dc22c RD |
37 | for i in range(30): |
38 | item = self.AppendItem(root, "Item %d" % i, im1) | |
8fa876ca | 39 | |
611dc22c | 40 | for j in range(10): |
78e8819c | 41 | child = self.AppendItem(item, "Child %d" % j, im2) |
611dc22c RD |
42 | |
43 | self.Expand(root) | |
44 | ||
45 | ||
46 | ||
8fa876ca RD |
47 | class TestValueWindow(gizmos.TreeCompanionWindow): |
48 | def __init__(self, parent, style=0): | |
49 | gizmos.TreeCompanionWindow.__init__(self, parent, -1, style=style) | |
611dc22c RD |
50 | self.SetBackgroundColour("WHITE") |
51 | ||
52 | # This method is called to draw each item in the value window | |
53 | def DrawItem(self, dc, itemId, rect): | |
54 | tree = self.GetTreeCtrl() | |
8fa876ca | 55 | |
611dc22c RD |
56 | if tree: |
57 | text = "This is " | |
58 | parent = tree.GetItemParent(itemId) | |
8fa876ca | 59 | |
611dc22c RD |
60 | if parent.IsOk(): |
61 | ptext = tree.GetItemText(parent) | |
62 | text = text + ptext + " --> " | |
8fa876ca | 63 | |
611dc22c | 64 | text = text + tree.GetItemText(itemId) |
8fa876ca | 65 | pen = wx.Pen( |
317d1550 | 66 | wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DLIGHT), |
8fa876ca RD |
67 | 1, wx.SOLID |
68 | ) | |
69 | ||
78e8819c | 70 | dc.SetPen(pen) |
8fa876ca | 71 | dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) |
d7403ad2 | 72 | dc.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1) |
611dc22c | 73 | dc.SetTextForeground("BLACK") |
8fa876ca | 74 | dc.SetBackgroundMode(wx.TRANSPARENT) |
611dc22c RD |
75 | tw, th = dc.GetTextExtent(text) |
76 | x = 5 | |
77 | y = rect.y + max(0, (rect.height - th) / 2) | |
d7403ad2 | 78 | dc.DrawText(text, x, y) |
611dc22c RD |
79 | |
80 | ||
81 | ||
8fa876ca | 82 | class TestPanel(wx.Panel): |
611dc22c | 83 | def __init__(self, parent, log): |
22c35d91 | 84 | wx.Panel.__init__(self, parent, -1, size=(640,480)) |
611dc22c RD |
85 | self.log = log |
86 | ||
8fa876ca RD |
87 | scroller = gizmos.SplitterScrolledWindow( |
88 | self, -1, style=wx.NO_BORDER | wx.CLIP_CHILDREN | wx.VSCROLL | |
89 | ) | |
90 | ||
91 | splitter = gizmos.ThinSplitterWindow( | |
92 | scroller, -1, style=wx.SP_3DBORDER | wx.CLIP_CHILDREN | |
93 | ) | |
94 | ||
611dc22c | 95 | splitter.SetSashSize(2) |
317d1550 RD |
96 | tree = TestTree(splitter, style = wx.TR_HAS_BUTTONS | |
97 | wx.TR_NO_LINES | | |
98 | wx.TR_ROW_LINES | | |
99 | #wx.TR_HIDE_ROOT | | |
100 | wx.NO_BORDER ) | |
8fa876ca RD |
101 | |
102 | valueWindow = TestValueWindow(splitter, style=wx.NO_BORDER) | |
611dc22c | 103 | |
4b7887a9 | 104 | wx.CallAfter(splitter.SplitVertically, tree, valueWindow, 150) |
52ad59c2 | 105 | scroller.SetTargetWindow(tree) |
1e4a197e | 106 | scroller.EnableScrolling(False, False) |
611dc22c | 107 | |
52ad59c2 RD |
108 | valueWindow.SetTreeCtrl(tree) |
109 | tree.SetCompanionWindow(valueWindow) | |
611dc22c | 110 | |
8fa876ca RD |
111 | sizer = wx.BoxSizer(wx.VERTICAL) |
112 | sizer.Add(scroller, 1, wx.EXPAND|wx.ALL, 25) | |
68320e40 | 113 | self.SetSizer(sizer) |
22c35d91 | 114 | self.Layout() |
611dc22c RD |
115 | |
116 | #---------------------------------------------------------------------- | |
117 | ||
118 | def runTest(frame, nb, log): | |
8fa876ca | 119 | if wx.Platform == "__WXMAC__": |
c4ef95da RD |
120 | from Main import MessagePanel |
121 | win = MessagePanel(nb, 'This demo currently fails on the Mac. The problem is being looked into...', | |
122 | 'Sorry', wx.ICON_WARNING) | |
123 | return win | |
1e4a197e | 124 | |
611dc22c RD |
125 | win = TestPanel(nb, log) |
126 | return win | |
127 | ||
128 | ||
129 | #---------------------------------------------------------------------- | |
130 | ||
131 | ||
611dc22c RD |
132 | overview = """\ |
133 | This demo shows a collection of classes that were designed to operate | |
134 | together and provide a tree control with additional columns for each | |
8fa876ca RD |
135 | item. The classes are wx.RemotelyScrolledTreeCtrl, wx.TreeCompanionWindow, |
136 | wx.ThinSplitterWindow, and wx.SplitterScrolledWindow, some of which may | |
611dc22c RD |
137 | also be useful by themselves. |
138 | """ | |
139 | ||
140 | ||
63b6646e RD |
141 | |
142 | if __name__ == '__main__': | |
143 | import sys,os | |
144 | import run | |
8eca4fef | 145 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) |
63b6646e | 146 |