]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/SplitTree.py
digital mars updated
[wxWidgets.git] / wxPython / demo / SplitTree.py
CommitLineData
611dc22c
RD
1from wxPython.wx import *
2from wxPython.gizmos import *
3
4import images
5
6#----------------------------------------------------------------------
7
8class 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)
611dc22c
RD
12
13 # make an image list
68673975 14 im1 = im2 = -1
78e8819c
RD
15 self.il = wxImageList(16, 16)
16 im1 = self.il.Add(images.getFolder1Bitmap())
17 im2 = self.il.Add(images.getFile1Bitmap())
18 self.SetImageList(self.il)
611dc22c
RD
19
20 # Add some items
21 root = self.AddRoot("Root")
22 for i in range(30):
23 item = self.AppendItem(root, "Item %d" % i, im1)
24 for j in range(10):
78e8819c 25 child = self.AppendItem(item, "Child %d" % j, im2)
611dc22c
RD
26
27 self.Expand(root)
28
29
30
31class TestValueWindow(wxTreeCompanionWindow):
32 def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, style=0):
33 wxTreeCompanionWindow.__init__(self, parent, ID, pos, size, style)
34 self.SetBackgroundColour("WHITE")
78e8819c
RD
35 EVT_ERASE_BACKGROUND(self, self.OEB)
36
37 def OEB(self, evt):
38 pass
611dc22c
RD
39
40 # This method is called to draw each item in the value window
41 def DrawItem(self, dc, itemId, rect):
42 tree = self.GetTreeCtrl()
43 if tree:
44 text = "This is "
45 parent = tree.GetItemParent(itemId)
46 if parent.IsOk():
47 ptext = tree.GetItemText(parent)
48 text = text + ptext + " --> "
49 text = text + tree.GetItemText(itemId)
78e8819c
RD
50 pen = wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID)
51 dc.SetPen(pen)
52 dc.SetBrush(wxBrush(self.GetBackgroundColour(), wxSOLID))
52ad59c2 53 dc.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
611dc22c
RD
54 dc.SetTextForeground("BLACK")
55 dc.SetBackgroundMode(wxTRANSPARENT)
56 tw, th = dc.GetTextExtent(text)
57 x = 5
58 y = rect.y + max(0, (rect.height - th) / 2)
59 dc.DrawText(text, x, y)
60
61
62
63class TestPanel(wxPanel):
64 def __init__(self, parent, log):
65 wxPanel.__init__(self, parent, -1)
66 self.log = log
67
68320e40 68 scroller = wxSplitterScrolledWindow(self, -1, #(50,50), (350, 250),
611dc22c
RD
69 style=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL)
70 splitter = wxThinSplitterWindow(scroller, -1, style=wxSP_3DBORDER | wxCLIP_CHILDREN)
71 splitter.SetSashSize(2)
52ad59c2
RD
72 tree = TestTree(splitter, -1, style = wxTR_HAS_BUTTONS |
73 wxTR_NO_LINES |
74 wxTR_ROW_LINES |
63b6646e 75 #wxTR_HIDE_ROOT |
52ad59c2 76 wxNO_BORDER )
611dc22c
RD
77 valueWindow = TestValueWindow(splitter, -1, style=wxNO_BORDER)
78
1e4a197e 79 splitter.SplitVertically(tree, valueWindow, 150)
52ad59c2 80 scroller.SetTargetWindow(tree)
1e4a197e 81 scroller.EnableScrolling(False, False)
611dc22c 82
52ad59c2
RD
83 valueWindow.SetTreeCtrl(tree)
84 tree.SetCompanionWindow(valueWindow)
611dc22c 85
68320e40
RD
86 sizer = wxBoxSizer(wxVERTICAL)
87 sizer.Add(scroller, 1, wxEXPAND|wxALL, 25)
1e4a197e 88 self.SetAutoLayout(True)
68320e40 89 self.SetSizer(sizer)
611dc22c
RD
90
91
92#----------------------------------------------------------------------
93
94def runTest(frame, nb, log):
1e4a197e
RD
95 if wxPlatform == "__WXMAC__":
96 wxMessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
97 return
98
611dc22c
RD
99 win = TestPanel(nb, log)
100 return win
101
102
103#----------------------------------------------------------------------
104
105
106
107
108
109overview = """\
110This demo shows a collection of classes that were designed to operate
111together and provide a tree control with additional columns for each
112item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
113wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
114also be useful by themselves.
115"""
116
117
63b6646e
RD
118
119if __name__ == '__main__':
120 import sys,os
121 import run
122 run.main(['', os.path.basename(sys.argv[0])])
123