a  ze2@sddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddd Z Gd d d ej ZGd d d ZeedkrddlmZedddddS)N) messagebox)idleConf) view_text)Hovertip)macosxPcCsd}d}d}d}td|D]~}||}||7}||7}||dkrn||kr`||d|7}|d7}d}n$||||7}||kr|d7}|}|d7}q|t||7}|dkr||d|7}n|d8}|S)Nrz[\t\n] )refinditerstartlen)sZ linewidthZtabwidthposZ linecountZcurrent_columnmnumcharsrD/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/squeezer.pycount_lines_with_wrappings.   rc@sFeZdZddZddZdddZddd Zdd d Zd Zd dZ dS)ExpandingButtonc s|_||_||_||_|j|_}|j|_}|jj|_|dkrFdnd}d|d|d}t j j |||ddd d } t || d d | d |jtr| d|jn| d|j|fddd|_||jdS)Nr lineslinezSqueezed text ( z).z#FFFFC0z#FFFFE0)textZ backgroundZactivebackgroundz5Double-click to expand, right-click for more options.r)Z hover_delayzz z cst|t|t|SN)int)offsetlengthrrrzz*ExpandingButton.__init__..)rtags numoflinessqueezereditwinrperbottom base_texttkButton__init__rbindexpandrZisAquaTkcontext_menu_eventZselection_handle is_dangerousZ after_idleset_is_dangerous) selfrr"r#r$r%rZline_pluralityZ button_textZbutton_tooltip_textrrrr+_s0     zExpandingButton.__init__csLd|j|jdkpDt|jdkpDtfddtd|jD|_dS)N2iiPc3s |]}t|dkVqdS)rN)rgroup).0Z line_matchZdangerous_line_lenrr sz3ExpandingButton.set_is_dangerous..z[^\n]+) rZ winfo_widthr#rranyr r r/)r1rr5rr0s    z ExpandingButton.set_is_dangerousNcCs|jdur||jrPtjddgd|jt|jftj|j d}|sPdS|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?)titlemessagedefaultparentbreak)r/r0rZ askokcanceljoinr#rrZCANCELrr(insertindexr"deleter$expandingbuttonsremove)r1eventZconfirmrrrr-s    zExpandingButton.expandcCs|||jdSr)Zclipboard_clearZclipboard_appendrr1rCrrrcopyszExpandingButton.copycCst|jd|jddddS)NzSqueezed Output ViewerFZnone)Zmodalwrap)rrrrDrrrviews zExpandingButton.view))rErE)rGrGcCsb|jdd|j|jftj|jdd}|jD]\}}|j|t||dq0| |j |j dS)Nr>z@%d,%dr)Ztearoff)labelZcommandr<) rZmark_setxyr)ZMenu rmenu_specsZ add_commandgetattrZtk_popupZx_rootZy_root)r1rCZrmenurHZ method_namerrrr.s z"ExpandingButton.context_menu_event)N)N)N) __name__ __module__ __qualname__r+r0r-rErGrKr.rrrrrTs     rc@s0eZdZeddZddZddZddZd S) SqueezercCstjdddddd|_dS)NmainZPyShellzauto-squeeze-min-linesrr2)typer:)rZ GetOptionauto_squeeze_min_lines)clsrrrreloadszSqueezer.reloadcsd|_|j_|jj_dtdtd_g_d|j ffdd }||_ dS)NZborderpadxrcs|dkr|||Sj}t||kr.|||S|}||krJ|||St|||}dtjjd|dddd dtj j |dS)NstdoutZiomarkZwindowrWZpady) rSr count_linesrZ mark_gravityr)ZRIGHT window_createZseeupdateZLEFTrAappend)rr"writerSr#expandingbuttonr1rrrmywrites"      z"Squeezer.__init__..mywrite) r%rr&r'r(rZcgetZwindow_width_deltarAr`)r1r%rcrrbrr+s     zSqueezer.__init__cCst||jjSr)rr%width)r1rrrrr\s zSqueezer.count_linesc Cs|jtj}dD]}||vrq2q|jdS|j|tjd\}}|j||}t|dkr|ddkr|jd|}|dd}|j ||| |}t ||||}|jj ||dd d t|j} | dkr|j|j| d d |r| d 8} q|j| |dS) N)rXstderrr<z+1crr z%s-1crYrZr[r >)r tag_namesr)ZINSERTZbellZ tag_prevrangegetrr?r(r@r\rr]rAZcomparer>) r1rCrhZtag_namer endrr#rairrrsqueeze_current_text_event s0       z#Squeezer.squeeze_current_text_eventN)rMrNrO classmethodrUr+r\rlrrrrrPs  ? rP__main__)rQzidlelib.idle_test.test_squeezerrVF) verbosityexit)r)r tkinterr)rZidlelib.configrZidlelib.textviewrZidlelib.tooltiprZidlelibrrr*rrPrUrMZunittestrQrrrrs      8r