%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/treetools.cpython-35.pyc



p�6V�<�@s�dZddlZddlmZGdd�de�ZGdd�dej�ZGdd	�d	e�Z	Gd
d�de	�Z
Gdd
�d
ej�ZGdd�dej
�ZdS)z�
Urwid tree view

Features:
- custom selectable widgets for trees
- custom list walker for displaying widgets in a tree fashion
�N)�SelectableIconc@seZdZdS)�TreeWidgetErrorN)�__name__�
__module__�__qualname__�rr�1/usr/lib/python3/dist-packages/urwid/treetools.pyr$src@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�-cCsN||_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�widgetrrrr.s			zTreeWidget.__init__cCs|jS)zS
        Allow selection of non-leaf nodes so children may be (un)expanded
        )r)rrrr�
selectable6szTreeWidget.selectablecCsq|j�}|jsLtjdd|j|jg|jf|gdd�}|j�}tj|ddd|�S)	NZfixed�Zdividechars�width�relative�d�left)rr)	�get_inner_widgetr�urwidZColumns�unexpanded_icon�
expanded_iconr�get_indent_colsZPadding)rr�indent_colsrrrr<s	zTreeWidget.get_indented_widgetcCs*|j|jg|j|jjjd<dS)z-Update display widget text for parent widgetsrN)r!r"r�_wZbase_widgetZwidget_list)rrrr�update_expanded_iconFszTreeWidget.update_expanded_iconcCs|j|j�j�S)N)r$�get_node�	get_depth)rrrrr#LszTreeWidget.get_indent_colscCs%|jdkr|j�|_|jS)N)r�load_inner_widget)rrrrrOszTreeWidget.get_inner_widgetcCstj|j��S)N)r ZText�get_display_text)rrrrr)TszTreeWidget.load_inner_widgetcCs|jS)N)r)rrrrr'WszTreeWidget.get_nodecCs*|j�j�dt|j�j��S)Nz: )r'�get_key�str�	get_value)rrrrr*ZszTreeWidget.get_display_textcCs�|j�}|dk	r|S|j�}|j�}|j�}xV|dkr�|dkr�|j�}|j�}|d8}||j�ksCt�qCW|dkr�dS|j�SdS)z5Return the next TreeWidget depth first from this one.Nrr)�first_childr'�next_siblingr(�
get_parent�AssertionError�
get_widget)rZ
firstchild�thisnodeZnextnode�depthrrr�next_inorder^s
zTreeWidget.next_inordercCs�|j}|j�}|dk	rP|j�}|j�}|dkrI|S|SnJ|j�}|dkrx|dkrxdS|dkr�|j�}|j�SdS)z9Return the previous TreeWidget depth first from this one.Nr)r�prev_siblingr2�
last_childr(r0)rr3ZprevnodeZ
prevwidget�	lastchildr4rrr�prev_inorderus	zTreeWidget.prev_inordercCs{|jr
|S|dkr/d|_|j�nH|dkrQd|_|j�n&|jj�rs|jj||�S|SdS)z2Handle expand & collapse requests (non-leaf nodes)r�rightTrFN)rzright)rrr&r%rr�keypress)r�size�keyrrrr;�s		
	
zTreeWidget.keypresscCsb|js!|dks!|dkr%dS|dkr^||j�kr^|j|_|j�dSdS)Nzmouse pressrFrT)rr#rr&)rr<ZeventZbutton�col�row�focusrrr�mouse_event�s!

