%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core22/current/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core22/current/lib/python3/dist-packages/urwid/__pycache__/treetools.cpython-310.pyc

o

��o_7=�@s�ddlmZmZ	ddlZddlmZGdd�de�ZGdd�dej�Z	Gdd	�d	e
�ZGd
d�de�ZGdd
�d
ej
�ZGdd�dej�ZdS)�)�division�print_functionN)�SelectableIconc@seZdZdS)�TreeWidgetErrorN)�__name__�
__module__�__qualname__�r	r	�1/usr/lib/python3/dist-packages/urwid/treetools.pyr&src@s�eZdZdZdZedd�Zedd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�
TreeWidgetz9A widget representing something in a nested tree display.��+r�-cCs8||_d|_t|d�|_d|_|��}|j�|�dS)N�get_first_childT)�_node�_innerwidget�hasattr�is_leaf�expanded�get_indented_widget�_TreeWidget__super�__init__)�self�node�widgetr	r	r
r0szTreeWidget.__init__cCs|jS)zS
        Allow selection of non-leaf nodes so children may be (un)expanded
        )r�rr	r	r
�
selectable8�zTreeWidget.selectablecCsL|��}|jstjdd|j|jg|jf|gdd�}|��}tj|d|d�S)N�fixed�)�dividechars)�relative�d)�width�left)	�get_inner_widgetr�urwid�Columns�unexpanded_icon�
expanded_iconr�get_indent_cols�Padding)rr�indent_colsr	r	r
r>s����zTreeWidget.get_indented_widgetcCs |j|jg|j|jjjd<dS)z-Update display widget text for parent widgetsrN)r(r)r�_w�base_widget�widget_listrr	r	r
�update_expanded_iconHs��zTreeWidget.update_expanded_iconcCs|j|����S�N)r,�get_node�	get_depthrr	r	r
r*NszTreeWidget.get_indent_colscCs|jdur
|��|_|jSr1)r�load_inner_widgetrr	r	r
r%Qs

zTreeWidget.get_inner_widgetcCst�|���Sr1)r&�Text�get_display_textrr	r	r
r4VszTreeWidget.load_inner_widgetcC�|jSr1)rrr	r	r
r2Y�zTreeWidget.get_nodecCs |����dt|�����S)Nz: )r2�get_key�str�	get_valuerr	r	r
r6\s�zTreeWidget.get_display_textcCs�|��}|dur
|S|��}|��}|��}|dur:|dkr:|��}|��}|d8}||��ks2J�|dur:|dks|dur@dS|��S)z5Return the next TreeWidget depth first from this one.Nrr)�first_childr2�next_siblingr3�
get_parent�
get_widget)r�
firstchild�thisnode�nextnode�depthr	r	r
�next_inorder`s�zTreeWidget.next_inordercCsj|j}|��}|dur|��}|��}|dur|S|S|��}|dur)|dkr)dS|dur1|��}|��S)z9Return the previous TreeWidget depth first from this one.Nr)r�prev_siblingr?�
last_childr3r>)rrA�prevnode�
prevwidget�	lastchildrCr	r	r
�prev_inorderwszTreeWidget.prev_inordercCsZ|jr|S|dvrd|_|��dS|dkrd|_|��dS|j��r+|j�||�S|S)z2Handle expand & collapse requests (non-leaf nodes))r
�rightTrFN)rrr0r-rr�keypress�r�size�keyr	r	r
rL�s
zTreeWidget.keypresscCsH|js|dks|dkr
dS|dkr"||��kr"|j|_|��dSdS)Nzmouse pressrFrT)rr*rr0)rrN�event�button�col�row�focusr	r	r
�mouse_event�s
zTreeWidget.mouse_eventcCs0|js|jsdS|j��r|j��}|��SdS)zReturn first child if expanded.N)rrr�has_childrenrr?)r�	firstnoder	r	r
r<�s

zTreeWidget.first_childcCsF|js|jsdS|j��r|j����}ndS|��}|dur!|S|S)zReturn last child if expanded.N)rrrrV�get_last_childr?rF)rrI�lastdescendantr	r	r
rF�s
zTreeWidget.last_childN)rrr�__doc__r,rr(r)rrrr0r*r%r4r2r6rDrJrLrUr<rFr	r	r	r
r*s(


rc@s�eZdZdZd"dd�Zd#dd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�ZdS)$�TreeNodea:
    Store tree contents and cache TreeWidget objects.
    A TreeNode consists of the following elements:
    *  key: accessor token for parent nodes
    *  value: subclass-specific data
    *  parent: a TreeNode which contains a pointer back to this object
    *  widget: The widget used to render the object
    NcCs"||_||_||_||_d|_dSr1)�_key�_parent�_value�_depth�_widget�r�value�parentrOrCr	r	r
r�s

zTreeNode.__init__FcC�"|jdus	|dkr|��|_|jS)z! Return the widget for this node.NT)r`�load_widget�r�reloadr	r	r
r?��
zTreeNode.get_widgetcCst|�Sr1)rrr	r	r
re�szTreeNode.load_widgetcCs@|jdur|jdurd|_|jS|jdur|j��d|_|jS)Nrr)r_r]r3rr	r	r
r3�s
�zTreeNode.get_depthcCs*|��dkrdS|��}|��}|�|�S�Nr)r3r9r>�get_child_index)rrOrcr	r	r
�	get_index�s

