File: D:/Python311/Lib/idlelib/__pycache__/replace.cpython-311.opt-1.pyc
�
��VcB( � � � d Z ddlZddlmZmZ ddlmZ ddlmZ dd�Z G d� de� � Z
d � Zed
k r'ddl
mZ edd
d�� � ddlmZ ee� � dS dS )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 �� � | � � � }t j |� � }t |d� � st ||� � |_ |j }|� | |�� � dS )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)�insert_tagsN)�_rootr �get�hasattr�
ReplaceDialogr �open)�textr �root�engine�dialogs �#D:\Python311\Lib\idlelib\replace.py�replacer sj � � �:�:�<�<�D�
�
�d�
#�
#�F��6�+�,�,� <� -�d�F� ;� ;���
�
"�F�
�K�K��+�K�.�.�.�.�.� c � � � e Zd ZdZdZdZ� fd�Zdd�Zd� Zd� Z dd �Z
dd
�Zdd�Zd� Z
dd
�Zdd�Zd� Zd� Zdd�Z� xZS )r
z3Dialog for finding and replacing a pattern in text.zReplace Dialog�Replacec � �� t � � � ||� � t |� � | _ d| _ dS )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 )�selfr r � __class__s �r r zReplaceDialog.__init__% s: �� � ������v�&�&�&� ����������r Nc �R � t j | |� � |� d� � }n# t $ r d}Y nw xY w |� d� � }n# t $ r d}Y nw xY w|p|� d� � }|p|}| � ||� � d| _ || _ dS )z�Make dialog visible on top of others and ready to use.
Also, highlight the currently selected text and set the
search to include the current selection (self.ok).
Args:
text: Text widget being searched.
� sel.firstN�sel.last�insertT)r r �indexr �show_hit�okr )r r r �first�lasts r r zReplaceDialog.open6 s� � � ��d�D�)�)�)� ��J�J�{�+�+�E�E��� � � ��E�E�E� ���� ��:�:�j�)�)�D�D��� � � ��D�D�D� �����-����H�-�-���}�u���
�
�e�T�"�"�"����&����s �- �<�<� A �A%�$A%c �z � t j | � � | � d| j � � d | _ dS )z8Create base and additional label and text entry widgets.z
Replace with:r N)r �create_entries�
make_entryr �replent�r s r r( zReplaceDialog.create_entriesN s3 � ��'��-�-�-�������E�E�a�H����r c �
� t j | � � | � d| j � � | � d| j � � | � d| j d�� � | � d| j � � dS )z�Create base and additional command buttons.
The additional buttons are for Find, Replace,
Replace+Find, and Replace All.
�Findr zReplace+FindT)�isdefzReplace AllN)r �create_command_buttons�make_button�find_it�
replace_it�default_command�replace_allr+ s r r/ z$ReplaceDialog.create_command_buttonsS s� � � �/��5�5�5�������.�.�.�����D�O�4�4�4������)=�T��J�J�J������(8�9�9�9�9�9r c �0 � | � d� � dS )zHandle the Find button.FN)�do_find�r �events r r1 zReplaceDialog.find_it_ s � ����U�����r c �f � | � | j � � r| � � � dS dS )z]Handle the Replace button.
If the find is successful, then perform replace.
N�r6 r$ �
do_replacer7 s r r2 zReplaceDialog.replace_itc s: � �
�<�<��� � � ��O�O������ � r c � � | � | j � � r+| � � � r| � d� � dS dS dS )z�Handle the Replace+Find button as the default command.
First performs a replace and then, if the replace was
successful, a find next.
FNr: r7 s r r3 zReplaceDialog.default_commandk sX � � �<�<��� � � $���� � �
$����U�#�#�#�#�#� $� $�
$�
$r c �� � | j � � � rI |� |� � }n4# t j $ r | j � |d� � d}Y nw xY w|}|S )z.Expand replacement text if regular expression.zInvalid Replace ExpressionN)r �isre�expand�re�error�report_error)r �m�repl�news r �_replace_expandzReplaceDialog._replace_expandv sy � ��;����� �
��h�h�t�n�n�����8�
�
�
���(�(��/K�L�L�L�����
���� �C��
s �1 �,A �A c �� � | j � � � }|sdS | j � � � }| j }| j � ||� � }|s| � � � dS |� ddd� � |� ddd� � |d }|d � � � }| j � � � rd}d}d}dx} }
|�
� � | j � ||||d |�
� � x}�r|\ }}|� d|z d|dz z � � }|� � � }
| �
||� � }|�n�|� � � \ }}d||fz } d||fz }
||
k r|� d
|
� � nP|� d
| � � | |
k r|� | |
� � |r|� | || j � � |t'