phoenix_title wx.lib.mixins.treemixin.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):
    # Other code here

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.


class_hierarchy Class Hierarchy

Inheritance diagram for class ExpansionState:

sub_classes Known Subclasses

wx.lib.agw.shortcuteditor.ListShortcut


super_classes Known Superclasses

wx.lib.mixins.treemixin.TreeAPIHarmonizer, wx.lib.mixins.treemixin.TreeHelper


method_summary Methods Summary

GetExpansionState

GetExpansionState() -> list of expanded items. Expanded items

GetExpansionStateOfChildren

GetExpansionStateOfItem

GetItemIdentity

Return a hashable object that represents the identity of the

SetExpansionState

SetExpansionState(listOfExpandedItems). Expands all tree items

SetExpansionStateOfChildren

SetExpansionStateOfItem


property_summary Properties Summary

ExpansionState

GetExpansionState() -> list of expanded items. Expanded items


api Class API

class ExpansionState(TreeAPIHarmonizer, TreeHelper)

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):
    # Other code here

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.


Methods

GetExpansionState(self)

GetExpansionState() -> list of expanded items. 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. 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(self, listOfExpandedItems)

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)

Properties

ExpansionState

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