zTreeWidget.mouse_eventcCsG|js|jrdS|jj�r?|jj�}|j�SdSdS)zReturn first child if expanded.N)rrr�has_childrenr
r2)rZ	firstnoderrrr.�s
zTreeWidget.first_childcCsf|js|jrdS|jj�r>|jj�j�}ndS|j�}|dkr^|S|SdS)zReturn last child if expanded.N)rrrrB�get_last_childr2r7)rr8Zlastdescendantrrrr7�szTreeWidget.last_childN)rrr�__doc__r$rr!r"rrrr&r#rr)r'r*r5r9r;rAr.r7rrrrr	(s&
r	c@s�eZdZdZddddd�Zddd�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
    NcCs1||_||_||_||_d|_dS)N)�_key�_parent�_value�_depth�_widget)r�value�parentr=r4rrrr�s
				zTreeNode.__init__FcCs1|jdks|dkr*|j�|_|jS)z! Return the widget for this node.NT)rJ�load_widget)r�reloadrrrr2�szTreeNode.get_widgetcCs
t|�S)N)r	)rrrrrM�szTreeNode.load_widgetcCsV|jdkr*|jdkr*d|_n%|jdkrO|jj�d|_|jS)Nrr)rIrGr()rrrrr(�s
zTreeNode.get_depthcCs?|j�dkrdS|j�}|j�}|j|�SdS)Nr)r(r+r0�get_child_index)rr=rLrrr�	get_index�s
zTreeNode.get_indexcCs|jS)N)rF)rrrrr+�szTreeNode.get_keycCs
||_dS)N)rF)rr=rrr�set_key�szTreeNode.set_keycCs|j�j|j|�dS)N)r0�change_child_keyrF)rr=rrr�
change_key�szTreeNode.change_keycCs7|jdkr0|j�dkr0|j�|_|jS)Nr)rGr(�load_parent)rrrrr0�s!zTreeNode.get_parentcCstd��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)rrrrrT�szTreeNode.load_parentcCs|jS)N)rH)rrrrr-�szTreeNode.get_valuecCs|j�dkS)Nr)r()rrrr�is_rootszTreeNode.is_rootcCs3|j�dkr+|j�j|j��SdSdS)Nr)r(r0�
next_childr+)rrrrr/szTreeNode.next_siblingcCs3|j�dkr+|j�j|j��SdSdS)Nr)r(r0�
prev_childr+)rrrrr6
szTreeNode.prev_siblingcCs/|}x"|j�dk	r*|j�}q	W|S)N)r0)r�rootrrr�get_rootszTreeNode.get_root)rrrrDrr2rMr(rPr+rQrSr0rTr-rUr/r6rYrrrrrE�s rEc@s�eZdZdZddddd�Zddd�Zdd	�Zd
d�Zddd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �
ParentNodez"Maintain sort order for TreeNodes.Nc	Cs8tj||d|d|d|�d|_i|_dS)NrLr=r4)rEr�_child_keys�	_children)rrKrLr=r4rrrrs"	zParentNode.__init__FcCs1|jdks|dkr*|j�|_|jS)z,Return a possibly ordered list of child keysNT)r[�load_child_keys)rrNrrr�get_child_keysszParentNode.get_child_keyscCstd��dS)zPProvide ParentNode with an ordered list of child keys (virtual
        function)z(virtual function.  Implement in subclassN)r)rrrrr]%szParentNode.load_child_keyscCs|j|�}|j�S)z8Return the widget for a given key.  Create if necessary.)�get_child_noder2)rr=Zchildrrr�get_child_widget*szParentNode.get_child_widgetcCs<||jks|dkr1|j|�|j|<|j|S)z<Return the child node for a given key.  Create if necessary.T)r\�load_child_node)rr=rNrrrr_0szParentNode.get_child_nodecCstd��dS)z6Load the child node for a given key (virtual function)z(virtual function.  Implement in subclassN)r)rr=rrrra6szParentNode.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=rrrr�set_child_node:szParentNode.set_child_nodecCsP||jkrtd|��|jj|�|j|<|j|j|�dS)Nz%s is already in use)r\r�poprQ)rZoldkeyZnewkeyrrrrR?szParentNode.change_child_keycCsey|j�j|�SWnGtk