zTreeNode.get_indexcCr7r1�r\rr	r	r
r9�r8zTreeNode.get_keycCs
||_dSr1rl�rrOr	r	r
�set_key��
zTreeNode.set_keycCs|���|j|�dSr1)r>�change_child_keyr\rmr	r	r
�
change_key�szTreeNode.change_keycCs&|jdkr|��dkr|��|_|jSri)r]r3�load_parentrr	r	r
r>�s
zTreeNode.get_parentcC�td��)z�Provide TreeNode with a parent for the current node.  This function
        is only required if the tree was instantiated from a child node
        (virtual function)�(virtual function.  Implement in subclass�rrr	r	r
rr�rzTreeNode.load_parentcCr7r1)r^rr	r	r
r;r8zTreeNode.get_valuecCs|��dkSri)r3rr	r	r
�is_rootszTreeNode.is_rootcC�"|��dkr|���|���SdSri)r3r>�
next_childr9rr	r	r
r=�zTreeNode.next_siblingcCrwri)r3r>�
prev_childr9rr	r	r
rEryzTreeNode.prev_siblingcCs(|}|��dur|��}|��dus|Sr1)r>)r�rootr	r	r
�get_roots
�zTreeNode.get_root�NNN�F)rrrrZrr?rer3rkr9rnrqr>rrr;rvr=rEr|r	r	r	r
r[�s"

r[c@s�eZdZdZd dd�Zd!dd�Zdd	�Zd
d�Zd!dd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)"�
ParentNodez"Maintain sort order for TreeNodes.NcCs$tj|||||d�d|_i|_dS)N)rcrOrC)r[r�_child_keys�	_childrenrar	r	r
rs
zParentNode.__init__FcCrd)z,Return a possibly ordered list of child keysNT)r��load_child_keysrfr	r	r
�get_child_keys!rhzParentNode.get_child_keyscCrs)zPProvide ParentNode with an ordered list of child keys (virtual
        function)rtrurr	r	r
r�'szParentNode.load_child_keyscCs|�|�}|��S)z8Return the widget for a given key.  Create if necessary.)�get_child_noder?)rrO�childr	r	r
�get_child_widget,s
zParentNode.get_child_widgetcCs,||jvs	|dkr|�|�|j|<|j|S)z<Return the child node for a given key.  Create if necessary.T)r��load_child_node)rrOrgr	r	r
r�2s
zParentNode.get_child_nodecCrs)z6Load the child node for a given key (virtual function)rtrurmr	r	r
r�8szParentNode.load_child_nodecCs||j|<dS)z]Set the child node for a given key.  Useful for bottom-up, lazy
        population of a tree.N)r�)rrOrr	r	r
