Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
treetools.cpython-313.pyc115 linesDownload Raw Back to __pycache__
1�

2��j�B�	�V�SrSSKJr SSKrSSKJr SSKJr SSKJ	r	J3r4 SSKJr SS	K
Jr SS5KJr SSKJr \R&(aSSKJrJr S
r"SS\5r"SS\\\R4\\45r"SS5r"SS\5r"SS\65r"SS\	5rg)z�7Urwid tree view8 9Features:10- custom selectable widgets for trees11- custom list walker for displaying widgets in a tree fashion12�)�annotationsN�)�Columns)�13WHSettings)�ListBox�14ListWalker)�Padding)�Text)�15WidgetWrap)�SelectableIcon)�Hashable�Sequence)�16ParentNode�TreeListBox�TreeNode�17TreeWalker�18TreeWidget�TreeWidgetErrorc��\rSrSrSrg)r�0�N)�__name__�19__module__�__qualname__�__firstlineno__�__static_attributes__r��\D:\code\apps\devtools\python\user_packages\Python313\site-packages\urwid/widget/treetools.pyrr0s��rrc�^�\rSrSrSrSr\"SS5r\"SS5rSU4Sjjr	SSjr20SS	jrSS21jrSSjr
SSjrSS
jrSSjrSSjrSSjrSSjrS U4SjjrS!SjrSSjrSSjrSrU=r$)"r�4z9A widget representing something in a nested tree display.��+r�-c�>�XlSUl[US5(+UlSUlUR5n[TU]U5 g)N�get_first_childT)�_node�_innerwidget�hasattr�is_leaf�expanded�get_indented_widget�super�__init__)�self�node�widget�	__class__s   �rr-�TreeWidget.__init__;sD����22�)-���"�4�):�;�;�����
��)�)�+��
���� rc�$�UR(+$)zC23Allow selection of non-leaf nodes so children may be (un)expanded24)r)�r.s r�25selectable�TreeWidget.selectableCs���<�<��rc���UR5nUR(d1[SURUR/UR264U/SS9nUR
5n[U[RS4US9$)Nr)�dividechars�d)�width�left)27�get_inner_widgetr)r�unexpanded_icon�
expanded_iconr*�get_indent_colsr	r�RELATIVE)r.r0�indent_colss   rr+�TreeWidget.get_indented_widgetIsv���&�&�(���|�|���d�*�*�D�,>�,>�?��
�
�N�O�QW�X���F��*�*�,���v�j�&9�&9�3�%?�k�R�Rrc��URUR/URnU[RSS44UR28RRS'g)z-Update display widget text for parent widgetsrFrN)r=r>r*r�GIVEN�_w�base_widget�contents)r.�icons  r�update_expanded_icon�TreeWidget.update_expanded_iconSsO���$�$�d�&8�&8�9�$�-�-�H��+/�*�2B�2B�A�u�1M�*N������$�$�Q�'rc�X�URUR5R5-$�N)rA�get_node�	get_depthr4s rr?�TreeWidget.get_indent_colsYs"�����$�-�-�/�";�";�"=�=�=rc�^�URcUR5UlUR$rL)r'�load_inner_widgetr4s rr<�TreeWidget.get_inner_widget\s+�����$� $� 6� 6� 8�D��� � � rc�4�[UR55$rL)r29�get_display_textr4s rrQ�TreeWidget.load_inner_widgetas���D�)�)�+�,�,rc��UR$rL)r&r4s rrM�TreeWidget.get_nodeds���z�z�rc��UR5R5SUR5R5<3$)Nz: )rM�get_key�	get_valuer4s rrT�TreeWidget.get_display_textgs3���-�-�/�)�)�+�,�B�t�}�}��/H�/H�/J�.M�N�Nrc�b�UR5=nbU$UR5nUR5nUR5nUcTUS:�aNUR	5nUR5nUS-nXBR5:wa[U5eUcUS:�aMNUcgUR
5$)z5Return the next TreeWidget depth first from this one.Nrr)�first_childrM�next_siblingrN�30get_parent�31ValueError�32get_widget)r.r]�	this_node�	next_node�depths     r�next_inorder�TreeWidget.next_inorderjs��� �+�+�-�-�K�:����M�M�O�	��*�*�,�	��#�#�%����E�A�I�!�,�,�.�I�!�.�.�0�I��Q�J�E��+�+�-�-� ��'�'�
��E�A�I�����#�#�%�%rc���URnUR5=nb'UR5nUR5=nbU$U$UR	5S:XagUR5R5$)z9Return the previous TreeWidget depth first from this one.Nr)r&�prev_siblingra�33last_childrNr_)r.rb�	prev_node�prev_widgetris     r�prev_inorder�TreeWidget.prev_inorder�s}���J�J�	�"�/�/�1�1�I�>�$�.�.�0�K�)�4�4�6�6�34�C�!�!������ �A�%���#�#�%�0�0�2�2rc�>�UR(aU$US;aSUlUR5 gUS:XaSUlUR5 gURR	5(a[35TU]X5$U$)z2Handle expand & collapse requests (non-leaf nodes)>r"�rightTNr#F)r)r*rIrEr5r,�keypress�r.�size�keyr1s   �rrp�TreeWidget.keypress�st����<�<��J��.� � �D�M��%�%�'���#�:�!�D�M��%�%�'���7�7������7�#�D�.�.��36rc���UR(dUS:wdUS:wagUS:Xa:X@R5:Xa'UR(+UlUR5 gg)Nzmouse pressrFrT)r)r?r*rI)r.rr�event�button�col�row�focuss       r�mouse_event�TreeWidget.mouse_event�sP���<�<�5�M�1�V�q�[���!�8��3�3�5�5� $�
�
�-�D�M��%�%�'��rc���UR(dUR(dgURR5(a*URR	5nUR5$g)zReturn first child if expanded.N)r)r*r&�has_childrenr%ra)r.�37first_nodes  rr]�TreeWidget.first_child�sI���<�<�t�}�}���:�:�"�"�$�$����3�3�5�J��(�(�*�*�rc��UR(dUR(dgURR5(a)URR	5R5nOgUR
5=nbU$U$)zReturn last child if expanded.N)r)r*r&r~�get_last_childrari)r.ri�last_descendants   rri�TreeWidget.last_child�sc���<�<�t�}�}���:�:�"�"�$�$����2�2�4�?�?�A�J��)�4�4�6�6�O�C�"�"��r)r'r&r*r))r/r�return�None�r��bool)r�zPadding[Text | Columns]�r�r��r��int)r�r38�r�r)r�z=str | tuple[Hashable, str] | list[str | tuple[Hashable, str]])r�zTreeWidget | None)rr�tuple[int] | tuple[()]rs�strr��39str | None)rrr�rvr�rwr�rxr�ryr�rzr�r�r�)rrrr�__doc__rArr=r>r-r5r+rIr?r<rQrMrTrerlrpr{r]rir�
__classcell__�r1s@rrr4s����C��K�$�S�!�,�O�"�3��*�M�!� �S�O�>�!�40-��O�&�03�&�$����41�	�,�$�����	�42���
���43��&	�
�
rrc���\rSrSrSrSSSjjrSSSjjrSSjrSSjrSSjr	SS	jr44SS45jrSSjrSSjr
S
rSrSSjrSSjrSSjrSSjrSrg) r��a46Store tree contents and cache TreeWidget objects.47A TreeNode consists of the following elements:48*  key: accessor token for parent nodes49*  value: subclass-specific data50*  parent: a TreeNode which contains a pointer back to this object51*  widget: The widget used to render the object52Nc�B�X0lX lXlX@lSUlgrL)�_key�_parent�_value�_depth�_widget)r.�value�parentrsrds     rr-�TreeNode.__init__�s���	�������*.��rc�l�URbU(aUR5UlUR$)z Return the widget for this node.)r��load_widget�r.�reloads  rra�TreeNode.get_widget�s(���<�<��6��+�+�-�D�L��|�|�rc��[U5$rL)rr4s rr��TreeNode.load_widget�s
���$��rc���URURs=LacO OSUlUR$URc"URR5S-UlUR$)Nrr)r�r�rNr4s rrN�TreeNode.get_depth�sW���;�;�$�,�,�.�.��D�K��{�{���[�[�
 ��,�,�0�0�2�Q�6�D�K��{�{�rc��UR5S:XagUR5RUR55$�Nr)rNr_�get_child_indexrYr4s r�	get_index�TreeNode.get_indexs2���>�>��q� ����� �0�0�����@�@rc��UR$rL�r�r4s rrY�TreeNode.get_keys���y�y�rc��XlgrLr��r.rss  r�set_key�TreeNode.set_key	s���	rc�X�UR5RURU5 grL)r_�change_child_keyr�r�s  r�53change_key�TreeNode.change_keys������*�*�4�9�9�c�:rc��URc)UR5S:�aUR5UlUR$r�)r�rN�load_parentr4s rr_�TreeNode.get_parents4���<�<��D�N�N�$4�q�$8��+�+�-�D�L��|�|�rc��[S5e)z�Provide TreeNode with a parent for the current node.  This function54is only required if the tree was instantiated from a child node55(virtual function)�(virtual function.  Implement in subclass�rr4s rr��TreeNode.load_parents���H�I�Irc��UR$rL)r�r4s rrZ�TreeNode.get_values���{�{�rc�(�UR5S:H$r�)rNr4s r�is_root�TreeNode.is_roots���~�~��1�$�$rc��UR5S:�a-UR5RUR55$gr�)rNr_�56next_childrYr4s rr^�TreeNode.next_sibling �2���>�>��a���?�?�$�/�/�����?�?�rc��UR5S:�a-UR5RUR55$gr�)rNr_�57prev_childrYr4s rrh�TreeNode.prev_sibling&r�rc�r�UnUR5b#UR5nUR5bM#U$rL)r_)r.�roots  r�get_root�TreeNode.get_root,s4�����o�o��+��?�?�$�D��o�o��+��r)r�r�r�r�r��NNN)58r��59typing.Anyr��ParentNode | Noners�Hashable | Nonerd�60int | Noner�r��F)r�r�r�r�r�rr�)r�r�)r�r�)rsr�r�r�)r�rr�)r��TreeNode | None)rrrrr�r-rar�rNr�rYr�r�r_r�rZr�r^rhr�rrrrrr�s����%)�#� �/��/�"�/��	/�61�/�62�
