3 2a3@sddlZddlZddlmZddljZddlm Z ddl m Z ddl m Z ddlmZdd d ZGd d d ejZGd ddZejedkrddlmZedddddS)N)Font)idleConf) view_text)Hovertip)macosxPc Csd}d}d}xtjd|D]}|j|}||7}||7}||dkrT|d7}d}n$||||7}||krx|d7}|}|d7}|dkrt|d|\}} ||7}| d}qW|t||7}|dkr||d|7}n|d8}|S)Nrz[\t\n] )refinditerstartdivmodlen) s linewidthtabwidthposZ linecountZcurrent_columnmnumcharslinescolumnr-/opt/alt/python36/lib64/python3.6/squeezer.pycount_lines_with_wrappings0   rc@sFeZdZddZddZdddZddd Zdd d ZdZddZ dS)ExpandingButtonc s|_||_||_||_|j|_}|j|_}|jj|_d|j}t j j |||dddd}t ||dd|j d|jtjr|j d |jn|j d |j|jfd d d|_|j|jdS) NzSqueezed text (%d lines).z#FFFFC0z#FFFFE0)textZ backgroundZactivebackgroundz5Double-click to expand, right-click for more options.r)Z hover_delayzz z cst|t|t|S)N)int)offsetZlength)rrr}sz*ExpandingButton.__init__..)rtags numoflinessqueezereditwinrperbottom base_texttkButton__init__rZbindexpandrZisAquaTkcontext_menu_eventZselection_handle is_dangerousZ after_idleset_is_dangerous) selfrr r!r"r#rZ button_textZbutton_tooltip_textr)rrr)as(      zExpandingButton.__init__csLd|jj|jdkpDt|jdkpDtfddtjd|jD|_dS)N2iiPc3s |]}t|jdkVqdS)rN)rgroup).0Z line_match)dangerous_line_lenrr sz3ExpandingButton.set_is_dangerous..z[^\n]+) r winfo_widthr!rranyr r r,)r.r)r2rr-s   z ExpandingButton.set_is_dangerousNcCs|jdkr|j|jrTtjddjddddg|jt|jftj|j d}|sTdS|j j |j j ||j|j |j j||jjj|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!rrZCANCELrr&insertindexr deleter"expandingbuttonsremove)r.eventZconfirmrrrr*s$   zExpandingButton.expandcCs|j|j|jdS)N)Zclipboard_clearZclipboard_appendr)r.rBrrrcopyszExpandingButton.copycCst|jd|jddddS)NzSqueezed Output ViewerFZnone)Zmodalwrap)rrr)r.rBrrrviews zExpandingButton.viewrCrEcCsf|jjdd|j|jftj|jdd}x&|jD]\}}|j|t||dq2W|j |j |j dS)Nr=z@%d,%dr)Ztearoff)labelZcommandr:) rZmark_setxyr'ZMenu rmenu_specsZ add_commandgetattrZtk_popupZx_rootZy_root)r.rBZrmenurFZ method_namerrrr+s z"ExpandingButton.context_menu_event)N)N)NrCrCrErE)rKrL) __name__ __module__ __qualname__r)r-r*rCrErIr+rrrrrVs !   rc@s0eZdZeddZddZddZddZd S) SqueezercCstjdddddd|_dS)NmainPyShellzauto-squeeze-min-linesrr/)typer8)rZ GetOptionauto_squeeze_min_lines)clsrrrreloadszSqueezer.reloadcsX|_|j_|jj_g_ddlm}t||rTf|j ffdd }||_ dS)Nr)rRcs|dkr|||Sj|}|jkr0|||St|||}jdtjjd|dddjdjjdtj j j |dS)NstdoutZiomark)windowpadxpady) count_linesrTrZ mark_gravityr'ZRIGHT window_createZseeupdateZLEFTr@append)rr writer!expandingbutton)r.rrrmywrites      z"Squeezer.__init__..mywrite) r#rr$r%r&r@Zidlelib.pyshellrR isinstancera)r.r#rRrcr)r.rrr)s     zSqueezer.__init__cshjj}jjj}|dtfddd D8}tjjjjjdd}||jd}t|||S) Ncsg|]}tjjj|qSr)rr#rcget)r1opt)r.rr sz(Squeezer.count_lines..borderr[font)name0)rir[) r#Zget_tk_tabwidthrr4sumrrfZmeasurer)r.rrrrjr)r.rr] s  zSqueezer.count_linesc Cs|jjtj}x$d D]}||krPqW|jjdS|jj|tjd\}}|jj||}t|dkr|ddkr|jjd|}|dd}|j j |||j |}t ||||}|jj ||d d d t|j} x0| dko|jj|j| dd |r| d8} qW|jj| |dS)NrWstderrr:z+1crr r z%s-1crXrY)rZr[r\>)rWrnrp)r tag_namesr'ZINSERTZbellZ tag_prevrangegetrr>r&r?r]rr^r@Zcomparer=) r.rBrqZtag_namer endrr!rbirrrsqueeze_current_text_event*s,          z#Squeezer.squeeze_current_text_eventN)rMrNrO classmethodrVr)r]rurrrrrPs 4rP__main__)rQzidlelib.idle_test.test_squeezerreF) verbosityexit)rr)r Ztkinterr'Z tkinter.fontrZtkinter.messageboxZ messageboxr;Zidlelib.configrZidlelib.textviewrZidlelib.tooltiprZidlelibrrr(rrPrVrMZunittestrQrrrrs       9s