Package wx :: Package lib :: Package mixins :: Module treemixin :: Class ExpansionState
[frames | no frames]

Type ExpansionState

       object --+    
                |    
TreeAPIHarmonizer --+
                    |
       object --+   |
                |   |
       TreeHelper --+
                    |
                   ExpansionState


This is a mixin class that can be used to save and restore
the expansion state (i.e. which items are expanded and which items
are collapsed) of a tree. It can be mixed in with wx.TreeCtrl, 
wx.gizmos.TreeListCtrl, or wx.lib.customtree.CustomTreeCtrl.

To use it derive a new class from this class and one of the tree
controls, e.g.:
class MyTree(ExpansionState, wx.TreeCtrl):
    ...

By default, ExpansionState uses the position of tree items in the tree 
to keep track of which items are expanded. This should be sufficient 
for the simple scenario where you save the expansion state of the tree 
when the user closes the application or file so that you can restore 
the expansion state when the user start the application or loads that 
file for the next session.  

If you need to add or remove items between the moments of saving and 
restoring the expansion state (e.g. in case of a multi-user application)
you must override GetItemIdentity so that saving and loading of the 
expansion doesn't depend on the position of items in the tree, but 
rather on some more stable characteristic of the underlying domain 
object, e.g. a social security number in case of persons or an isbn 
number in case of books.

Method Summary
list of expanded items GetExpansionState()
Expanded items are coded as determined by the result of GetItemIdentity(item).
  GetExpansionStateOfChildren(self, item)
  GetExpansionStateOfItem(self, item)
  GetItemIdentity(self, item)
Return a hashable object that represents the identity of the item.
  SetExpansionState(listOfExpandedItems)
Expands all tree items whose identity, as determined by GetItemIdentity(item), is present in the list and collapses all other tree items.
  SetExpansionStateOfChildren(self, listOfExpandedItems, item)
  SetExpansionStateOfItem(self, listOfExpandedItems, item)

Property Summary
  ExpansionState: GetExpansionState() -> list of expanded items.

Method Details

GetExpansionState()

Expanded items are coded as determined by the result of GetItemIdentity(item).

Returns:
list of expanded items

GetItemIdentity(self, item)

Return a hashable object that represents the identity of the item. By default this returns the position of the item in the tree. You may want to override this to return the item label (if you know that labels are unique and don't change), or return something that represents the underlying domain object, e.g. a database key.

SetExpansionState(listOfExpandedItems)

Expands all tree items whose identity, as determined by GetItemIdentity(item), is present in the list and collapses all other tree items.


Property Details

ExpansionState

GetExpansionState() -> list of expanded items. Expanded items are coded as determined by the result of GetItemIdentity(item).

Get Method:
GetExpansionState()
Set Method:
SetExpansionState(listOfExpandedItems)

Generated by Epydoc 2.1.20050511.rpd on Mon Feb 16 12:55:02 2009 http://epydoc.sf.net