r`dd}t|||j�t|j��f��YnXdS)Nz#Can't find key %s in ParentNode %s
zParentNode items: %s)r^�index�
ValueErrorrr+r,)rr=ZerrorstringrrrrOEs
zParentNode.get_child_indexcCs`|j|�}|dkrdS|d7}|j�}|t|�krX|j||�SdSdS)z=Return the next child node in index order from the given key.Nr)rOr^�lenr_)rr=rd�
child_keysrrrrVNs
zParentNode.next_childcCsZ|j|�}|dkrdS|j�}|d8}|dkrR|j||�SdSdS)zAReturn the previous child node in index order from the given key.Nrr)rOr^r_)rr=rdrgrrrrW^s
zParentNode.prev_childcCs|j�}|j|d�S)z+Return the first TreeNode in the directory.r)r^r_)rrgrrrr
mszParentNode.get_first_childcCs|j�}|j|d�S)z*Return the last TreeNode in the directory.r���)r^r_)rrgrrrrCrszParentNode.get_last_childcCst|j��dkS)z!Does this node have any children?r)rfr^)rrrrrBwszParentNode.has_children)rrrrDrr^r]r`r_rarbrRrOrVrWr
rCrBrrrrrZs	rZc@sReZdZdZdd�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)r@)r�
start_fromrrrr�szTreeWalker.__init__cCs|jj�}||jfS)N)r@r2)rrrrr�	get_focus�szTreeWalker.get_focuscCs||_|j�dS)N)r@Z	_modified)rr@rrr�	set_focus�s	zTreeWalker.set_focuscCs<|j�}|j�}|dkr(dS||j�fSdS)N)NN)r2r5r')rrjr�targetrrr�get_next�s
zTreeWalker.get_nextcCs<|j�}|j�}|dkr(dS||j�fSdS)N)NN)r2r9r')rrjrrmrrr�get_prev�s
zTreeWalker.get_prevN)	rrrrDrrkrlrnrorrrrri|sric@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=rrrr;�szTreeListBox.keypresscCsx|dkr|j|�nX|dkr8|j|�n<|dkrT|j|�n |dkrp|j|�n|SdS)zHandle macro-navigation keysrr�home�endN)�move_focus_to_parent�collapse_focus_parent�
focus_home�	focus_end)rr<�inputrrrrq�szTreeListBox.unhandled_inputcCsW|jj�\}}|j|�|jj�\}}||krS|j|d�dS)zCollapse parent directory.rN)�bodyrkrtr;)rr<r�posZpwidgetZpposrrrru�s

z!TreeListBox.collapse_focus_parentcCs�|jj�\}}|j�}|dkr1dS|j|�\}}}|\}}	}
}}|\}
}xD|D]<\}}}||8}||krq|j|||�dSqqW|j||j��dS)z(Move focus to parent of widget in focus.N)ryrkr0Zcalculate_visible�change_focus)rr<rrz�	parentposZmiddle�topZbottom�
row_offsetZfocus_widgetZ	focus_posZ
focus_rowsZcursorZtrim_topZ
fill_aboveZrowsrrrrt�s
z TreeListBox.move_focus_to_parentcCs5|jj�\}}|j�}|j||�dS)zMove focus to very top.N)ryrkrYr{)rr<rrz�rootnoderrrrv�szTreeListBox.focus_homec
Csl|\}}|jj�\}}|j�}|j�}|j�}|j�}	|j||	|d�dS)zMove focus to far bottom.rN)ryrkrYr2r7r'r{)
rr<ZmaxrowZmaxcolrrzrZ
rootwidgetZ
lastwidgetZlastnoderrrrw�szTreeListBox.focus_endN)
rrrrDr;rqrurtrvrwrrrrrp�s

rp)rDr Z
urwid.wimpr�RuntimeErrorrZ
WidgetWrapr	�objectrErZZ
ListWalkerriZListBoxrprrrr�<module>s�Ue"

Zerion Mini Shell 1.0