/�� ��A���;��63J��%���rrc��^�\rSrSrSrSSU4SjjjrSSSjjrSSjrSSjrSSSjjr	SSjr64SS	jrSS65jrSSjr
SSjrSS
jrSSjrSSjrSSjrSrU=r$) ri3z"Maintain sort order for TreeNodes.c�>>�[TU]XX4S9 SUl0Ulg)N)r�rsrd)r,r-�_child_keys�	_children)r.r�r�rsrdr1s     �rr-�ParentNode.__init__6s&���	����3��D�6:���35��rc�l�URbU(aUR5UlUR$)z,Return a possibly ordered list of child keys)r��load_child_keysr�s  r�get_child_keys�ParentNode.get_child_keysBs-�����#�v�#�3�3�5�D�����rc��[S5e)zHProvide ParentNode with an ordered list of child keys (virtual function)r�r�r4s rr��ParentNode.load_child_keysH����H�I�Irc�@�URU5R5$)z8Return the widget for a given key.  Create if necessary.)�get_child_noderar�s  r�get_child_widget�ParentNode.get_child_widgetLs���"�"�3�'�2�2�4�4rc��XR;dU(aURU5URU'URU$)z;Return the child node for a given key. Create if necessary.)r��load_child_node)r.rsr�s   rr��ParentNode.get_child_nodeQs6���n�n�$��"&�"6�"6�s�";�D�N�N�3���~�~�c�"�"rc��[S5e)z6Load the child node for a given key (virtual function)r�r�r�s  rr��ParentNode.load_child_nodeWr�rc� �X RU'g)zVSet the child node for a given key.66 67Useful for bottom-up, lazy population of a tree.68N)r�)r.rsr/s   r�set_child_node�ParentNode.set_child_node[s��69#���s�rc���X R;a[US35eURRU5URU'URURU5 g)Nz is already in use)r�r�popr�)r.�oldkey�newkeys   rr��ParentNode.change_child_keybsS���^�^�#�!�V�H�,>�"?�@�@�!%���!3�!3�F�!;����v�����v��&�&�v�.rc70���UR5RU5$![aPn[SUSUR	5SUR5<35RUR5UeSnAff=f)NzCan't find key z in ParentNode z71ParentNode items: )r��indexr`rrY�with_traceback�
__traceback__)r.rs�excs   rr��ParentNode.get_child_indexhsy��	9��&�&�(�.�.�s�3�3���	9�!�!�#��o�d�l�l�n�5E�EY�Z^�Zm�Zm�Zo�Yr�s���n�S�.�.�/�S�
9��	9�s�!�72A;�AA6�6A;c��URU5=nb8US-[UR5=n5:aURX2S-5$g)z=Return the next child node in index order from the given key.Nr)r��lenr�r�)r.rsr��73child_keyss    rr��ParentNode.next_childpsU���)�)�#�.�.�E�;����c�`d�`s�`s�`u�Ru�R\�Nv�@v��&�&�z�!�)�'<�=�=�rc��URU5=nb+US:�a%URUR5US-745$g)zAReturn the previous child node in index order from the given key.Nr)r�r�r�)r.rsr�s   rr��ParentNode.prev_childysD���)�)�#�.�.�E�;���75��&�&�t�':�':�'<�U�Q�Y�'G�H�H�rc�J�UR5nURUS5$)z+Return the first TreeNode in the directory.r�r�r��r.r�s  rr%�ParentNode.get_first_child�s%���(�(�*�76��"�"�:�a�=�1�1rc�J�UR5nURUS5$)z*Return the last TreeNode in the directory.�����rrs  rr��ParentNode.get_last_child�s%���(�(�*�77��"�"�:�b�>�2�2rc�:�[UR55S:�$)z!Does this node have any children?r)r�r�r4s rr~�ParentNode.has_children�s���4�&�&�(�)�A�-�-r)r�r�r�)78r�r�r�r�rsr
rdr�r�r�r�)r�r�r��Sequence[Hashable])r�rr�)r�r�r�r)rsr
r�r)rsr
r/rr�r�)r�r
r�r
r�r�)rsr
r�r�)rsr
r�r�r�r�)rrrrr�r-r�r�r�r�r�r�r�r�r�r�r%r�r~rr�r�s@rrr3s����,�79%)�� �806��816�"�826��	836�84�856�86�
876�886� �J�5�89#�J�#�/�9���2�903�91.�.rrc�F�\rSrSrSrS92SjrSrS93SjrSSjrSSjr	Sr94g	)ri�zPListWalker-compatible class for displaying TreeWidgets95 96positions are TreeNodes.c��Xlg)z,start_from: TreeNode with the initial focus.N�rz)r.�97start_froms  rr-�TreeWalker.__init__�s���98rc�P�URR5nXR4$rL)rzra)r.r0s  r�	get_focus�TreeWalker.get_focus�s!�����&�&�(���z�z�!�!rc�0�XlUR5 grL)rz�	_modified)r.rzs  r�	set_focus�TreeWalker.set_focus�s���99����rc�h�UR5R5=nbX"R54$g�N)NN)rarerM�r.r�targets   r�get_next�TreeWalker.get_next��2�� �+�+�-�:�:�<�<�F�I��?�?�,�,�,�rc�h�UR5R5=nbX"R54$gr)rarlrMrs   r�get_prev�TreeWalker.get_prev�rrrNr�)r�z/tuple[TreeWidget, TreeNode] | tuple[None, None])rrrrr�r-rrrrrrrrrr�s �� � �"��100�rrc�^�\rSrSrSrSU4SjjrS
SjrSSjrSSjrSSjr	SSjr101SS	jrSS102jrSr
U=r$)ri�zLA ListBox with special handling for navigation and103collapsing of TreeWidgetsc�D>�[TU]X5nURX5$rL)r,rp�unhandled_inputrqs   �rrp�TreeListBox.keypress�s%���104 �'�*�4�5���#�#�D�.�.rc�f�US:XaURU5 gUS:XaURU5 gU$)zHandle macro-navigation keysr;Nr#)�move_focus_to_parent�collapse_focus_parent)r.rr�datas   rr!�TreeListBox.unhandled_input�s7���6�>��%�%�d�+���3�;��&�&�t�,���rc���URR5up#URU5 URR5upEX5:waURUS5 gg)zCollapse parent directory.r#N)�bodyrr$rp)r.rrr��pos�_pwidget�pposs      rr%�!TreeListBox.collapse_focus_parent�sR���y�y�*�*�,����!�!�$�'����,�,�.����;��M�M�$��$�rc�0�URR5up#UR5nUcgURU5upVnUup�p�nUup�UH#up#nX�-nX4:XdMUR	XU5  g UR	XR55 g)z(Move focus to parent of widget in focus.N)r)rr_�calculate_visible�change_focus)r.rrr�r*�	parentpos�middle�top�_bottom�105row_offset�
_focus_widget�106_focus_pos�_focus_rows�_cursor�	_trim_top�107fill_above�rowss                rr$� TreeListBox.move_focus_to_parent�s����y�y�*�*�,����N�N�$�	����#�5�5�d�;���W�FL�C�108�:�G� #��	�",��G�$���J����!�!�$�Z�8��	#-�	
���$��� 0�1rc�&�URU5 grL)�109focus_home�r.rrs  r�_keypress_max_left�TreeListBox._keypress_max_left�s������rc�&�URU5 grL)�	focus_endr@s  r�_keypress_max_right�TreeListBox._keypress_max_right�s�����t�rc�~�URR5up#UR5nURX5 g)zMove focus to very top.N)r)rr�r0)r.rrr�r*�rootnodes     rr?�TreeListBox.focus_home�s1���y�y�*�*�,����<�<�>�����$�)rc���Uup#URR5upEUR5R5R	5=n(a&UR5nUR
XUS-1105 gg)zMove focus to far bottom.rN)r)rr�rarirMr0)r.rr�maxrow�_maxcolr�r*�111lastwidget�lastnodes        rrD�TreeListBox.focus_end�sj������y�y�*�*�,�������2�2�4�?�?�A�A�:�A�!�*�*�,�H����d�f�q�j�9�Brr)rr�tuple[int, int]rsr�r�r�)rrrPr&r�r�r�)rrrPr�r�)rrrrr�rpr!r%r$rArEr?rDrr�r�s@rrr�sQ���!�/��/��/�112�	/�	�%�2�.��*�	:�	:rr) r��113__future__r�typing�columnsr�	constantsr�listboxrr�paddingr	�textr114r0r�wimpr�
TYPE_CHECKING�collections.abcr
r�__all__�RuntimeErrorr�Unionrrrrrrrr�<module>r^s���,�#�
��!�(���� �	���2�115b��	�l�	�b��G�F�L�L��w��$?�@�A�b�JW�W�tZ.��Z.�z���BN:�'�N:r
codekingpro/portable-devtools · Team Ai