Hacked By AnonymousFox

Current Path : /proc/thread-self/root/opt/alt/python36/lib64/python3.6/idlelib/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python36/lib64/python3.6/idlelib/__pycache__/squeezer.cpython-36.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}n4||dksdt�||||7}||kr�|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�AssertionError�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_wrappings2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�anyrr
r.)r0r)r4rr/�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)r0�eventZconfirmrrrr,�s$	

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

        Copy the original text to the clipboard.
        N)Zclipboard_clearZclipboard_appendr)r0rDrrr�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)r0rDrrr�view�szExpandingButton.viewrErFcCsf|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)r0rDZrmenurGZmethod_namerrrr-�sz"ExpandingButton.context_menu_event)N)N)N�rErE�rFrF)rLrM)�__name__�
__module__�__qualname__�__doc__r+r/r,rErFrJr-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-linesrr1)�typer:N)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)rTcs�|dkr|||�S�j|�}|�jkr0|||�St|||��}�jdtj��jd|ddd��jd��j��jdtj	��j
j|�dS)N�stdoutZiomark��)�window�padx�pady)�count_linesrVrZmark_gravityr)ZRIGHT�
window_createZsee�updateZLEFTrB�append)rr"�writer#�expandingbutton)r0rrr�mywrite�s





z"Squeezer.__init__.<locals>.mywriteN)
r%rr&r'r(rBZidlelib.pyshellrT�
isinstancerc)r0r%rTrer)r0rrr+�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)r3Zopt)r0rr�
<listcomp>sz(Squeezer.count_lines.<locals>.<listcomp>�borderr]�font)�name�0)rjr])	r%Zget_tk_tabwidthrr6�sumrrhZmeasurer)r0rrrrkr)r0rr_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.
        rY�stderrr<z+1crr	r
z%s-1cNrZr[)r\r]r^�>)rYro���rq)r�	tag_namesr)ZINSERTZbellZ
tag_prevrange�getrr@r(rAr_rr`rBZcomparer?)
r0rDrrZtag_namer�endrr#rd�irrr�squeeze_current_text_event*s,	






z#Squeezer.squeeze_current_text_eventN)	rNrOrPrQ�classmethodrXr+r_rvrrrrrR�s
4rR�__main__)rSzidlelib.idle_test.test_squeezerrgF)�	verbosity�exit)rr)rQrZtkinterr)Ztkinter.fontrZtkinter.messageboxZ
messageboxr=Zidlelib.configrZidlelib.textviewrZidlelib.tooltiprZidlelibrrr*rrRrXrNZunittestrSrrrr�<module>s 

9s

Hacked By AnonymousFox1.0, Coded By AnonymousFox