]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/tests/testTree.py
3 from wxPython
import wx
10 def __init__(self
, obj
):
12 # Uncomment next line to eliminate crash.
13 # GlobalObjList.append(self)
16 head
, tail
= os
.path
.split(self
.obj
)
22 def HasChildren(self
):
23 return os
.path
.isdir(self
.obj
)
26 objList
= os
.listdir(self
.obj
)
28 objList
= map(lambda obj
,parent
=self
.obj
: os
.path
.join(parent
,obj
),
30 objectList
= map(Obj
, objList
)
43 #----------------------------------------------------------------------
45 class pyTree(wx
.wxTreeCtrl
):
47 def __init__(self
, parent
, id, obj
):
48 wx
.wxTreeCtrl
.__init
__(self
, parent
, id)
49 self
.root
= self
.AddRoot(obj
.Name(), -1, -1, wx
.wxTreeItemData(''))
50 self
.SetPyData(self
.root
, obj
)
52 self
.SetItemHasChildren(self
.root
, wx
.TRUE
)
53 wx
.EVT_TREE_ITEM_EXPANDING(self
, self
.GetId(), self
.OnItemExpanding
)
54 wx
.EVT_TREE_ITEM_COLLAPSED(self
, self
.GetId(), self
.OnItemCollapsed
)
55 wx
.EVT_TREE_SEL_CHANGED(self
, self
.GetId(), self
.OnSelChanged
)
58 def SetOutput(self
, output
):
61 def OnItemExpanding(self
,event
):
62 item
= event
.GetItem()
63 obj
= self
.GetPyData(item
)
64 children
= obj
.Children()
65 for child
in children
:
66 new_item
= self
.AppendItem(item
, child
.Name(), -1, -1,
67 wx
.wxTreeItemData(''))
68 self
.SetPyData(new_item
, child
)
69 if child
.HasChildren():
70 self
.SetItemHasChildren(new_item
, wx
.TRUE
)
72 def OnItemCollapsed(self
, event
):
73 item
= event
.GetItem()
74 self
.DeleteChildren(item
)
76 def OnSelChanged(self
, event
):
79 obj
= self
.GetPyData( event
.GetItem() )
80 apply(self
.output
, (`obj`
,))
84 #----------------------------------------------------------------------
85 if __name__
== '__main__':
87 class MyFrame(wx
.wxFrame
):
90 wx
.wxFrame
.__init
__(self
, wx
.NULL
, -1, 'PyTreeItemData Test',
91 wx
.wxDefaultPosition
, wx
.wxSize(600,500))
92 split
= wx
.wxSplitterWindow(self
, -1)
94 if sys
.platform
== 'win32':
95 tree
= pyTree(split
, -1, Obj('C:\\'))
97 tree
= pyTree(split
, -1, Obj('/'))
99 text
= wx
.wxTextCtrl(split
, -1, '', wx
.wxDefaultPosition
,
100 wx
.wxDefaultSize
, wx
.wxTE_MULTILINE
)
101 split
.SplitVertically(tree
, text
, 200)
102 tree
.SetOutput(text
.SetValue
)
103 tree
.SelectItem(tree
.root
)
105 class MyApp(wx
.wxApp
):
110 self
.SetTopWindow(frame
)