B
„ f(2 ã @ s¨ d Z ddlZddlZddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZ ddd „ZG d
d„ dejƒZG dd
„ d
ƒZe ¡ edkr¤ddlmZ edddd� 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-clicking 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)ÚidleConf)Ú view_text)ÚHovertip)ÚmacosxéP c C sæ d}d}d}d}xžt d| ¡D ]Ž}| ¡ | }||7 }||7 }| | dkrp||krb||d | 7 }|d7 }d}n4| | dks€t‚|||| 7 }||kr¤|d7 }|}|d7 }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Úlen)ÚsZ linewidthZtabwidthÚposZ linecountZcurrent_columnÚmÚnumchars© r ú5/opt/alt/python37/lib64/python3.7/idlelib/squeezer.pyÚcount_lines_with_wrapping s0 r c @ sJ e Zd ZdZdd„ Zdd„ Zddd„Zdd d
„Zddd„Zd
Z 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| _|dkrFdnd}d|› d|› d�}t j
j| ||ddd � d
} t| | dd� |
d
| j¡ t ¡ rª|
d| j¡ n|
d| j¡ | ‡ fdd„¡ d | _| | j¡ d S )Nr ÚlinesÚlinezSqueezed text (ú z).z#FFFFC0z#FFFFE0)ÚtextZ
backgroundZactivebackgroundz5Double-click to expand, right-click for more options.r )Zhover_delayzz
z
c s ˆ t | ƒt | ƒt |ƒ … S )N)Úint)ÚoffsetÚlength)r r r Úz ó z*ExpandingButton.__init__..)r ÚtagsÚ
numoflinesÚsqueezerÚeditwinr ÚperÚbottomÚ base_textÚtkÚButtonÚ__init__r ZbindÚexpandr ZisAquaTkÚcontext_menu_eventZselection_handleÚis_dangerousZ
after_idleÚset_is_dangerous)
Úselfr r! r" r# r$ r Zline_pluralityZbutton_textZbutton_tooltip_textr )r r r* _ s*
zExpandingButton.__init__c sL d| j ¡ ‰ | jdkpDt| jƒdkpDt‡ fdd„t d| j¡D ƒƒ| _d S )Né2 iè iPà c 3 s | ]}t | d ¡ƒˆ kV qdS )r N)r Úgroup)Ú.0Z
line_match)Údangerous_line_lenr r ú … s z3ExpandingButton.set_is_dangerous..z[^\n]+) r Zwinfo_widthr" r r Úanyr r r- )r/ r )r3 r r. s
z ExpandingButton.set_is_dangerousNc C sŽ | j dkr| ¡ | j rTtjdd ddddg¡| jt| jƒf tj| j d�}|sTd S | j
| j | ¡| j| j
¡ | j
| ¡ | jj | ¡ dS )
aA expand 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" r r ZCANCELr r' ÚinsertÚindexr! Údeleter# ÚexpandingbuttonsÚremove)r/ ÚeventZconfirmr r r r+ Š s$
zExpandingButton.expandc C s | ¡ | | j¡ dS )zMcopy event handler
Copy the original text to the clipboard.
N)Zclipboard_clearZclipboard_appendr )r/ rB r r r Úcopy§ s zExpandingButton.copyc C s t | jd| jddd� dS )z]view event handler
View the original text in a separate text viewer window.
zSqueezed Output ViewerFZnone)ZmodalZwrapN)r r r )r/ rB r r r Úview¯ s zExpandingButton.view))rC rC )rD rD c C sf | j dd|j|jf ¡ tj| j dd�}x&| jD ]\}}|j|t| |ƒd� q2W | |j
|j¡ dS )Nr= z@%d,%dr )Ztearoff)ÚlabelZcommandr: )r Zmark_setÚxÚyr( ZMenuÚrmenu_specsZadd_commandÚgetattrZtk_popupZx_rootZy_root)r/ rB ZrmenurE Zmethod_namer r r r, ½ s z"ExpandingButton.context_menu_event)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r* r. r+ rC rD rH r, r r r r r T s
r c @ s4 e Zd ZdZedd„ ƒ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.
c C s t jdddddd�| _dS )z!Load class variables from config.ÚmainZPyShellzauto-squeeze-min-linesr r0 )Útyper8 N)r Z GetOptionÚauto_squeeze_min_lines)Úclsr r r ÚreloadÌ s zSqueezer.reloadc sd |ˆ _ |j ˆ _‰|jjˆ _dtˆ d¡ƒtˆ d¡ƒ ˆ _g ˆ _d|j f‡ ‡fdd„ }||_ dS )ae Initialize 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.
é ZborderÚpadxr c s¨ |dkr|| |ƒS ˆ j }t| ƒ|k r.|| |ƒS ˆ | ¡}||k rJ|| |ƒS t| ||ˆ ƒ}ˆ dtj¡ ˆjd|ddd� ˆ d¡ ˆ ¡ ˆ dtj
¡ ˆ j |¡ d S )NÚstdoutZiomarké é )ÚwindowrU Úpady)
rQ r Úcount_linesr Zmark_gravityr( ZRIGHTÚ
window_createZseeÚupdateZLEFTr@ Úappend)r r! ÚwriterQ r" Úexpandingbutton)r/ r r r Úmywriteó s
z"Squeezer.__init__..mywriteN)
r$ r r% r&