Sindbad~EG File Manager
�
&Μgq&����dZddlZeje_ddlmZmZddlmZddl m
Z
dd�ZGd�de�Zd �Z
ed
k(r ddlmZedd
d��ddlmZee
�yy)z�Replace dialog for IDLE. Inherits SearchDialogBase for GUI.
Uses idlelib.searchengine.SearchEngine for search capability.
Defines various replace related functions like replace, replace all,
and replace+find.
�N)� StringVar�TclError)�SearchDialogBase)�searchenginec���|j�}tj|�}t|d�st ||�|_|j
}|jdd�}|j
|||��y)z�Create or reuse a singleton ReplaceDialog instance.
The singleton dialog saves user entries and preferences
across instances.
Args:
text: Text widget containing the text to be searched.
�_replacedialog� sel.first�sel.last��insert_tagsN)�_rootr�get�hasattr�
ReplaceDialogr�open)�textr�root�engine�dialog�searchphrases �,/usr/local/lib/python3.12/idlelib/replace.py�replacersf���:�:�<�D�
�
�
�d�
#�F��6�+�,� -�d�F� ;���
�
"�
"�F��8�8�K��4�L�
�K�K��l��K�<�c���eZdZdZdZdZ�fd�Zddd�d�Zd�Zd �Z dd
�Z
dd�Zdd�Zd
�Z
dd�Zdd�Zd�Zd�Zdd�Z�xZS)rz3Dialog for finding and replacing a pattern in text.zReplace Dialog�Replacec�T��t�|�||�t|�|_d|_y)a�Create search dialog for finding and replacing text.
Uses SearchDialogBase as the basis for the GUI and a
searchengine instance to prepare the search.
Attributes:
replvar: StringVar containing 'Replace with:' value.
replent: Entry widget for replvar. Created in
create_entries().
ok: Boolean used in searchengine.search_text to indicate
whether the search includes the selection.
N)�super�__init__r�replvarr)�selfrr� __class__s �rrzReplaceDialog.__init__'s'��� ����v�&� �������rNrc�N�tj|||�d|_||_y)aMake dialog visible on top of others and ready to use.
Also, set the search to include the current selection
(self.ok).
Args:
text: Text widget being searched.
searchphrase: String phrase to search.
TN)rr�okr)r rrrs rrzReplaceDialog.open8s%�� ���d�D�,�7����&��rc�v�tj|�|jd|j�d|_y)z8Create base and additional label and text entry widgets.z
Replace with:rN)r�create_entries�
make_entryr�replent�r s rr%zReplaceDialog.create_entriesFs+���'�'��-��������E�a�H��rc��tj|�|jd|j�|jd|j�|jd|j
d��|jd|j�y)z�Create base and additional command buttons.
The additional buttons are for Find, Replace,
Replace+Find, and Replace All.
�FindrzReplace+FindT)�isdefzReplace AllN)r�create_command_buttons�make_button�find_it�
replace_it�default_command�replace_allr(s rr,z$ReplaceDialog.create_command_buttonsKsk�� �/�/��5��������.�����D�O�O�4������)=�)=�T��J������(8�(8�9rc�&�|jd�y)zHandle the Find button.FN)�do_find�r �events rr.zReplaceDialog.find_itWs�����U�rc�\�|j|j�r|j�yy)z]Handle the Replace button.
If the find is successful, then perform replace.
N�r3r#�
do_replacer4s rr/zReplaceDialog.replace_it[s#��
�<�<���� ��O�O��!rc��|j|j�r#|j�r|jd�yyy)z�Handle the Replace+Find button as the default command.
First performs a replace and then, if the replace was
successful, a find next.
FNr7r4s rr0zReplaceDialog.default_commandcs4���<�<���� ���� ����U�#�!�!rc���|jj�r |j|�}|S|}|S#tj$r"|jj|d�d}Y|SwxYw)z.Expand replacement text if regular expression.zInvalid Replace ExpressionN)r�isre�expand�re�PatternError�report_error)r �m�repl�news r�_replace_expandzReplaceDialog._replace_expandnsm���;�;����
��h�h�t�n���
��C��
��
�?�?�
����(�(��/K�L����
�
�s�3�1A(�'A(c�r�|jj�}|sy|jj�}|j}|jj||�}|s|j
�y|jddd�|jddd�|d}|dj�}|jj�rd}d}d}dx} }
|j�|jj||||d |�
�x}r�|\}}|jd|zd|dzz�}|j�}
|j||�}|�n�|j�\}}d||fz} d||fz}
||
k(r|jd
|
�nH|jd
| �| |
k7r|j!| |
�|r|j#| ||j$�|t'|�z}d }|jj||||d |�
�x}r��|j)�| r|
r|j+| |
�|j-�y)a�Handle the Replace All button.
Search text for occurrences of the Find value and replace
each of them. The 'wrap around' value controls the start
point for searching. If wrap isn't set, then the searching
starts at the first occurrence after the current selection;
if wrap is set, the replacement starts at the first line.
The replacement is always done top-to-bottom in the text.
N�sel�1.0�end�hitr�TF)�wrapr#�%d.0�%d.%d�insert)r�getprogrrr�search_text�bell�
tag_remove�start�iswrap�undo_block_start�search_forward�grouprC�span�mark_set�deleterMr�len�undo_block_stop�show_hit�close)r r5�progrAr�res�line�colr#�first�lastr@�chars�origrB�i�js rr1zReplaceDialog.replace_all{s.���{�{�"�"�$�����|�|���!���y�y���k�k�%�%�d�D�1����I�I�K������u�e�,�����u�e�,��1�v���!�f�l�l�n���;�;�����D��C�
�����������[�[�/�/��d�D�#�E�b�0�:�:�c�:��G�D�!��H�H�V�d�]�F�d�1�f�,=�>�E��7�7�9�D��&�&�q�$�/�C��{���6�6�8�D�A�q��t�Q�i�'�E��d�A�Y�&�D��d�{��
�
�h��-��
�
�h��.��D�=��K�K��t�,���K�K��s�D�,<�,<�=��c�#�h�,�C��B�)�[�[�/�/��d�D�#�E�b�0�:�:�c�:�*
�����T��M�M�%��&��
�
�rc�0�|jj�sy|j}|jj|d|�}|s|j �y|\}}|j�\}}d||fz}d||fz} |j
|| �d|_y)z|Search for and highlight next occurrence of pattern in text.
No text replacement is done with this option.
FNrLT)rrNrrOrPrWr\r#)
r r#rr_r`r@rfrgrbrcs
rr3zReplaceDialog.do_find�s���
�{�{�"�"�$���y�y���k�k�%�%�d�D�"�5����I�I�K�����a��v�v�x���1��4��)�#���$���"���
�
�e�T�"����rc��|jj�}|sy|j} |jd�x}}|jd�}|s|jd�x}x}}tj|�\}}|jd|zd|dzz�}|j||�} |sy|j| |jj��}
|
�y|jd�|j�| j�r|j|�|
r|j||
|j �|j#�|j%||jd��d|_y#t$rd}Y��6wxYw) z6Replace search pattern in text with replacement value.Fr r
NrMrKrIT)rrNr�indexrr�get_line_colr�matchrCrrXrTrVrYrMrr[r\r#)r r^rrb�posrcr`rardr@rBs rr8zReplaceDialog.do_replace�sa���{�{�"�"�$�����y�y�� ��*�*�[�1�1�E�C��:�:�j�)�D��!%���H�!5�5�E�5�D�3� �-�-�c�2� ��c�����$���$�q�&�(9�:���J�J�u�c�"�����"�"�1�d�l�l�&6�&6�&8�9���;���
�
�h��&������7�7�9��K�K��t�$���K�K��s�D�$4�$4�5������
�
�e�T�Z�Z��1�2������+� ��C� �s�$E7�7F�Fc�J�|j}|jd|�|jddd�|jd||�|jddd�||k(r|jd|�n|jd||�|j d�|j�y)a�Highlight text between first and last indices.
Text is highlighted via the 'hit' tag and the marked
section is brought into view.
The colors from the 'hit' tag aren't currently shown
when the text is displayed. This is due to the 'sel'
tag being added first, so the colors in the 'sel'
config are seen instead of the colors for 'hit'.
rMrErFrGrHN)rrXrQ�tag_add�see�update_idletasks)r rbrcrs rr\zReplaceDialog.show_hit�s����y�y���
�
�h��&�����u�e�,����U�E�4�(�����u�e�,��D�=��L�L���&��L�L���t�,���������rc�x�tj||�|jjddd�d|_y)z%Close the dialog and remove hit tags.rHrFrGN)rr]rrQrr4s rr]zReplaceDialog.close�s0�����t�U�+�� � ���U�E�5�1���r�N)F)�__name__�
__module__�__qualname__�__doc__�title�iconrrr%r,r.r/r0rCr1r3r8r\r]�
__classcell__)r!s@rrr!s[���9��E��D� �"'�4�'�I�
:��� $��6�p�(�@ �. rrc��
���ddlm}m}m�
m�ddlm}m}||�}|jd�tt|j�jd�dd�\}}|jd||dzfz�d �}d
�} ||�}
|
j�||
d���|�_| �_�j��j!d
d��j#��
��fd�}||
d|��}|j�y)Nr)�Toplevel�Text�END�SEL)�Frame�ButtonzTest ReplaceDialog�+rIz+%d+%d�c��yrs�r�rrrTz)_replace_dialog.<locals>.undo_block_start���rc��yrsr�r�rrr[z(_replace_dialog.<locals>.undo_block_stopr�r�gray)�inactiveselectbackgroundrMz"This is a sample sTring
Plus MORE.c�h���j�d��t���j�d��y)NrF)rorrQ)r~rrs���r�show_replacez%_replace_dialog.<locals>.show_replaces*������S�%��%���
�����U�C�(rr)r�command)�tkinterr|r}r~r�tkinter.ttkr�r�rx�map�int�geometry�split�packrTr[rM� focus_set)�parentr|r}r�r��top�x�yrTr[�framer��buttonr~rrs @@@r�_replace_dialogr�s����0�0�)�
�6�
�C��I�I�"�#��s�F�O�O�%�+�+�C�0���4�5�D�A�q��L�L��Q��C��L�(�)�
�
�
�#�J�E� �J�J�L����7�D�,�D��*�D���I�I�K��K�K��>�?��N�N��)�
�E� �<�
@�F�
�K�K�Mr�__main__)�mainzidlelib.idle_test.test_replace�F)� verbosity�exit)�runrs)rwr=�errorr>r�rr�idlelib.searchbaser�idlelibrrrr�rt�unittestr��idlelib.idle_test.htestr�r�rr�<module>r�sh���
��(�(���'�/� �=�$a �$�a �H�D�z���� )�Q�U�C�+����r
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists