Your IP : 18.225.117.89


Current Path : /opt/alt/python36/lib64/python3.6/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/idlelib/__pycache__/replace.cpython-36.opt-1.pyc

3

� fN�@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 for search capability.
Defines various replace related functions like replace, replace all,
replace+find.
�N)�	StringVar�TclError)�SearchDialogBase)�searchenginecCs<|j�}tj|�}t|d�s(t||�|_|j}|j|�dS)zvReturns a singleton ReplaceDialog instance.The single dialog
     saves user entries and preferences across instances.�_replacedialogN)Z_rootr�get�hasattr�
ReplaceDialogr�open)�text�root�engineZdialog�r�4/opt/alt/python36/lib64/python3.6/idlelib/replace.py�replace
s

rc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zddd
�Z	d dd�Z
d!dd�Zdd�Zd"dd�Z
d#dd�Zdd�Zdd�Zd$dd�ZdS)%r	zReplace Dialog�ReplacecCstj|||�t|�|_dS)N)r�__init__r�replvar)�selfrr
rrrrszReplaceDialog.__init__cCs�tj||�y|jd�}Wntk
r2d}YnXy|jd�}Wntk
rZd}YnX|ph|jd�}|pp|}|j||�d|_dS)zDisplay the replace dialogz	sel.firstNzsel.last�insert�)rr
�indexr�show_hit�ok)rr�first�lastrrrr
!s

zReplaceDialog.opencCs"tj|�|jd|j�d|_dS)z#Create label and text entry widgetsz
Replace with:rN)r�create_entriesZ
make_entryrZreplent)rrrrr1s
zReplaceDialog.create_entriescCsHtj|�|jd|j�|jd|j�|jd|jd�|jd|j�dS)NZFindrzReplace+FindrzReplace All)r�create_command_buttonsZmake_button�find_it�
replace_it�default_command�replace_all)rrrrr6s

z$ReplaceDialog.create_command_buttonsNcCs|jd�dS)Nr)�do_find)r�eventrrrr=szReplaceDialog.find_itcCs|j|j�r|j�dS)N)r"r�
do_replace)rr#rrrr@szReplaceDialog.replace_itcCs"|j|j�r|j�r|jd�dS)zReplace and find next.rN)r"rr$)rr#rrrr DszReplaceDialog.default_commandcCsL|jj�rDy|j|�}WqHtjk
r@|jj|d�d}YqHXn|}|S)za Helper function for expanding a regular expression
            in the replace field, if needed. zInvalid Replace ExpressionN)r
Zisre�expand�re�errorZreport_error)r�m�repl�newrrr�_replace_expandKs
zReplaceDialog._replace_expandcCs�|jj�}|sdS|jj�}|j}|jj||�}|s@|j�dS|jddd�|jddd�|d}|dj�}|jj	�r�d}d}d}d}	}
|j
�x�|jj||||d|�}|s�P|\}}|jd|d|d�}|j�}
|j
||�}|dkr�P|j�\}}d	||f}	d	||f}
||
k�r.|jd
|
�n4|jd
|	�|	|
k�rP|j|	|
�|�rb|j|	|�|t|�}d}q�W|j�|	�r�|
�r�|j|	|
�|j�dS)z4Replace all instances of patvar with replvar in textN�selz1.0�end�hitrrz%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!YsZ




zReplaceDialog.replace_allrc
Csv|jj�sdS|j}|jj|d|�}|s4|j�dS|\}}|j�\}}d||f}d||f}	|j||	�d|_dS)NFz%d.%drT)r
r/rr0r1r6rr)
rrrr=r>r(rArBrrrrrr"�s
zReplaceDialog.do_findc
Cs|jj�}|sdS|j}y|jd�}}|jd�}Wntk
rLd}YnX|sd|jd�}}}tj|�\}}|jd|d|d�}|j||�}	|s�dS|j	|	|j
j��}
|
dkr�dS|jd|�|j�|	j
�r�|j||�|
r�|j||
�|j�|j||jd��d|_dS)	NFz	sel.firstzsel.lastrz%d.0rrT)r
r/rrrrZget_line_colr�matchr+rr7r4r5r8rr:rr)rr<rr�posrr>r?r@r(r*rrrr$�s:

zReplaceDialog.do_replacecCsv|j}|jd|�|jddd�|jd||�|jddd�||krR|jd|�n|jd||�|jd�|j�dS)zMHighlight text from 'first' to 'last'.
        'first', 'last' - Text indicesrr,z1.0r-r.N)rr7r2�tag_addZseeZupdate_idletasks)rrrrrrrr�s
zReplaceDialog.show_hitcCs tj||�|jjddd�dS)Nr.z1.0r-)rr;rr2)rr#rrrr;�szReplaceDialog.close)N)N)N)N)r)N)�__name__�
__module__�__qualname__�titleZiconrr
rrrrr r+r!r"r$rr;rrrrr	s



2
r	cs�ddlm}m}m�m�ddlm}||�}|jd�tt	|j
�jd�dd��\}}|j
d||df�d	d
�}dd�}||d
d��|�_|�_
�j��jdd��j����fdd�}	||d|	d�}
|
j�dS)Nr)�Toplevel�Text�END�SEL)�ButtonzTest ReplaceDialog�+rz+%d+%d�cSsdS)Nrrrrrr4�sz)_replace_dialog.<locals>.undo_block_startcSsdS)Nrrrrrr:�sz(_replace_dialog.<locals>.undo_block_stopZgray)Zinactiveselectbackgroundrz"This is a sample sTring
Plus MORE.cs(�j�d��t���j�d��dS)Nz1.0)rErr2r)rLrMrrr�show_replace�sz%_replace_dialog.<locals>.show_replacer)rZcommand)�tkinterrJrKrLrMZtkinter.ttkrNrI�map�intZgeometry�splitr4r:ZpackrZ	focus_set)�parentrJrKrNZbox�x�yr4r:rQZbuttonr)rLrMrr�_replace_dialog�s"
 rY�__main__)�mainzidlelib.idle_test.test_replace�F)�	verbosity�exit)�run)�__doc__r&rRrrZidlelib.searchbaserZidlelibrrr	rYrFZunittestr[Zidlelib.idle_test.htestr_rrrr�<module>s7

?>