Your IP : 18.222.179.96


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

3

� f�3�@s�dZddlZddlZddlmZddljZddl	m
Z
ddlmZddl
mZddlmZdd
d�ZGdd
�d
ej�ZGdd�d�Zej�edkr�ddlmZedddd�dS)a
An 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-cliking 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)�Font)�idleConf)�	view_text)�Hovertip)�macosx�P�c
Cs�d}d}d}x�tjd|�D]�}|j�|}||7}||7}||dkrT|d7}d}n$||||7}||krx|d7}|}|d7}|dkrt|d|�\}}	||7}|	d}qW|t|�|7}|dkr�||d|7}n|d8}|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�divmod�len)
�s�	linewidth�tabwidth�posZ	linecountZcurrent_column�m�numchars�lines�column�r�5/opt/alt/python36/lib64/python3.6/idlelib/squeezer.py�count_lines_with_wrappings0rc@sJeZdZdZdd�Zdd�Zddd�Zdd	d
�Zddd�ZdZ	dd�Z
dS)�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	s��|_||_||_||_|j|_}|j|_}|jj|_d|j}t	j
j|||ddd�d}t||dd�|j
d|j�tj�r�|j
d	|j�n|j
d
|j�|j�fdd��d|_|j|j�dS)
NzSqueezed text (%d lines).z#FFFFC0z#FFFFE0)�textZ
backgroundZactivebackgroundz5Double-click to expand, right-click for more options.r)Zhover_delayz<Double-Button-1>z
<Button-2>z
<Button-3>cs�t|�t|�t|��S)N)�int)�offsetZlength)rrr�<lambda>}sz*ExpandingButton.__init__.<locals>.<lambda>)r�tags�
numoflines�squeezer�editwinr�per�bottom�	base_text�tk�Button�__init__rZbind�expandrZisAquaTk�context_menu_eventZselection_handle�is_dangerousZ
after_idle�set_is_dangerous)	�selfrr r!r"r#rZbutton_textZbutton_tooltip_textr)rrr)as(


zExpandingButton.__init__csLd|jj��|jdkpDt|j�dkpDt�fdd�tjd|j�D��|_dS)N�2i�iP�c3s |]}t|jd���kVqdS)rN)r�group)�.0Z
line_match)�dangerous_line_lenrr�	<genexpr>�sz3ExpandingButton.set_is_dangerous.<locals>.<genexpr>z[^\n]+)	r�winfo_widthr!rr�anyrrr,)r.r)r2rr-�s

z ExpandingButton.set_is_dangerousNcCs�|jdkr|j�|jrTtjddjddddg�|jt|j�ftj|j	d�}|sTd	S|j
j|j	j|�|j|j
�|j
j|�|jjj|�dS)
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-�tkMessageBoxZaskokcancel�joinr!rrZCANCELrr&�insert�indexr �deleter"�expandingbuttons�remove)r.�eventZconfirmrrrr*�s$	

zExpandingButton.expandcCs|j�|j|j�dS)zMcopy event handler

        Copy the original text to the clipboard.
        N)Zclipboard_clearZclipboard_appendr)r.rBrrr�copy�szExpandingButton.copycCst|jd|jddd�dS)z]view event handler

        View the original text in a separate text viewer window.
        zSqueezed Output ViewerFZnone)ZmodalZwrapN)rrr)r.rBrrr�view�szExpandingButton.viewrCrDcCsf|jjdd|j|jf�tj|jdd�}x&|jD]\}}|j|t||�d�q2W|j	|j
|j�dS)Nr=z@%d,%dr)Ztearoff)�labelZcommandr:)rZmark_set�x�yr'ZMenu�rmenu_specsZadd_command�getattrZtk_popupZx_rootZy_root)r.rBZrmenurEZmethod_namerrrr+�sz"ExpandingButton.context_menu_event)N)N)N�rCrC�rDrD)rJrK)�__name__�
__module__�__qualname__�__doc__r)r-r*rCrDrHr+rrrrrVs
!



rc@s4eZdZdZedd��Zdd�Zdd�Zdd	�Zd
S)�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.
    cCstjdddddd�|_dS)z!Load class variables from config.�main�PyShellzauto-squeeze-min-linesrr/)�typer8N)rZ	GetOption�auto_squeeze_min_lines)�clsrrr�reload�szSqueezer.reloadcsX|�_|j�_�|jj�_g�_ddlm}t||�rTf|j	f��fdd�	}||_	dS)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.
        r)rRcs�|dkr|||�S�j|�}|�jkr0|||�St|||��}�jdtj��jd|ddd��jd��j��jdtj	��j
j|�dS)N�stdoutZiomark��)�window�padx�pady)�count_linesrTrZmark_gravityr'ZRIGHT�
window_createZsee�updateZLEFTr@�append)rr �writer!�expandingbutton)r.rrr�mywrite�s





z"Squeezer.__init__.<locals>.mywriteN)
r#rr$r%r&r@Zidlelib.pyshellrR�
isinstancera)r.r#rRrcr)r.rrr)�s


zSqueezer.__init__csh�jj�}�jjj�}|dt�fdd�d	D��8}t�jj�jjjd�d�}||jd�}t|||�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.
        �csg|]}t�jjj|���qSr)rr#r�cget)r1Zopt)r.rr�
<listcomp>sz(Squeezer.count_lines.<locals>.<listcomp>�borderr[�font)�name�0)rhr[)	r#Zget_tk_tabwidthrr4�sumrrfZmeasurer)r.rrrrir)r.rr]s
zSqueezer.count_linesc
Cs|jjtj�}x$dD]}||krPqW|jj�dS|jj|tjd�\}}|jj||�}t|�dkr�|ddkr�|jjd|�}|d	d�}|j	j
||�|j|�}t||||�}|jj
||d
dd�t|j�}	x0|	dko�|jj|j|	dd
|��r|	d8}	q�W|jj|	|�dS)z�squeeze-current-text event handler

        Squeeze the block of text inside which contains the "insert" cursor.

        If the insert cursor is not in a squeezable block of text, give the
        user a small warning and do nothing.
        rW�stderrr:z+1crr	r
z%s-1cNrXrY)rZr[r\�>)rWrm���ro)r�	tag_namesr'ZINSERTZbellZ
tag_prevrange�getrr>r&r?r]rr^r@Zcomparer=)
r.rBrpZtag_namer
�endrr!rb�irrr�squeeze_current_text_event*s,	






z#Squeezer.squeeze_current_text_eventN)	rLrMrNrO�classmethodrVr)r]rtrrrrrP�s
4rP�__main__)rQzidlelib.idle_test.test_squeezerreF)�	verbosity�exit)rr)rOrZtkinterr'Ztkinter.fontrZtkinter.messageboxZ
messageboxr;Zidlelib.configrZidlelib.textviewrZidlelib.tooltiprZidlelibrrr(rrPrVrLZunittestrQrrrr�<module>s 

9s

?>