ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/replace.cpython-37.pyc

B

� f�&�@s�dZddlZddlmZmZddlmZddlmZdd�Z	Gdd	�d	e�Z
d
d�Zedkr�dd
l
mZedddd�ddlmZee�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)�searchenginecCs<|��}t�|�}t|d�s(t||�|_|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.
    �_replacedialogN)Z_rootr�get�hasattr�
ReplaceDialogr�open)�text�root�engineZdialog�r�4/opt/alt/python37/lib64/python3.7/idlelib/replace.py�replaces	

rcs�eZdZdZdZdZ�fdd�Zdd�Zdd	�Zd
d�Z	d d
d�Z
d!dd�Zd"dd�Zdd�Z
d#dd�Zd$dd�Zdd�Zdd�Zd%dd�Z�ZS)&r	z3Dialog for finding and replacing a pattern in text.zReplace Dialog�Replacecst��||�t|�|_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�replvar)�selfrr
)�	__class__rrr%s
zReplaceDialog.__init__cCs�t�||�y|�d�}Wntk
r2d}YnXy|�d�}Wntk
rZd}YnX|ph|�d�}|pp|}|�||�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.
        z	sel.firstNzsel.last�insertT)rr
�indexr�show_hit�ok)rr�first�lastrrrr
5s	

zReplaceDialog.opencCs"t�|�|�d|j�d|_dS)z8Create base and additional label and text entry widgets.z
Replace with:rN)r�create_entriesZ
make_entryrZreplent)rrrrrLs
zReplaceDialog.create_entriescCsJt�|�|�d|j�|�d|j�|jd|jdd�|�d|j�dS)z�Create base and additional command buttons.

        The additional buttons are for Find, Replace,
        Replace+Find, and Replace All.
        ZFindrzReplace+FindT)ZisdefzReplace AllN)r�create_command_buttonsZmake_button�find_it�
replace_it�default_command�replace_all)rrrrrQs

z$ReplaceDialog.create_command_buttonsNcCs|�d�dS)zHandle the Find button.FN)�do_find)r�eventrrrr]szReplaceDialog.find_itcCs|�|j�r|��dS)z]Handle the Replace button.

        If the find is successful, then perform replace.
        N)r#r�
do_replace)rr$rrrr aszReplaceDialog.replace_itcCs"|�|j�r|��r|�d�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.
        FN)r#rr%)rr$rrrr!iszReplaceDialog.default_commandcCsL|j��rDy|�|�}WqHtjk
r@|j�|d�d}YqHXn|}|S)z.Expand replacement text if regular expression.zInvalid Replace ExpressionN)r
Zisre�expand�re�errorZreport_error)r�m�repl�newrrr�_replace_expandts
zReplaceDialog._replace_expandcCs�|j��}|sdS|j��}|j}|j�||�}|s@|��dS|�ddd�|�ddd�|d}|d��}|j�	�r�d}d}d}d}	}
|�
�x�|jj||||d	|d
�}|s�P|\}}|�d|d|d�}|��}
|�
||�}|dkr�P|��\}}d||f}	d||f}
||
k�r0|�d
|
�n4|�d
|	�|	|
k�rR|�|	|
�|�rd|�|	|�|t|�}d	}q�W|��|	�r�|
�r�|�|	|
�|��dS)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�selz1.0�end�hitr�TF)Zwraprz%d.0z%d.%dr)r
�getprogrrr�search_text�bell�
tag_remove�startZiswrap�undo_block_startZsearch_forward�groupr,�span�mark_set�deleter�len�undo_block_stopr�close)rr$�progr*r�res�line�colrrrr)�charsZorigr+�i�jrrrr"�s\






zReplaceDialog.replace_allFc
Csv|j��sdS|j}|j�|d|�}|s4|��dS|\}}|��\}}d||f}d||f}	|�||	�d|_dS)z|Search for and highlight next occurrence of pattern in text.

        No text replacement is done with this option.
        FNz%d.%dT)r
r1rr2r3r8rr)
rrrr?r@r)rCrDrrrrrr#�s
zReplaceDialog.do_findcCs|j��}|sdS|j}y|�d�}}|�d�}Wntk
rLd}YnX|sd|�d�}}}t�|�\}}|�d|d|d�}|�||�}	|s�dS|�	|	|j
���}
|
dkr�dS|�d|�|��|	�
�r�|�||�|
r�|�||
�|��|�||�d��d|_dS)	z6Replace search pattern in text with replacement value.Fz	sel.firstzsel.lastNrz%d.0r0T)r
r1rrrrZget_line_colr�matchr,rr9r6r7r:rr<rr)rr>rr�posrr@rArBr)r+rrrr%�s:

zReplaceDialog.do_replacecCsv|j}|�d|�|�ddd�|�d||�|�ddd�||krR|�d|�n|�d||�|�d�|��dS)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'.
        rr-z1.0r.r/N)rr9r4�tag_addZseeZupdate_idletasks)rrrrrrrr�s
zReplaceDialog.show_hitcCs t�||�|j�ddd�dS)z%Close the dialog and remove hit tags.r/z1.0r.N)rr=rr4)rr$rrrr=szReplaceDialog.close)N)N)N)N)F)N)�__name__�
__module__�__qualname__�__doc__�titleZiconrr
rrrr r!r,r"r#r%rr=�
__classcell__rr)rrr	s 



;
 r	c
s�ddlm}m}m�m�ddlm}m}||�}|�d�t	t
|���d�dd��\}}|�d||df�d	d
�}dd�}	||�}
|
�
�||
d
d��|�_|	�_��
���dd�������fdd�}||
d|d�}|�
�dS)Nr)�Toplevel�Text�END�SEL)�Frame�ButtonzTest ReplaceDialog�+r0z+%d+%d�cSsdS)Nrrrrrr6sz)_replace_dialog.<locals>.undo_block_startcSsdS)Nrrrrrr<sz(_replace_dialog.<locals>.undo_block_stopZgray)Zinactiveselectbackgroundrz"This is a sample sTring
Plus MORE.cs(���d��t�����d��dS)Nz1.0)rGrr4r)rPrQrrr�show_replace&sz%_replace_dialog.<locals>.show_replacer)rZcommand)�tkinterrNrOrPrQZtkinter.ttkrRrSrL�map�intZgeometry�splitZpackr6r<rZ	focus_set)
�parentrNrOrRrS�top�x�yr6r<�framerVZbuttonr)rPrQrr�_replace_dialog
s&
 r`�__main__)�mainzidlelib.idle_test.test_replace�F)�	verbosity�exit)�run)rKr'rWrrZidlelib.searchbaserZidlelibrrr	r`rHZunittestrbZidlelib.idle_test.htestrfrrrr�<module>so!

Zerion Mini Shell 1.0