%PDF- %PDF-
Mini Shell

Mini Shell

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

3

��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�}|jj|�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|j�}|js4tjdd|j|jg|jf|gdd�}|j�}tj|d|d�S)NZfixed�)Zdividechars�relative�d)�width�left)rr)	�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_list)rr	r	r
�update_expanded_iconHszTreeWidget.update_expanded_iconcCs|j|j�j�S)N)r&�get_node�	get_depth)rr	r	r
r%NszTreeWidget.get_indent_colscCs|jdkr|j�|_|jS)N)r�load_inner_widget)rr	r	r
r!Qs

zTreeWidget.get_inner_widgetcCstj|j��S)N)r"ZText�get_display_text)rr	r	r
r+VszTreeWidget.load_inner_widgetcCs|jS)N)r)rr	r	r
r)YszTreeWidget.get_nodecCs |j�j�dt|j�j��S)Nz: )r)�get_key�str�	get_value)rr	r	r
r,\szTreeWidget.get_display_textcCs�|j�}|dk	r|S|j�}|j�}|j�}x<|dkrh|dkrh|j�}|j�}|d8}||j�ks.t�q.W|dkrvdS|j�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}|j�}|dk	r8|j�}|j�}|dkr2|S|Sn4|j�}|dkrT|dkrTdS|dkrd|j�}|j�SdS)z9Return the previous TreeWidget depth first from this one.Nr)r�prev_siblingr4�
last_childr*r2)rr5ZprevnodeZ
prevwidget�	lastchildr6r	r	r
�prev_inorderwszTreeWidget.prev_inordercCsZ|jr
|S|dkr"d|_|j�n4|dkr:d|_|j�n|jj�rR|jj||�S|SdS)z2Handle expand & collapse requests (non-leaf nodes)r
�rightTrFN)r
r<)rrr(r'rr�keypress)r�size�keyr	r	r
r=�s


zTreeWidget.keypresscCsH|js|dks|dkrdS|dkrD||j�krD|j|_|j�dSdS)Nzmouse pressrFrT)rr%rr()rr>ZeventZbutton�col�row�focusr	r	r
�mouse_event�s
zTreeWidget.mouse_eventcCs6|js|jrdS|jj�r.|jj�}|j�SdSdS)zReturn first child if expanded.N)rrr�has_childrenrr4)rZ	firstnoder	r	r
r0�s

zTreeWidget.first_childcCsL|js|jrdS|jj�r,|jj�j�}ndS|j�}|dkrD|S|SdS)zReturn last child if expanded.N)rrrrD�get_last_childr4r9)rr:Zlastdescendantr	r	r
r9�s
zTreeWidget.last_childN)rrr�__doc__r&rr#r$rrrr(r%r!r+r)r,r7r;r=rCr0r9r	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|_dS)N)�_key�_parent�_value�_depth�_widget)r�value�parentr?r6r	r	r
r�s
zTreeNode.__init__FcCs"|jdks|dkr|j�|_|jS)z! Return the widget for this node.NT)rL�load_widget)r�reloadr	r	r
r4�s
zTreeNode.get_widgetcCst|�S)N)r)rr	r	r
rO�szTreeNode.load_widgetcCs<|jdkr|jdkrd|_n|jdkr6|jj�d|_|jS)Nrr)rKrIr*)rr	r	r
r*�s

zTreeNode.get_depthcCs.|j�dkrdS|j�}|j�}|j|�SdS)Nr)r*r-r2�get_child_index)rr?rNr	r	r
�	get_index�s
zTreeNode.get_indexcCs|jS)N)rH)rr	r	r
r-�szTreeNode.get_keycCs
||_dS)N)rH)rr?r	r	r
�set_key�szTreeNode.set_keycCs|j�j|j|�dS)N)r2�change_child_keyrH)rr?r	r	r
�
change_key�szTreeNode.change_keycCs&|jdkr |j�dkr |j�|_|jS)Nr)rIr*�load_parent)rr	r	r
r2�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)z(virtual function.  Implement in subclassN)r)rr	r	r
rV�szTreeNode.load_parentcCs|jS)N)rJ)rr	r	r
r/szTreeNode.get_valuecCs|j�dkS)Nr)r*)rr	r	r
�is_rootszTreeNode.is_rootcCs&|j�dkr|j�j|j��SdSdS)Nr)r*r2�
next_childr-)rr	r	r
r1szTreeNode.next_siblingcCs&|j�dkr|j�j|j��SdSdS)Nr)r*r2�
prev_childr-)rr	r	r
r8szTreeNode.prev_siblingcCs"|}x|j�dk	r|j�}qW|S)N)r2)r�rootr	r	r
�get_rootszTreeNode.get_root)NNN)F)rrrrFrr4rOr*rRr-rSrUr2rVr/rWr1r8r[r	r	r	r
rG�s 

rGc@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)rNr?r6)rGr�_child_keys�	_children)rrMrNr?r6r	r	r
rszParentNode.__init__FcCs"|jdks|dkr|j�|_|jS)z,Return a possibly ordered list of child keysNT)r]�load_child_keys)rrPr	r	r
�get_child_keys!s
zParentNode.get_child_keyscCstd��dS)zPProvide ParentNode with an ordered list of child keys (virtual
        function)z(virtual function.  Implement in subclassN)r)rr	r	r
