B YI~d(2@sddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dddZGd d d ejZGd d d Zeed krddlmZedddddS)N)idleConf) view_text)Hovertip)macosxPcCsd}d}d}d}xtd|D]~}||}||7}||7}||dkrp||krb||d|7}|d7}d}n$||||7}||kr|d7}|}|d7}qW|t||7}|dkr||d|7}n|d8}|S)Nrz[\t\n] )refinditerstartlen)sZ linewidthZtabwidthposZ linecountZcurrent_columnmnumcharsr5/opt/alt/python37/lib64/python3.7/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)NrlineslinezSqueezed text ( z).z#FFFFC0z#FFFFE0)textZ backgroundZactivebackgroundz5Double-click to expand, right-click for more options.r)Z hover_delayzz z cst|t|t|S)N)int)offsetlength)rrrzz*ExpandingButton.__init__..)rtags numoflinessqueezereditwinrperbottom base_texttkButton__init__rZbindexpandrZisAquaTkcontext_menu_eventZselection_handle is_dangerousZ after_idleset_is_dangerous) selfrrr r!r"rZline_pluralityZ button_textZbutton_tooltip_textr)rrr(_s*     zExpandingButton.__init__csLd|j|jdkpDt|jdkpDtfddtd|jD|_dS)N2iiPc3s |]}t|dkVqdS)rN)r group).0Z line_match)dangerous_line_lenrr sz3ExpandingButton.set_is_dangerous..z[^\n]+) rZ winfo_widthr r ranyr r r+)r-r)r1rr,s   z ExpandingButton.set_is_dangerousNcCs|jdkr||jrTtjddddddg|jt|jftj|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?)titlemessagedefaultparentbreak)r+r, tkMessageBoxZ askokcanceljoinr r rZCANCELrr%insertindexrdeleter!expandingbuttonsremove)r-eventZconfirmrrrr)s$   zExpandingButton.expandcCs|||jdS)N)Zclipboard_clearZclipboard_appendr)r-r@rrrcopyszExpandingButton.copycCst|jd|jddddS)NzSqueezed Output ViewerFZnone)Zmodalwrap)rrr)r-r@rrrviews zExpandingButton.view))rArA)rCrCcCsf|jdd|j|jftj|jdd}x&|jD]\}}|j|t||dq2W| |j |j dS)Nr;z@%d,%dr)Ztearoff)labelZcommandr8) rZmark_setxyr&ZMenu rmenu_specsZ add_commandgetattrZtk_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@s0eZdZeddZddZddZddZd S) SqueezercCstjdddddd|_dS)NmainZPyShellzauto-squeeze-min-linesrr.)typer6)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)NstdoutZiomark)windowrSpady) rOr count_linesrZ mark_gravityr&ZRIGHT window_createZseeupdateZLEFTr>append)rrwriterOr expandingbutton)r-rrrmywrites        z"Squeezer.__init__..mywrite) r"rr#r$r%rZcgetZwindow_width_deltar>r])r-r"r_r)r-rrr(s    zSqueezer.__init__cCst||jjS)N)rr"width)r-rrrrrYs zSqueezer.count_linesc Cs|jtj}x$dD]}||krPqW|jdS|j|tjd\}}|j||}t|dkr|ddkr|jd|}|dd}|j ||| |}t ||||}|jj ||dd d t|j} x2| dkr|j|j| d d |r| d 8} qW|j| |dS) N)rTstderrr8z+1crr z%s-1crUrV)rWrSrXr>)r tag_namesr&ZINSERTZbellZ tag_prevrangegetr r<r%r=rYrrZr>Zcomparer;) r-r@rdZtag_namer endrr r^irrrsqueeze_current_text_event s,          z#Squeezer.squeeze_current_text_eventN)rIrJrK classmethodrQr(rYrhrrrrrLs ? rL__main__)rMzidlelib.idle_test.test_squeezerrRF) verbosityexit)r)r Ztkinterr&Ztkinter.messageboxZ messageboxr9Zidlelib.configrZidlelib.textviewrZidlelib.tooltiprZidlelibrrr'rrLrQrIZunittestrMrrrrs      8r