]>
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
 
  21 #---------------------------------------------------------------------- 
  23 class TestTree(gizmos
.RemotelyScrolledTreeCtrl
): 
  24     def __init__(self
, parent
, style
=wx
.TR_HAS_BUTTONS
): 
  25         gizmos
.RemotelyScrolledTreeCtrl
.__init
__(self
, parent
, -1, style
=style
) 
  29         self
.il 
= wx
.ImageList(16, 16) 
  30         im1 
= self
.il
.Add(images
.getFolder1Bitmap()) 
  31         im2 
= self
.il
.Add(images
.getFile1Bitmap()) 
  32         self
.SetImageList(self
.il
) 
  35         root 
= self
.AddRoot("Root") 
  38             item 
= self
.AppendItem(root
, "Item %d" % i
, im1
) 
  41                 child 
= self
.AppendItem(item
, "Child %d" % j
, im2
) 
  47 class TestValueWindow(gizmos
.TreeCompanionWindow
): 
  48     def __init__(self
, parent
, style
=0): 
  49         gizmos
.TreeCompanionWindow
.__init
__(self
, parent
, -1, style
=style
) 
  50         self
.SetBackgroundColour("WHITE") 
  51         self
.Bind(wx
.EVT_ERASE_BACKGROUND
, self
.OEB
) 
  56     # This method is called to draw each item in the value window 
  57     def DrawItem(self
, dc
, itemId
, rect
): 
  58         tree 
= self
.GetTreeCtrl() 
  62             parent 
= tree
.GetItemParent(itemId
) 
  65                 ptext 
= tree
.GetItemText(parent
) 
  66                 text 
= text 
+ ptext 
+ " --> " 
  68             text 
= text 
+ tree
.GetItemText(itemId
) 
  70                 wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_3DLIGHT
),  
  75             dc
.SetBrush(wx
.Brush(self
.GetBackgroundColour(), wx
.SOLID
)) 
  76             dc
.DrawRectangle((rect
.x
, rect
.y
), (rect
.width
+1, rect
.height
+1)) 
  77             dc
.SetTextForeground("BLACK") 
  78             dc
.SetBackgroundMode(wx
.TRANSPARENT
) 
  79             tw
, th 
= dc
.GetTextExtent(text
) 
  81             y 
= rect
.y 
+ max(0, (rect
.height 
- th
) / 2) 
  82             dc
.DrawText(text
, (x
, y
)) 
  86 class TestPanel(wx
.Panel
): 
  87     def __init__(self
, parent
, log
): 
  88         wx
.Panel
.__init
__(self
, parent
, -1) 
  91         scroller 
= gizmos
.SplitterScrolledWindow( 
  92             self
, -1, style
=wx
.NO_BORDER | wx
.CLIP_CHILDREN | wx
.VSCROLL
 
  95         splitter 
= gizmos
.ThinSplitterWindow( 
  96             scroller
, -1, style
=wx
.SP_3DBORDER | wx
.CLIP_CHILDREN
 
  99         splitter
.SetSashSize(2) 
 100         tree 
= TestTree(splitter
, style 
= wx
.TR_HAS_BUTTONS |
 
 106         valueWindow 
= TestValueWindow(splitter
, style
=wx
.NO_BORDER
) 
 108         splitter
.SplitVertically(tree
, valueWindow
, 150) 
 109         scroller
.SetTargetWindow(tree
) 
 110         scroller
.EnableScrolling(False, False) 
 112         valueWindow
.SetTreeCtrl(tree
) 
 113         tree
.SetCompanionWindow(valueWindow
) 
 115         sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 116         sizer
.Add(scroller
, 1, wx
.EXPAND|wx
.ALL
, 25) 
 117         self
.SetAutoLayout(True) 
 121 #---------------------------------------------------------------------- 
 123 def runTest(frame
, nb
, log
): 
 124     if wx
.Platform 
== "__WXMAC__": 
 125         wx
.MessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry") 
 128     win 
= TestPanel(nb
, log
) 
 132 #---------------------------------------------------------------------- 
 136 This demo shows a collection of classes that were designed to operate 
 137 together and provide a tree control with additional columns for each 
 138 item.  The classes are wx.RemotelyScrolledTreeCtrl, wx.TreeCompanionWindow, 
 139 wx.ThinSplitterWindow, and wx.SplitterScrolledWindow, some of which may 
 140 also be useful by themselves. 
 145 if __name__ 
== '__main__': 
 148     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])