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