%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2318/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2318/lib/python3/dist-packages/urwid/__pycache__/treetools.cpython-38.pyc

U

��dZ�<�@s�ddlmZmZddlZddlmZGdd�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
�
selectable8szTreeWidget.selectablecCsL|��}|js4tjdd|j|jg|jf|gdd�}|��}tj|d|d�S)NZfixed�)Zdividechars)�relative�d)�width�left)	�get_inner_widgetr�urwidZColumns�unexpanded_icon�
expanded_iconr�get_indent_colsZPadding)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�_wZbase_widgetZwidget_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|jdkr|��|_|jSr*)r�load_inner_widgetrr	r	r
r"Qs

zTreeWidget.get_inner_widgetcCst�|���Sr*)r#ZText�get_display_textrr	r	r
r-VszTreeWidget.load_inner_widgetcCs|jSr*)rrr	r	r
r+YszTreeWidget.get_nodecCs |����dt|�����S)Nz: )r+�get_key�str�	get_valuerr	r	r
r.\s�zTreeWidget.get_display_textcCs~|��}|dk	r|S|��}|��}|��}|dkrf|dkrf|��}|��}|d8}||��ks,t�q,|dkrrdS|��SdS)z5Return the next TreeWidget depth first from this one.Nrr)�first_childr+�next_siblingr,�
get_parent�AssertionError�
get_widget)rZ
firstchild�thisnodeZnextnode�depthr	r	r
�next_inorder`szTreeWidget.next_inordercCsp|j}|��}|dk	r8|��}|��}|dkr2|S|Sn4|��}|dkrT|dkrTdS|dkrd|��}|��SdS)z9Return the previous TreeWidget depth first from this one.Nr)r�prev_siblingr6�
last_childr,r4)rr7ZprevnodeZ
prevwidget�	lastchildr8r	r	r
�prev_inorderwszTreeWidget.prev_inordercCsZ|jr
|S|dkr"d|_|��n4|dkr:d|_|��n|j��rR|j�||�S|SdS)z2Handle expand & collapse requests (non-leaf nodes))r
�rightTrFN)rrr)r(rr�keypress�r�size�keyr	r	r
r?�s


zTreeWidget.keypresscCsH|js|dks|dkrdS|dkrD||��krD|j|_|��dSdS)Nzmouse pressrFrT)rr&rr))rrAZeventZbutton�col�row�focusr	r	r
�mouse_event�s
zTreeWidget.mouse_eventcCs4|js|jsdS|j��r,|j��}|��SdSdS)zReturn first child if expanded.N)rrr�has_childrenrr6)rZ	firstnoder	r	r
r2�s

zTreeWidget.first_childcCsJ|js|jsdS|j��r*|j����}ndS|��}|dkrB|S|SdS)zReturn last child if expanded.N)rrrrG�get_last_childr6r;)rr<Zlastdescendantr	r	r
r;�s
zTreeWidget.last_childN)rrr�__doc__r'rr$r%rrrr)r&r"r-r+r.r9r=r?rFr2r;r	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|_dSr*)�_key�_parent�_value�_depth�_widget�r�value�parentrBr8r	r	r
r�s
zTreeNode.__init__FcCs"|jdks|dkr|��|_|jS)z! Return the widget for this node.NT)rO�load_widget�r�reloadr	r	r
r6�s
zTreeNode.get_widgetcCst|�Sr*)rrr	r	r
rS�szTreeNode.load_widgetcCs<|jdkr|jdkrd|_n|jdkr6|j��d|_|jS)Nrr)rNrLr,rr	r	r
r,�s

zTreeNode.get_depthcCs.|��dkrdS|��}|��}|�|�SdS�Nr)r,r/r4�get_child_index)rrBrRr	r	r
�	get_index�s
zTreeNode.get_indexcCs|jSr*�rKrr	r	r
r/�szTreeNode.get_keycCs
||_dSr*rY�rrBr	r	r
�set_key�szTreeNode.set_keycCs|���|j|�dSr*)r4�change_child_keyrKrZr	r	r
�
change_key�szTreeNode.change_keycCs&|jdkr |��dkr |��|_|jSrV)rLr,�load_parentrr	r	r
r4�s
zTreeNode.get_parentcCstd��dS)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 subclassN�rrr	r	r
r^�szTreeNode.load_parentcCs|jSr*)rMrr	r	r
r1szTreeNode.get_valuecCs|��dkSrV)r,rr	r	r
�is_rootszTreeNode.is_rootcCs&|��dkr|���|���SdSdSrV)r,r4�
next_childr/rr	r	r
r3szTreeNode.next_siblingcCs&|��dkr|���|���SdSdSrV)r,r4�
prev_childr/rr	r	r
r:szTreeNode.prev_siblingcCs|}|��dk	r|��}q|Sr*)r4)r�rootr	r	r
�get_roots
zTreeNode.get_root)NNN)F)rrrrIrr6rSr,rXr/r[r]r4r^r1rar3r:rer	r	r	r
rJ�s 

rJc@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)rRrBr8)rJr�_child_keys�	_childrenrPr	r	r
rszParentNode.__init__FcCs"|jdks|dkr|��|_|jS)z,Return a possibly ordered list of child keysNT)rg�load_child_keysrTr	r	r
�get_child_keys!s
zParentNode.get_child_keyscCstd��dS)zPProvide ParentNode with an ordered list of child keys (virtual
        function)r_Nr`rr	r	r