r_'szParentNode.load_child_keyscCs|j|�}|j�S)z8Return the widget for a given key.  Create if necessary.)�get_child_noder4)rr?Zchildr	r	r
�get_child_widget,s
zParentNode.get_child_widgetcCs,||jks|dkr"|j|�|j|<|j|S)z<Return the child node for a given key.  Create if necessary.T)r^�load_child_node)rr?rPr	r	r
ra2szParentNode.get_child_nodecCstd��dS)z6Load the child node for a given key (virtual function)z(virtual function.  Implement in subclassN)r)rr?r	r	r
rc8szParentNode.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^)rr?rr	r	r
�set_child_node<szParentNode.set_child_nodecCs<||jkrtd|��|jj|�|j|<|j|j|�dS)Nz%s is already in use)r^r�poprS)rZoldkeyZnewkeyr	r	r
rTAs
zParentNode.change_child_keycCsJy|j�j|�Stk
rDd}t|||j�t|j��f��YnXdS)Nz#Can't find key %s in ParentNode %s
zParentNode items: %sz7Can't find key %s in ParentNode %s
ParentNode items: %s)r`�index�
ValueErrorrr-r.)rr?Zerrorstringr	r	r
rQGszParentNode.get_child_indexcCsH|j|�}|dkrdS|d7}|j�}|t|�kr@|j||�SdSdS)z=Return the next child node in index order from the given key.Nr)rQr`�lenra)rr?rf�
child_keysr	r	r
rXPs
zParentNode.next_childcCsD|j|�}|dkrdS|j�}|d8}|dkr<|j||�SdSdS)zAReturn the previous child node in index order from the given key.Nrr)rQr`ra)rr?rfrir	r	r
rY`s
zParentNode.prev_childcCs|j�}|j|d�S)z+Return the first TreeNode in the directory.r)r`ra)rrir	r	r
roszParentNode.get_first_childcCs|j�}|j|d�S)z*Return the last TreeNode in the directory.r���)r`ra)rrir	r	r
rEtszParentNode.get_last_childcCst|j��dkS)z!Does this node have any children?r)rhr`)rr	r	r
rDyszParentNode.has_children)NNN)F)F)rrrrFrr`r_rbrarcrdrTrQrXrYrrErDr	r	r	r
r\s


	r\c@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)rB)r�
start_fromr	r	r
r�szTreeWalker.__init__cCs|jj�}||jfS)N)rBr4)rrr	r	r
�	get_focus�s
zTreeWalker.get_focuscCs||_|j�dS)N)rBZ	_modified)rrBr	r	r
�	set_focus�szTreeWalker.set_focuscCs,|j�}|j�}|dkrdS||j�fSdS)N)NN)r4r7r))rrlr�targetr	r	r
�get_next�s
zTreeWalker.get_nextcCs,|j�}|j�}|dkrdS||j�fSdS)N)NN)r4r;r))rrlrror	r	r
�get_prev�s
zTreeWalker.get_prevN)	rrrrFrrmrnrprqr	r	r	r
rk~srkc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TreeListBoxzPA ListBox with special handling for navigation and
    collapsing of TreeWidgetscCs|jj||�}|j||�S)N)Z_TreeListBox__superr=�unhandled_input)rr>r?r	r	r
r=�szTreeListBox.keypresscCsX|dkr|j|�n@|dkr(|j|�n,|dkr<|j|�n|dkrP|j|�n|SdS)zHandle macro-navigation keysr r�home�endN)�move_focus_to_parent�collapse_focus_parent�
focus_home�	focus_end)rr>�inputr	r	r
rs�szTreeListBox.unhandled_inputcCs>|jj�\}}|j|�|jj�\}}||kr:|j|d�dS)zCollapse parent directory.rN)�bodyrmrvr=)rr>r�posZpwidgetZpposr	r	r
rw�s

z!TreeListBox.collapse_focus_parentcCs�|jj�\}}|j�}|dkr"dS|j|�\}}}|\}}	}
}}|\}
}x4|D],\}}}||8}||krN|j|||�dSqNW|j||j��dS)z(Move focus to parent of widget in focus.N)r{rmr2Zcalculate_visible�change_focus)rr>rr|�	parentposZmiddle�topZbottom�
row_offsetZfocus_widgetZ	focus_posZ
focus_rowsZcursorZtrim_topZ
fill_aboveZrowsr	r	r
rv�sz TreeListBox.move_focus_to_parentcCs&|jj�\}}|j�}|j||�dS)zMove focus to very top.N)r{rmr[r})rr>rr|�rootnoder	r	r
rx�szTreeListBox.focus_homec
CsL|\}}|jj�\}}|j�}|j�}|j�}|j�}	|j||	|d�dS)zMove focus to far bottom.rN)r{rmr[r4r9r)r})
rr>ZmaxrowZmaxcolrr|r�Z
rootwidgetZ
lastwidgetZlastnoder	r	r
ry�szTreeListBox.focus_endN)
rrrrFr=rsrwrvrxryr	r	r	r
rr�s

rr)Z
__future__rrr"Z
urwid.wimpr�RuntimeErrorrZ
WidgetWrapr�objectrGr\Z
ListWalkerrkZListBoxrrr	r	r	r
�<module>sUe"

Zerion Mini Shell 1.0