�set_child_node<szParentNode.set_child_nodecCs<||jvrtd|��|j�|�|j|<|j|�|�dS)Nz%s is already in use)r�r�poprn)r�oldkey�newkeyr	r	r
rpAs
zParentNode.change_child_keyc
CsBz|���|�WSty d}t|||��t|���f��w)Nz7Can't find key %s in ParentNode %s
ParentNode items: %s)r��index�
ValueErrorrr9r:)rrO�errorstringr	r	r
rjGs
��zParentNode.get_child_indexcCsD|�|�}|durdS|d7}|��}|t|�kr |�||�SdS)z=Return the next child node in index order from the given key.Nr)rjr��lenr��rrOr��
child_keysr	r	r
rxPs
zParentNode.next_childcCs@|�|�}|durdS|��}|d8}|dkr|�||�SdS)zAReturn the previous child node in index order from the given key.Nrr)rjr�r�r�r	r	r
rz`s
zParentNode.prev_childcC�|��}|�|d�S)z+Return the first TreeNode in the directory.r�r�r��rr�r	r	r
ro�zParentNode.get_first_childcCr�)z*Return the last TreeNode in the directory.���r�r�r	r	r
rXtr�zParentNode.get_last_childcCst|���dkS)z!Does this node have any children?r)r�r�rr	r	r
rVyszParentNode.has_childrenr}r~)rrrrZrr�r�r�r�r�r�rprjrxrzrrXrVr	r	r	r
rs 


	rc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
TreeWalkerzTListWalker-compatible class for displaying TreeWidgets

    positions are TreeNodes.cCs
||_dS)z,start_from: TreeNode with the initial focus.N)rT)r�
start_fromr	r	r
r�s
zTreeWalker.__init__cCs|j��}||jfSr1)rTr?)rrr	r	r
�	get_focus�s

zTreeWalker.get_focuscCs||_|��dSr1)rT�	_modified)rrTr	r	r
�	set_focus�szTreeWalker.set_focuscC�(|��}|��}|durdS||��fS�N)NN)r?rDr2�rr�r�targetr	r	r
�get_next��
zTreeWalker.get_nextcCr�r�)r?rJr2r�r	r	r
�get_prev�r�zTreeWalker.get_prevN)	rrrrZrr�r�r�r�r	r	r	r
r�~sr�c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TreeListBoxzPA ListBox with special handling for navigation and
    collapsing of TreeWidgetscCs|j�||�}|�||�Sr1)�_TreeListBox__superrL�unhandled_inputrMr	r	r
rL�szTreeListBox.keypresscCs0|dkr|�|�dS|dkr|�|�dS|S)zHandle macro-navigation keysr$rN)�move_focus_to_parent�collapse_focus_parent)rrN�inputr	r	r
r��s
zTreeListBox.unhandled_inputcCsB|j��\}}|�|�|j��\}}||kr|�|d�dSdS)zCollapse parent directory.rN)�bodyr�r�rL)rrNr�pos�pwidget�pposr	r	r
r��s
�z!TreeListBox.collapse_focus_parentcCs�|j��\}}|��}|durdS|�|�\}}}|\}}	}
}}|\}
}|D]\}}}||8}||kr=|�|||�dSq&|�||���dS)z(Move focus to parent of widget in focus.N)r�r�r>�calculate_visible�change_focus)rrNrr��	parentpos�middle�top�bottom�
row_offset�focus_widget�	focus_pos�
focus_rows�cursor�trim_top�
fill_above�rowsr	r	r
r��s�z TreeListBox.move_focus_to_parentcC�
|�|�Sr1)�
focus_home�rrNr	r	r
�_keypress_max_left�rozTreeListBox._keypress_max_leftcCr�r1)�	focus_endr�r	r	r
�_keypress_max_right�rozTreeListBox._keypress_max_rightcCs&|j��\}}|��}|�||�dS)zMove focus to very top.N)r�r�r|r�)rrNrr��rootnoder	r	r
r��szTreeListBox.focus_homec
CsT|\}}|j��\}}|��}|��}|��}|r(|��}	|�||	|d�dSdS)zMove focus to far bottom.rN)r�r�r|r?rFr2r�)
rrN�maxrow�maxcolrr�r��
rootwidget�
lastwidget�lastnoder	r	r
r��s�zTreeListBox.focus_endN)rrrrZrLr�r�r�r�r�r�r�r	r	r	r
r��s	
r�)�
__future__rrr&�
urwid.wimpr�RuntimeErrorr�
WidgetWrapr�objectr[r�
ListWalkerr��ListBoxr�r	r	r	r
�<module>s	Ue"

Zerion Mini Shell 1.0