]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/SplitTree.py
1 # 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7 # o Bigtime errors on startup. Blows up with a program error.
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!
13 # I suspect this error is in the lib itself.
17 import wx
.gizmos
as gizmos
20 #----------------------------------------------------------------------
22 class TestTree(gizmos
.RemotelyScrolledTreeCtrl
):
23 def __init__(self
, parent
, style
=wx
.TR_HAS_BUTTONS
):
24 gizmos
.RemotelyScrolledTreeCtrl
.__init
__(self
, parent
, -1, style
=style
)
28 self
.il
= wx
.ImageList(16, 16)
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)))
31 self
.SetImageList(self
.il
)
34 root
= self
.AddRoot("Root")
37 item
= self
.AppendItem(root
, "Item %d" % i
, im1
)
40 child
= self
.AppendItem(item
, "Child %d" % j
, im2
)
46 class TestValueWindow(gizmos
.TreeCompanionWindow
):
47 def __init__(self
, parent
, style
=0):
48 gizmos
.TreeCompanionWindow
.__init
__(self
, parent
, -1, style
=style
)
49 self
.SetBackgroundColour("WHITE")
51 # This method is called to draw each item in the value window
52 def DrawItem(self
, dc
, itemId
, rect
):
53 tree
= self
.GetTreeCtrl()
57 parent
= tree
.GetItemParent(itemId
)
60 ptext
= tree
.GetItemText(parent
)
61 text
= text
+ ptext
+ " --> "
63 text
= text
+ tree
.GetItemText(itemId
)
65 wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_3DLIGHT
),
70 dc
.SetBrush(wx
.Brush(self
.GetBackgroundColour(), wx
.SOLID
))
71 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
+1, rect
.height
+1)
72 dc
.SetTextForeground("BLACK")
73 dc
.SetBackgroundMode(wx
.TRANSPARENT
)
74 tw
, th
= dc
.GetTextExtent(text
)
76 y
= rect
.y
+ max(0, (rect
.height
- th
) / 2)
77 dc
.DrawText(text
, x
, y
)
81 class TestPanel(wx
.Panel
):
82 def __init__(self
, parent
, log
):
83 wx
.Panel
.__init
__(self
, parent
, -1, size
=(640,480))
86 scroller
= gizmos
.SplitterScrolledWindow(
87 self
, -1, style
=wx
.NO_BORDER | wx
.CLIP_CHILDREN | wx
.VSCROLL
90 splitter
= gizmos
.ThinSplitterWindow(
91 scroller
, -1, style
=wx
.SP_3DBORDER | wx
.CLIP_CHILDREN
94 splitter
.SetSashSize(2)
95 tree
= TestTree(splitter
, style
= wx
.TR_HAS_BUTTONS |
101 valueWindow
= TestValueWindow(splitter
, style
=wx
.NO_BORDER
)
103 wx
.CallAfter(splitter
.SplitVertically
, tree
, valueWindow
, 150)
104 scroller
.SetTargetWindow(tree
)
105 scroller
.EnableScrolling(False, False)
107 valueWindow
.SetTreeCtrl(tree
)
108 tree
.SetCompanionWindow(valueWindow
)
110 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
111 sizer
.Add(scroller
, 1, wx
.EXPAND|wx
.ALL
, 25)
115 #----------------------------------------------------------------------
117 def runTest(frame
, nb
, log
):
118 if wx
.Platform
== "__WXMAC__":
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
)
124 win
= TestPanel(nb
, log
)
128 #----------------------------------------------------------------------
132 This demo shows a collection of classes that were designed to operate
133 together and provide a tree control with additional columns for each
134 item. The classes are wx.RemotelyScrolledTreeCtrl, wx.TreeCompanionWindow,
135 wx.ThinSplitterWindow, and wx.SplitterScrolledWindow, some of which may
136 also be useful by themselves.
141 if __name__
== '__main__':
144 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])