
    Iic                    t    d Z ddlmZ ddlmZ ddlZddlmZ  G d d      Z G d	 d
eej                        Z
y)a  
Selection management for wxPython tree controls.

Provides a mixin and ready-to-use control that automatically manages selection
state for tree controls:
- Auto-focus first item when control gains focus with no selection
- Helper to maintain valid selection after item deletion

Includes:
- TreeSelectionManagerMixin: For wx.TreeCtrl-style controls
- ManagedTreeCtrl: Ready-to-use tree with selection management

Requires: wxPython
    )annotations)AnyN   )FocusAfterDeletec                  l     e Zd ZdZej
                  d	 	 	 	 	 	 	 d fdZddZ	 	 	 	 	 	 	 	 ddZ xZ	S )	TreeSelectionManagerMixina  
    Mixin that manages selection for wx.TreeCtrl-style controls.

    Features:
    - Auto-selects first visible item when focused with no selection
    - Provides select_after_delete() to maintain valid selection after removal

    Args:
        focus_after_delete: Where to focus after deleting an item.
            FocusAfterDelete.PREVIOUS (default) or FocusAfterDelete.NEXT
    )focus_after_deletec                   t        |   |i | || _        | j                  t        j
                  | j                         y )N)super__init__r	   BindwxEVT_SET_FOCUS_on_tree_focus_ensure_selection)selfr	   argskwargs	__class__s       KC:\Users\dbart\PlayPalace11\clients\desktop\ui\enhance_wx\tree_selection.pyr   z"TreeSelectionManagerMixin.__init__+   s9     	$)&)"4		"""D$H$HI    c                   |j                          | j                         }|j                         ry| j                         }|j                         sy| j	                  |      \  }}|j                         r| j                  |       yy)zGAuto-select first visible item when tree gains focus with no selection.N)SkipGetSelectionIsOkGetRootItemGetFirstChild
SelectItem)r   evtselrootfirst_child_s         r   r   z9TreeSelectionManagerMixin._on_tree_focus_ensure_selection5   sp    
!88:!yy{++D1QOOK( r   c                   | j                   t        j                  k(  r||}}n||}}d}|r|j                         r|}n<|r|j                         r|}n'|r%|j                         r|| j	                         k7  r|}|r| j                  |       yy)a  Select an appropriate item after deletion.

        Call this AFTER deleting a tree item to move selection to the
        previous sibling, next sibling, or parent -- in order of preference
        based on the focus_after_delete setting.

        Args:
            parent: Parent of the deleted item.
            prev_sibling: Sibling before the deleted item, or None.
            next_sibling: Sibling after the deleted item, or None.
        N)r	   r   PREVIOUSr   r   r   )r   parentprev_siblingnext_siblingprimaryfallbacktargets          r   select_after_deletez-TreeSelectionManagerMixin.select_after_deleteB   s    " ""&6&?&?? ,lXG ,lXGw||~F(--/F&D4D4D4F*FFOOF# r   )r   r   r	   r   r   r   returnNone)r   zwx.FocusEventr,   r-   )r%   zwx.TreeItemIdr&   wx.TreeItemId | Noner'   r.   r,   r-   )
__name__
__module____qualname____doc__r   r$   r   r   r+   __classcell__)r   s   @r   r   r      st    
 0@/H/HJJ -J 	J
 
J)$$ +$ +	$
 
$r   r   c                      e Zd ZdZy)ManagedTreeCtrlz2A wx.TreeCtrl with automatic selection management.N)r/   r0   r1   r2    r   r   r5   r5   i   s    <r   r5   )r2   
__future__r   typingr   r   list_selectionr   r   TreeCtrlr5   r6   r   r   <module>r;      s8    #  	 ,C$ C$V	/ 	r   