.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. currentmodule:: wx.lib.mixins.treemixin .. highlight:: python .. _wx.lib.mixins.treemixin.ExpansionState: ========================================================================================================================================== |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 ================================= .. raw:: html
Inheritance diagram for class ExpansionState:
| |sub_classes| Known Subclasses ============================== :class:`wx.lib.agw.shortcuteditor.ListShortcut` | |super_classes| Known Superclasses ================================== :class:`wx.lib.mixins.treemixin.TreeAPIHarmonizer`, :class:`wx.lib.mixins.treemixin.TreeHelper` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.lib.mixins.treemixin.ExpansionState.GetExpansionState` GetExpansionState() -> list of expanded items. Expanded items :meth:`~wx.lib.mixins.treemixin.ExpansionState.GetExpansionStateOfChildren` :meth:`~wx.lib.mixins.treemixin.ExpansionState.GetExpansionStateOfItem` :meth:`~wx.lib.mixins.treemixin.ExpansionState.GetItemIdentity` Return a hashable object that represents the identity of the :meth:`~wx.lib.mixins.treemixin.ExpansionState.SetExpansionState` SetExpansionState(listOfExpandedItems). Expands all tree items :meth:`~wx.lib.mixins.treemixin.ExpansionState.SetExpansionStateOfChildren` :meth:`~wx.lib.mixins.treemixin.ExpansionState.SetExpansionStateOfItem` ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.lib.mixins.treemixin.ExpansionState.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. .. method:: GetExpansionState(self) GetExpansionState() -> list of expanded items. Expanded items are coded as determined by the result of GetItemIdentity(item). .. method:: GetExpansionStateOfChildren(self, item) .. method:: GetExpansionStateOfItem(self, item) .. method:: 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. .. method:: 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. .. method:: SetExpansionStateOfChildren(self, listOfExpandedItems, item) .. method:: SetExpansionStateOfItem(self, listOfExpandedItems, item) .. attribute:: ExpansionState GetExpansionState() -> list of expanded items. Expanded items are coded as determined by the result of GetItemIdentity(item).