Tree node collapse event : Tree « wxPython « Python Tutorial

Python Tutorial
1. Introduction
2. Data Type
3. Statement
4. Operator
5. String
6. Tuple
7. List
8. Dictionary
9. Collections
10. Function
11. Class
12. File
13. Buildin Function
14. Buildin Module
15. Database
16. Regular Expressions
17. Thread
18. Tkinker
19. wxPython
20. XML
21. Network
22. CGI Web
23. Windows
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python Tutorial » wxPython » Tree 
19. 45. 9. Tree node collapse event
Tree node collapse event
import wx

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="tree: misc tests", size=(400,500))

        il = wx.ImageList(16,16)

        self.fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16,16)))
        self.fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,   wx.ART_OTHER, (16,16)))
        self.fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, (16,16)))
        
        self.tree = wx.TreeCtrl(self, style=wx.TR_DEFAULT_STYLE | wx.TR_EDIT_LABELS)

        self.tree.AssignImageList(il)

        root = self.tree.AddRoot("wx.Object")
        self.tree.SetItemPyData(root, None)
        self.tree.SetItemImage(root, self.fldridx,wx.TreeItemIcon_Normal)
        self.tree.SetItemImage(root, self.fldropenidx,wx.TreeItemIcon_Expanded)
        
        tree = ["A","B","C","D","E","F","G","H"]

        self.AddTreeNodes(root, tree)

        self.tree.Expand(root)

        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree)
            

    def OnItemCollapsed(self, evt):
        print "OnItemCollapsed:", self.GetItemText(evt.GetItem())
    def AddTreeNodes(self, parentItem, items):
        for item in items:
            if type(item== str:
                newItem = self.tree.AppendItem(parentItem, item)
                self.tree.SetItemPyData(newItem, None)
                self.tree.SetItemImage(newItem, self.fileidx,wx.TreeItemIcon_Normal)
            else:
                newItem = self.tree.AppendItem(parentItem, item[0])
                self.tree.SetItemPyData(newItem, None)
                self.tree.SetItemImage(newItem, self.fldridx,wx.TreeItemIcon_Normal)
                self.tree.SetItemImage(newItem, self.fldropenidx,wx.TreeItemIcon_Expanded)
   
                self.AddTreeNodes(newItem, item[1])

app = wx.PySimpleApp(redirect=True)
frame = TestFrame()
frame.Show()
app.MainLoop()
19. 45. Tree
19. 45. 1. Create a tree and expand its childrenCreate a tree and expand its children
19. 45. 2. Set tree iconSet tree icon
19. 45. 3. Print tree node outPrint tree node out
19. 45. 4. Edit tree nodeEdit tree node
19. 45. 5. Sort tree nodesSort tree nodes
19. 45. 6. Delete a tree nodeDelete a tree node
19. 45. 7. Find a tree nodeFind a tree node
19. 45. 8. Tree node expanded eventTree node expanded event
19. 45. 9. Tree node collapse eventTree node collapse event
19. 45. 10. Tree node selection changed eventTree node selection changed event
19. 45. 11. Tree node activated eventTree node activated event
19. 45. 12. Tree node begin edit eventTree node begin edit event
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.