B ÓÃic¥gÕeã@s¤ddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddd„ZGd d „d ejƒZGd d „d ƒZe ¡ed kr ddlmZedddddS)éN)ÚidleConf)Ú view_text)ÚHovertip)ÚmacosxéPcCsÖd}d}d}d}xŽt d|¡D]~}| ¡|}||7}||7}||dkrp||krb||d|7}|d7}d}n$||||7}||kr”|d7}|}|d7}qW|t|ƒ|7}|dkrÊ||d|7}n|d8}|S)Néréz[\t\n]Ú )ÚreÚfinditerÚstartÚlen)ÚsZ linewidthZtabwidthÚposZ linecountZcurrent_columnÚmÚnumchars©rú3/opt/alt/python37/lib/python3.7/idlelib/squeezer.pyÚcount_lines_with_wrappings.   rc@sFeZdZdd„Zdd„Zddd„Zddd „Zdd d „Zd Zd d„Z dS)ÚExpandingButtonc sàˆ|_||_||_||_|j|_}|j|_}|jj|_|dkrFdnd}d|›d|›d}t j j |||ddd d } t || d d |  d |j¡t ¡rª|  d|j¡n|  d|j¡| ‡fdd„¡d|_| |j¡dS)NrÚlinesÚlinezSqueezed text (ú z).z#FFFFC0z#FFFFE0)ÚtextZ backgroundZactivebackgroundz5Double-click to expand, right-click for more options.r)Z hover_delayzz z csˆt|ƒt|ƒt|ƒ…S)N)Úint)ÚoffsetÚlength)rrrÚzóz*ExpandingButton.__init__..)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) Úselfrrr r!r"rZline_pluralityZ button_textZbutton_tooltip_textr)rrr(_s*     zExpandingButton.__init__csLd|j ¡‰|jdkpDt|jƒdkpDt‡fdd„t d|j¡Dƒƒ|_dS)Né2ièiPÃc3s |]}t| d¡ƒˆkVqdS)rN)r Úgroup)Ú.0Z line_match)Údangerous_line_lenrrú …sz3ExpandingButton.set_is_dangerous..z[^\n]+) rZ winfo_widthr r rÚanyr r r+)r-r)r1rr,s   z ExpandingButton.set_is_dangerousNcCsŽ|jdkr| ¡|jrTtjdd ddddg¡|jt|jƒftj|j d}|sTdS|j   |j   |¡|j|j ¡|j  |¡|jj |¡dS) 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,Ú tkMessageBoxZ askokcancelÚjoinr r rZCANCELrr%ÚinsertÚindexrÚdeleter!ÚexpandingbuttonsÚremove)r-ÚeventZconfirmrrrr)Šs$   zExpandingButton.expandcCs| ¡| |j¡dS)N)Zclipboard_clearZclipboard_appendr)r-r@rrrÚcopy§szExpandingButton.copycCst|jd|jddddS)NzSqueezed Output ViewerFZnone)ZmodalÚwrap)rrr)r-r@rrrÚview¯s zExpandingButton.view))rArA)rCrCcCsf|j dd|j|jf¡tj|jdd}x&|jD]\}}|j|t||ƒdq2W|  |j |j ¡dS)Nr;z@%d,%dr)Ztearoff)ÚlabelZcommandr8) rZmark_setÚxÚyr&ZMenuÚ rmenu_specsZ add_commandÚgetattrZtk_popupZx_rootZy_root)r-r@ZrmenurDZ method_namerrrr*½s z"ExpandingButton.context_menu_event)N)N)N) Ú__name__Ú __module__Ú __qualname__r(r,r)rArCrGr*rrrrrTs     rc@s0eZdZedd„ƒZdd„Zdd„Zdd„Zd S) ÚSqueezercCstjdddddd|_dS)NÚmainZPyShellzauto-squeeze-min-linesrr.)Útyper6)rZ GetOptionÚauto_squeeze_min_lines)ÚclsrrrÚreloadÌszSqueezer.reloadcsd|ˆ_|jˆ_‰|jjˆ_dtˆ d¡ƒtˆ d¡ƒˆ_gˆ_d|j f‡‡fdd„ }||_ dS)NéZborderÚpadxrcs¨|dkr|||ƒSˆj}t|ƒ|kr.|||ƒSˆ |¡}||krJ|||ƒSt|||ˆƒ}ˆ dtj¡ˆjd|dddˆ d¡ˆ  ¡ˆ dtj ¡ˆj   |¡dS)NÚstdoutZiomarkéé)ÚwindowrSÚpady) rOr Ú count_linesrZ mark_gravityr&ZRIGHTÚ window_createZseeÚupdateZLEFTr>Úappend)rrÚwriterOr Úexpandingbutton)r-rrrÚmywriteós        z"Squeezer.__init__..mywrite) r"rr#r$r%rZcgetZwindow_width_deltar>r])r-r"r_r)r-rrr(Ôs    zSqueezer.__init__cCst||jjƒS)N)rr"Úwidth)r-rrrrrYs zSqueezer.count_linesc Cs|j tj¡}x$dD]}||krPqW|j ¡dS|j |tjd¡\}}|j ||¡}t|ƒdkrŽ|ddkrŽ|j d|¡}|dd…}|j   ||¡|  |¡}t ||||ƒ}|jj ||dd d t|jƒ} x2| dkr|j |j| d d |¡r| d 8} qÔW|j | |¡dS) N)rTÚstderrr8z+1créÿÿÿÿr z%s-1crUrV)rWrSrXrú>)rÚ tag_namesr&ZINSERTZbellZ tag_prevrangeÚgetr r<r%r=rYrrZr>Zcomparer;) r-r@rdZtag_namer Úendrr r^ÚirrrÚsqueeze_current_text_event s,          z#Squeezer.squeeze_current_text_eventN)rIrJrKÚ classmethodrQr(rYrhrrrrrLÆs ? rLÚ__main__)rMzidlelib.idle_test.test_squeezerrRF)Ú verbosityÚexit)r)r Ztkinterr&Ztkinter.messageboxZ messageboxr9Zidlelib.configrZidlelib.textviewrZidlelib.tooltiprZidlelibrrr'rrLrQrIZunittestrMrrrrÚs      8r