ri'szParentNode.load_child_keyscCs|�|�}|��S)z8Return the widget for a given key.  Create if necessary.)�get_child_noder6)rrBZchildr	r	r
�get_child_widget,s
zParentNode.get_child_widgetcCs,||jks|dkr"|�|�|j|<|j|S)z<Return the child node for a given key.  Create if necessary.T)rh�load_child_node)rrBrUr	r	r
rk2szParentNode.get_child_nodecCstd��dS)z6Load the child node for a given key (virtual function)r_Nr`rZr	r	r
rm8szParentNode.load_child_nodecCs||j|<dS)z]Set the child node for a given key.  Useful for bottom-up, lazy
        population of a tree.N)rh)rrBrr	r	r
�set_child_node<szParentNode.set_child_nodecCs<||jkrtd|��|j�|�|j|<|j|�|�dS)Nz%s is already in use)rhr�popr[)rZoldkeyZnewkeyr	r	r
r\As
zParentNode.change_child_keyc
CsLz|���|�WStk
rFd}t|||��t|���f��YnXdS)Nz7Can't find key %s in ParentNode %s
ParentNode items: %s)rj�index�
ValueErrorrr/r0)rrBZerrorstringr	r	r
rWGs
�zParentNode.get_child_indexcCsH|�|�}|dkrdS|d7}|��}|t|�kr@|�||�SdSdS)z=Return the next child node in index order from the given key.Nr)rWrj�lenrk�rrBrp�
child_keysr	r	r
rbPs
zParentNode.next_childcCsD|�|�}|dkrdS|��}|d8}|dkr<|�||�SdSdS)zAReturn the previous child node in index order from the given key.Nrr)rWrjrkrsr	r	r
rc`s
zParentNode.prev_childcCs|��}|�|d�S)z+Return the first TreeNode in the directory.r�rjrk�rrtr	r	r
roszParentNode.get_first_childcCs|��}|�|d�S)z*Return the last TreeNode in the directory.���rurvr	r	r
rHtszParentNode.get_last_childcCst|���dkS)z!Does this node have any children?r)rrrjrr	r	r
rGyszParentNode.has_children)NNN)F)F)rrrrIrrjrirlrkrmrnr\rWrbrcrrHrGr	r	r	r
rfs


	rfc@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)rE)r�
start_fromr	r	r
r�szTreeWalker.__init__cCs|j��}||jfSr*)rEr6)rrr	r	r
�	get_focus�s
zTreeWalker.get_focuscCs||_|��dSr*)rEZ	_modified)rrEr	r	r
�	set_focus�szTreeWalker.set_focuscCs,|��}|��}|dkrdS||��fSdS�N)NN)r6r9r+�rryr�targetr	r	r
�get_next�s
zTreeWalker.get_nextcCs,|��}|��}|dkrdS||��fSdSr|)r6r=r+r}r	r	r
�get_prev�s
zTreeWalker.get_prevN)	rrrrIrrzr{rr�r	r	r	r
rx~srxc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TreeListBoxzPA ListBox with special handling for navigation and
    collapsing of TreeWidgetscCs|j�||�}|�||�Sr*)Z_TreeListBox__superr?�unhandled_inputr@r	r	r
r?�szTreeListBox.keypresscCsX|dkr|�|�n@|dkr(|�|�n,|dkr<|�|�n|dkrP|�|�n|SdS)zHandle macro-navigation keysr!r�home�endN)�move_focus_to_parent�collapse_focus_parent�
focus_home�	focus_end)rrA�inputr	r	r
r��szTreeListBox.unhandled_inputcCs>|j��\}}|�|�|j��\}}||kr:|�|d�dS)zCollapse parent directory.rN)�bodyrzr�r?)rrAr�posZpwidgetZpposr	r	r
r��s

z!TreeListBox.collapse_focus_parentcCs�|j��\}}|��}|dkr"dS|�|�\}}}|\}}	}
}}|\}
}|D].\}}}||8}||krL|�|||�dSqL|�||���dS)z(Move focus to parent of widget in focus.N)r�rzr4Zcalculate_visible�change_focus)rrArr��	parentposZmiddle�topZbottom�
row_offsetZfocus_widgetZ	focus_posZ
focus_rowsZcursorZtrim_topZ
fill_aboveZrowsr	r	r
r��sz TreeListBox.move_focus_to_parentcCs&|j��\}}|��}|�||�dS)zMove focus to very top.N)r�rzrer�)rrArr��rootnoder	r	r
r��szTreeListBox.focus_homec
CsL|\}}|j��\}}|��}|��}|��}|��}	|�||	|d�dS)zMove focus to far bottom.rN)r�rzrer6r;r+r�)
rrAZmaxrowZmaxcolrr�r�Z
rootwidgetZ
lastwidgetZlastnoder	r	r
r��szTreeListBox.focus_endN)
rrrrIr?r�r�r�r�r�r	r	r	r
r��s

r�)Z
__future__rrr#Z
urwid.wimpr�RuntimeErrorrZ
WidgetWrapr�objectrJrfZ
ListWalkerrxZListBoxr�r	r	r	r
�<module>sUe"

Zerion Mini Shell 1.0