e"2SrSSKrSSKrSSKJr SSKJr SSKJr SSK J r SSK J r SSjr "S S \R5r"S S 5r\R#5 \S :XaSSKJr \"SSSS9 gg)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) messagebox)idleConf) view_text)Hovertip)macosxc^SnSnSnSn[R"SU5HanUR5U- nX7- nXW- nXS:XaXQ:a XES- U-- nUS- nSnOXS:XdeXRXR-- - nXQ:aUS- nUnUS- nMc U[U5U- - nUS:a XES- U-- nU$US-nU$)zCount 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. rz[\t\n]  )refinditerstartlen)s linewidthtabwidthpos linecountcurrent_columnmnumcharss 6/opt/imh/python3.13/lib/python3.13/idlelib/squeezer.pycount_lines_with_wrappingrsH CIN [[A &779s? " 6T>) q0Y>> NIN6T> !> .*CD DN)Q !) q;'@c!fsl"Nq(Y66  Q cL\rSrSrSrSrSrS SjrS SjrS Sjr S r S r S r g) ExpandingButtonTaClass 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^TUlX lX0lX@lUR=UlnUR =UlnUR RUlUS:waSOSnSUSUS3n[RRXUSSS 9 S n [X S S 9 URS UR5 [R "5(aURSUR"5 OURSUR"5 UR%U4Sj5 SUlUR)UR*5 g)Nr lineslinezSqueezed text ( z).z#FFFFC0z#FFFFE0)text backgroundactivebackgroundz5Double-click to expand, right-click for more options.P) hover_delayzz z cJ>T[U5[U5[U5-$N)int)offsetlengthrs r*ExpandingButton.__init__..zs1S[Vs6{1J#Kr)rtags numoflinessqueezereditwinr#perbottom base_texttkButton__init__rbindexpandrisAquaTkcontext_menu_eventselection_handle is_dangerous after_idleset_is_dangerous) selfrr/r0r1r2r#line_plurality button_textbutton_tooltip_texts ` rr8ExpandingButton.__init___s $ !)!1!11 w"<<' D ++$.!O' |1^4DBG  4K&/)  M D  ; %t{{3 ??   IIlD$;$; < IIlD$;$; <  K M! --.rc^SURR5-mURS:=(dS [UR5S:=(d4 [ U4Sj[ R"SUR555Ulg)N2iiPc3^># UH"n[URS55T:v M$ g7f)rN)rgroup).0 line_matchdangerous_line_lens r 3ExpandingButton.set_is_dangerous..s."@JJ$$Q'(,>>"@s*-z[^\n]+) r# winfo_widthr0rranyr rr>)rArLs @rr@ ExpandingButton.set_is_dangeroussm$))"7"7"99 OOd "  K%   "$++i"@  rNcURcUR5 UR(aj[R"SSR /SQ5UR [ UR54-[RURS9nU(dgURRU5nURRX0RUR5 URRU5 URR!X0RUR5 UR"R$R'U5 g)aexpand 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?)titlemessagedefaultparentbreak)r>r@r askokcanceljoinr0rrCANCELr#indexr5insertr/deleter2on_squeezed_expandr1expandingbuttonsremove)rAeventconfirmr[s rr:ExpandingButton.expands    $  ! ! #    ,,+ % oos466{3 4 #))yy "G % eVVTYY7 d# ''vvtyyA &&--d3rcZUR5 URUR5 g)z=copy event handler Copy the original text to the clipboard. N)clipboard_clearclipboard_appendrrAras rcopyExpandingButton.copys"  dff%rcF[URSURSSS9 g)zMview event handler View the original text in a separate text viewer window. zSqueezed Output ViewerFnone)modalwrapN)rr#rrgs rviewExpandingButton.views $))5tvvF ,r))rhrh)rnrncTURRSSURUR4-5 [R "URSS9nUR Hup4URU[X5S9 M URURUR5 g)Nr\z@%d,%dr)tearoff)labelcommandrW) r#mark_setxyr6Menu rmenu_specs add_commandgetattrtk_popupx_rooty_root)rArarmenurr method_names rr<"ExpandingButton.context_menu_events 8X%''0B%BC 1-"&"2"2 E   E743M  N#3 u||U\\2r)r5r2r>r0rr1r/r#r)) __name__ __module__ __qualname____firstlineno____doc__r8r@r:rhrnrxr<__static_attributes__rrrrTs- /@  4>&,K rrc:\rSrSrSr\S5rSrSrSr Sr g) SqueezerzReplace 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>[R"SSSSSS9Ulg)z!Load class variables from config.mainPyShellzauto-squeeze-min-linesr*rG)typerUN)r GetOptionauto_squeeze_min_lines)clss rreloadSqueezer.reloads$&.%7%7 I7& "rc0^^UTlUR=TlmURRTlS[ TR S55[ TR S55--Tl/TlSUR4UU4SjjnX!l g)a-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. borderpadxrc>US:waU"X5$TRn[U5U:aU"X5$TRU5nXC:aU"X5$[XUT5nTR S[ R 5 TRSUSSS9 TRS5 TR5 TR S[ R5 TRRU5 g)Nstdoutiomarkwindowrpady) rr count_linesr mark_gravityr6RIGHT window_createseeupdateLEFTr_append)rr/writerr0expandingbuttonrAr#s rmywrite"Squeezer.__init__..mywritesxQ~%&*%@%@ "1v..Q~%))!,J2Q~%.az4HO   h 1   x$%A  / HHX  KKM   h 0  ! ! ( ( 9rN) r2r#r3r4r5r*cgetwindow_width_deltar_r)rAr2rr#s` @rr8Squeezer.__init__s "<<' D!++#$  (# $  &! " ##  !#gmm : :< rc@[XRR5$)a2Count the number of lines in a given text. Before calculation, the tab width and line length of the text are fetched, so that up-to-date values are used. Lines are counted as if the string was wrapped so that lines are never over linewidth characters long. Tabs are considered tabwidth characters long. )rr2width)rArs rrSqueezer.count_liness)LL,>,>??rcURR[R5nSH nX!;dM O URR 5 gURR U[RS-5up4URR X45n[U5S:a,USS:Xa#URRSU-5nUSSnURRX45 URU5n[XRX`5nURRX7S S S 9 [UR5nUS:aqURRURUS - S U5(a?US -nUS:a4URRURUS - S U5(aM?URR!X5 g)zSqueeze the text block where the insertion cursor is. If the cursor is not in a squeezable block of text, give the user a small warning and do nothing. )rstderrrWz+1crr z%s-1cNrrrr >)r# tag_namesr6INSERTbell tag_prevrangegetrr[r5r]rrrr_comparer\) rArtag_namerendrr0ris rsqueeze_current_textSqueezer.squeeze_current_text"sII'' 2 ,H$- IINN YY,,Xryy57HI  IIMM% % q6A:!B%4-))//'C-0C#2A e)%%a( )!zH %&Q  0 %% &!e ))$*?*?!*D*-@@ FA!e ))$*?*?!*D*-@@ $$Q8r)r5r2r_r#rN) rrrrr classmethodrr8rrrrrrrrs,   = ~ @-rr__main__)rzidlelib.idle_test.test_squeezerrF) verbosityexit)r&)rr tkinterr6ridlelib.configridlelib.textviewridlelib.tooltipridlelibrrr7rrrrunittestrrrrrsr  #&$5pqbiiqhGGT  z *aeDr