Sindbad~EG File Manager
�
&Μg"2����dZddlZddlZddlmZddlmZddlmZddl m
Z
ddlmZdd�Z
Gd �d
ej�ZGd�d�Zej#�ed
k(rddlmZeddd��yy)aAn IDLE extension to avoid having very long texts printed in the shell.
A common problem in IDLE's interactive shell is printing of large amounts of
text into the shell. This makes looking at the previous history difficult.
Worse, this can cause IDLE to become very slow, even to the point of being
completely unusable.
This extension will automatically replace long texts with a small button.
Double-clicking this button will remove it and insert the original text instead.
Middle-clicking will copy the text to the clipboard. Right-clicking will open
the text in a separate viewing window.
Additionally, any output can be manually "squeezed" by the user. This includes
output written to the standard error stream ("stderr"), such as exception
messages and their tracebacks.
�N)�
messagebox)�idleConf)� view_text)�Hovertip)�macosxc�b�d}d}d}d}tjd|�D]e}|j�|z
}||z
}||z
}||dk(r||kDr||dz
|zz
}|dz
}d}n!||dk(sJ�||||zz
z
}||kDr|dz
}|}|dz
}�g|t|�|z
z
}|dkDr
||dz
|zz
}|S|dz}|S)z�Count the number of lines in a given string.
Lines are counted as if the string was wrapped so that lines are never over
linewidth characters long.
Tabs are considered tabwidth characters long.
�r�z[\t\n]�
� )�re�finditer�start�len)�s� linewidth�tabwidth�pos� linecount�current_column�m�numcharss �-/usr/local/lib/python3.12/idlelib/squeezer.py�count_lines_with_wrappingrs���H�
�C��I��N�
�[�[��A�
&���7�7�9�s�?���x����(�"��
�S�6�T�>�� �)��n�q�0�Y�>�>� ���N�I��N��S�6�T�>�!�>��h�.�8�*C�D�D�N�� �)��Q�� �!)���q���;'�@�c�!�f�s�l�"�N�����n�q�(�Y�6�6� �
�� �Q�� ���c�>�eZdZdZd�Zd�Zd
d�Zd
d�Zd
d�ZdZ d �Z
y)�ExpandingButtona�Class for the "squeezed" text buttons used by Squeezer
These buttons are displayed inside a Tk Text widget in place of text. A
user can then use the button to replace it with the original text, copy
the original text to the clipboard or view the original text in a separate
window.
Each button is tied to a Squeezer instance, and it knows to update the
Squeezer instance when it is expanded (and therefore removed).
c����|_||_||_||_|jx|_}|j
x|_}|jj|_|dk7rdnd}d|�d|�d�}tjj|||dd� �d
} t|| d��|jd
|j�tj �r|jd|j"�n|jd|j"�|j%�fd��d|_|j)|j*�y)Nr
�lines�linezSqueezed text (� z).z#FFFFC0z#FFFFE0)�text�
background�activebackgroundz5Double-click to expand, right-click for more options.�P)�hover_delayz<Double-Button-1>z
<Button-2>z
<Button-3>c�J���t|�t|�t|�zS�N)�int)�offset�lengthrs �r�<lambda>z*ExpandingButton.__init__.<locals>.<lambda>zs���1�S��[��V��s�6�{�1J�#Kr)r�tags�
numoflines�squeezer�editwinr"�per�bottom� base_text�tk�Button�__init__r�bind�expandr�isAquaTk�context_menu_event�selection_handle�is_dangerous�
after_idle�set_is_dangerous)
�selfrr-r.r/r0r"�line_plurality�button_text�button_tooltip_texts
` rr6zExpandingButton.__init___s$�������� �$��� ��
�!)�!1�!1�1���w�"�<�<�'�� �D� ���+�+���$.�!�O����'�
�|�1�^�4D�B�G��
� � ���4��K�&/�)� � M�
D� � ��*��;�� � �%�t�{�{�3��?�?���I�I�l�D�$;�$;�<��I�I�l�D�$;�$;�<����K� M�!�������-�-�.rc���d|jj�z�|jdkDxsLt|j�dkDxs2t�fd�t
jd|j�D��|_y)N�2i�iP�c3�X�K�|]!}t|jd���k\���#y�w)rN)r�group)�.0�
line_match�dangerous_line_lens �r� <genexpr>z3ExpandingButton.set_is_dangerous.<locals>.<genexpr>�s/������"@�J��J�$�$�Q�'�(�,>�>�"@�s�'*z[^\n]+) r"�winfo_widthr.rr�anyr
rr<)r?rIs @rr>z ExpandingButton.set_is_dangeroussm����$�)�)�"7�"7�"9�9���O�O�d�"�
�����K�%��
���"$�+�+�i����"@��
�
�rNc��|j�|j�|jrgtjddj gd��|j
t
|j�fztj|j��}|sy|jj|�}|jj||j|j�|jj|�|jj!||j|j�|j"j$j'|�y)aAexpand event handler
This inserts the original text in place of the button in the Text
widget, removes the button and updates the Squeezer instance.
If the original text is dangerously long, i.e. expanding it could
cause a performance degradation, ask the user for confirmation.
NzExpand huge output?z
)z5The squeezed output is very long: %d lines, %d chars.z2Expanding it could make IDLE slow or unresponsive.z5It is recommended to view or copy the output instead.zReally expand?)�title�message�default�parent�break)r<r>r�askokcancel�joinr.rr�CANCELr"�indexr3�insertr-�deleter0�on_squeezed_expandr/�expandingbuttons�remove)r?�event�confirmrVs rr8zExpandingButton.expand�s������$��!�!�#���� �,�,�+����%��
�o�o�s�4�6�6�{�3�4�#�)�)��y�y� "�G���� � ����%�������e�T�V�V�T�Y�Y�7������d�#����'�'��t�v�v�t�y�y�A��
�
�&�&�-�-�d�3rc�Z�|j�|j|j�y)zMcopy event handler
Copy the original text to the clipboard.
N)�clipboard_clear�clipboard_appendr�r?r\s r�copyzExpandingButton.copy�s"��
�������d�f�f�%rc�L�t|jd|jdd��y)z]view event handler
View the original text in a separate text viewer window.
zSqueezed Output ViewerF�none)�modal�wrapN)rr"rras r�viewzExpandingButton.view�s ��
�$�)�)�5�t�v�v��F� ,r))rbrb)rgrgc�^�|jjdd|j|jfz�t j
|jd��}|jD]"\}}|j|t||����$|j|j|j�y)NrWz@%d,%dr)�tearoff)�label�commandrR)r"�mark_set�x�yr4�Menu�rmenu_specs�add_command�getattr�tk_popup�x_root�y_root)r?r\�rmenurj�method_names rr:z"ExpandingButton.context_menu_event�s���� � ���8�X����%�'�'�0B�%B�C����� � �1�-��"&�"2�"2��E�;����E�7�4��3M��N�#3�
���u�|�|�U�\�\�2�rr()�__name__�
__module__�__qualname__�__doc__r6r>r8rbrgrpr:�rrrrTs-�� �/�@
�4�>&�,��K�rrc�2�eZdZdZed��Zd�Zd�Zd�Zy)�Squeezerz�Replace long outputs in the shell with a simple button.
This avoids IDLE's shell slowing down considerably, and even becoming
completely unresponsive, when very long outputs are written.
c�B�tjddddd��|_y)z!Load class variables from config.�main�PyShellzauto-squeeze-min-linesr)rD)�typerPN)r� GetOption�auto_squeeze_min_lines)�clss r�reloadzSqueezer.reload�s$��&.�%7�%7��I�7���&
��"rc�.���|�_|jx�_�|jj�_dt�j
d��t�j
d��zz�_g�_d|jf��fd� }||_ y)aeInitialize settings for Squeezer.
editwin is the shell's Editor window.
self.text is the editor window text widget.
self.base_test is the actual editor window Tk text widget, rather than
EditorWindow's wrapper.
self.expandingbuttons is the list of all buttons representing
"squeezed" output.
��border�padxr|c����|dk7r |||�S�j}t|�|kr |||�S�j|�}||kr |||�St|||��}�j dt
j��jd|dd���jd��j��j dt
j��jj|�y)N�stdout�iomark����windowr��pady)
r�r�count_linesr�mark_gravityr4�RIGHT�
window_create�see�update�LEFTrZ�append)rr-�writer�r.�expandingbuttonr?r"s ��r�mywritez"Squeezer.__init__.<locals>.mywrite�s�����x���Q��~�%�&*�%@�%@�"��1�v�.�.��Q��~�%��)�)�!�,�J��2�2��Q��~�%�.�a��z�4�H�O�
���h����1����x��$%�A�
�
/��H�H�X���K�K�M����h����0�
�!�!�(�(��9rN)
r0r"r1r2r3r)�cget�window_width_deltarZr�)r?r0r�r"s` @rr6zSqueezer.__init__�s�������"�<�<�'�� �D�!���+�+���#$��� � �(�#�$��� � �&�!�"�
#�#
���
!#����g�m�m� :�< ��
rc�B�t||jj�S)abCount the number of lines in a given text.
Before calculation, the tab width and line length of the text are
fetched, so that up-to-date values are used.
Lines are counted as if the string was wrapped so that lines are never
over linewidth characters long.
Tabs are considered tabwidth characters long.
)rr0�width)r?rs rr�zSqueezer.count_liness��)��D�L�L�,>�,>�?�?rc��|jjtj�}dD]}||vs�n|jj �y|jj|tjdz�\}}|jj
||�}t|�dkDr+|ddk(r#|jjd|z�}|dd}|jj||�|j|�}t||||�}|jj||d d
��t|j�}|dkDre|jj|j|dz
d
|�r8|dz}|dkDr.|jj|j|dz
d
|�r�8|jj!||�y)z�Squeeze the text block where the insertion cursor is.
If the cursor is not in a squeezable block of text, give the
user a small warning and do nothing.
)r��stderrrRz+1cr���rz%s-1cNr�r�r�r
�>)r"� tag_namesr4�INSERT�bell�
tag_prevrange�getrrVr3rXr�rr�rZ�comparerW) r?r��tag_namer�endrr.r��is r�squeeze_current_textzSqueezer.squeeze_current_text"s����I�I�'�'�� � �2� �,�H��9�$��-�
�I�I�N�N����Y�Y�,�,�X�r�y�y�5�7H�I�
��s��I�I�M�M�%��%���q�6�A�:�!�B�%�4�-��)�)�/�/�'�C�-�0�C��#�2��A�
�����e�S�)��%�%�a�(�
�)�!�X�z�4�H��
� � ����o�%&�Q� � 0�
��%�%�&���!�e�� � �)�)�$�*?�*?��!��*D�*-��@�
��F�A��!�e�� � �)�)�$�*?�*?��!��*D�*-��@�
���$�$�Q��8�rN) rxryrzr{�classmethodr�r6r�r�r|rrr~r~�s,���
�
��
�= �~@�-rr~�__main__)r�zidlelib.idle_test.test_squeezerr�F)� verbosity�exit)r%)r{r
�tkinterr4r�idlelib.configr�idlelib.textviewr�idlelib.tooltipr�idlelibrrr5rr~r�rx�unittestr�r|rr�<module>r�sr���
���#�&�$��5�pq�b�i�i�q�hG�G�T �����z���� *�a�e�D�r
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists