+
     BigO                     X   R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt R tR tR tR	 t]P$                  R
 4       t ! R R4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      tR t]R8X  d"   ^ RIHt ]! R^RR7       ^ RIHt ]! ]4       R# R# )zLine numbering implementation for IDLE as an extension.
Includes BaseSideBar which can be extended for other sidebar based extensions
N)Font)idleConf)	Delegator)macosxc                `    V P                  V4      pV'       d   \        \        V4      4      # R# )z7Return the line number of an index in a Tk text widget.N)indexintfloat)textr   
text_indexs   && &/usr/lib/python3.14/idlelib/sidebar.py
get_linenor      s'    E"J%/3uZ !9T9    c                    \        V R4      # )z7Return the number of the last line in a Tk text widget.zend-1c)r   r
   s   &r   get_end_linenumberr      s    dH%%r   c                8    V P                  V R2V R2RRR7      # )z@Display height, in lines, of a logical line in a Tk text widget.z
 linestartz lineenddisplaylinesT)return_ints)count)r
   r   s   &&r   get_displaylinesr      s0    ::z*x($$  8 8r   c           
        V P                  4       pVR8X  d   V P                  4       pM&VR8X  d   V P                  4       pM\        RV 24      h\	        \        V P                  P                  VR,          V P                  R4      V P                  R4      .4      4      p\	        \        V P                  P                  VR,          V P                  R4      V P                  R4      .4      4      pW43# )z;Get the total padding of a Tk widget, including its border.packgridzUnsupported geometry manager: padxborderpady)	winfo_manager	pack_info	grid_info
ValueErrorsummaptkgetintcget)widgetmanagerinfor   r   s   &    r   get_widget_paddingr)       s     ""$G&!	F	!9'CDD s699##VFH&  D
 s699##VFH&  D
 :r   c              #      "   V P                  \        P                  R 7        Rx  V P                  \        P                  R 7       R#   T P                  \        P                  R 7       i ; i5i)stateN)	configurer#   NORMALDISABLEDr   s   &r   temp_enable_text_widgetr0   :   sC     NNN#*R[[)R[[)s   !A/A
 "A/
"A,,A/c                   r   a  ] tR t^Ct o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tRtV tR# )BaseSideBarz%A base class for sidebars using Text.c                    Wn         VP                  V n        VP                  V n        R V n        V P                  4       V n        V P                  4        V P                  4        V P                  4        R# FN)
editwin
text_frameparentr
   is_showninit_widgetsmain_widgetbind_eventsupdate_fontupdate_colors)selfr5   s   &&r   __init__BaseSideBar.__init__E   s[    ((LL	,,.r   c                    \         h)z<Initialize the sidebar's widgets, returning the main widget.NotImplementedErrorr>   s   &r   r9   BaseSideBar.init_widgetsS       !!r   c                    \         h);Update the sidebar text font, usually after config changes.rB   rD   s   &r   r<   BaseSideBar.update_fontW   rF   r   c                    \         h)=Update the sidebar text colors, usually after config changes.rB   rD   s   &r   r=   BaseSideBar.update_colors[   rF   r   c                    \         h)z,Layout the widget, always using grid layout.rB   rD   s   &r   r   BaseSideBar.grid_   rF   r   c                \    V P                   '       g   V P                  4        R V n         R# R# )TN)r8   r   rD   s   &r   show_sidebarBaseSideBar.show_sidebarc   s     }}}IIK DM r   c                p    V P                   '       d$   V P                  P                  4        R V n         R# R# r4   )r8   r:   grid_forgetrD   s   &r   hide_sidebarBaseSideBar.hide_sidebarh   s)    ===((*!DM r   c                    \         h)z8Hook for vertical scrolling for sub-classes to override.rB   r>   argskwargss   &*,r   yscroll_eventBaseSideBar.yscroll_eventm   rF   r   c                n    V P                   P                  P                  ! V!   V P                  ! V/ VB # )]Redirect vertical scrolling to the main editor text widget.

The scroll bar is also updated.
)r5   vbarsetrZ   rW   s   &*,r   redirect_yscroll_event"BaseSideBar.redirect_yscroll_eventq   s2    
 	t$!!42622r   c                :    V P                   P                  4        R# )z8Redirect focus-in events to the main editor text widget.break)r
   	focus_setr>   events   &&r   redirect_focusin_event"BaseSideBar.redirect_focusin_eventy   s    		r   c                    V P                   P                  4        V P                   P                  V^ VP                  R7       R# )z<Redirect mouse button events to the main editor text widget.xyrc   )r
   rd   event_generaterl   )r>   rf   
event_names   &&&r   redirect_mousebutton_event&BaseSideBar.redirect_mousebutton_event~   s2    				  qEGG <r   c                l    V P                   P                  R^ VP                  VP                  R7       R# )z7Redirect mouse wheel events to the editwin text widget.<MouseWheel>)rk   rl   deltarc   )r
   rm   rl   rs   re   s   &&r   redirect_mousewheel_event%BaseSideBar.redirect_mousewheel_event   s.    		  #$u{{ 	! 	Dr   c                  a a	a
aaa S P                   S P                  R &   S P                  P                  RS P                  4       S P                  P                  RS P
                  4       V 3R lpR FE  pRV R2RV R2RV R23 F  pV! W3R	7       K  	  R
V R2RV R23 F  pV! VRV R2R	7       K  	  KG  	  RoRoRo	V V3R lo
V
VV V3R lpS P                  P                  RV4       VV V3R lpS P                  P                  RV4       V
V3R lpS P                  P                  RV4       V	V
VV V3R loV	VV V3R lpS P                  P                  RV4       V	V 3R lpS P                  P                  RV4       R# )yscrollcommandz	<FocusIn>rr   c                    < \         P                  ! SP                  VR 7      pSP                  P	                  W4       R# ))rn   N)	functoolspartialro   r:   bind)rn   target_event_namehandlerr>   s   && r   bind_mouse_event1BaseSideBar.bind_events.<locals>.bind_mouse_event   s3    ''(G(G3DFG!!*6r   z<Button->z<ButtonRelease-z<Bz-Motion>)r|   z<Double-Button-z<Triple-Button-Nc                B  < \        SP                  RV  24      p\        SV.4      w  r#SP                  P                  RRR4       SP                  P	                  RV R2V^,            R24       SP                  P                  RW8X  d   TMV^,            R24       R# )z6Helper function for drag and selection event handlers.@0,sel1.0endz.0insertN)r   r
   sorted
tag_removetag_addmark_set)y_coordlinenoabr>   
start_lines   &   r   %drag_update_selection_and_insert_markFBaseSideBar.bind_events.<locals>.drag_update_selection_and_insert_mark   s    		S	?;F:v./DAII  u5IIes"X!A#bz:IIx,2K&VaZ!HKMr   c                    < \        \        SP                  P                  R V P                   24      4      4      oV P                  oS! V P                  4       R# )r   N)r   r	   r
   r   rl   )rf   r   last_yr>   r   s   &r   b1_mousedown_handler5BaseSideBar.bind_events.<locals>.b1_mousedown_handler   s@     U499??S	?#CDEJWWF1%'':r   z
<Button-1>c                 `   < R oR oSP                   P                  R^ V P                  R7       R # )N<ButtonRelease-1>rj   )r
   rm   rl   )rf   r   r>   r   s   &r   b1_mouseup_handler3BaseSideBar.bind_events.<locals>.b1_mouseup_handler   s-    
 JFII$$%8A$Ir   r   c                 P   < Sf   R # V P                   oS! V P                   4       R # N)rl   )rf   r   r   s   &r   b1_drag_handler0BaseSideBar.bind_events.<locals>.b1_drag_handler   s     ~WWF1%'':r   z<B1-Motion>c                   < Sp V f    SP                   P                  S4       RoR# V ^ 8  d-   SP                  P                  RV ,           R4       S! V 4       MiV SP                   P	                  4       8  dK   SP                  P                  ^V ,           SP                   P	                  4       ,
          R4       S! V 4       SP                   P                  ^2S4      oR# )z6Mimic Text auto-scrolling when dragging outside of it.Npixels)r:   after_cancelr
   yview_scrollwinfo_heightafter)rl   auto_scrolling_after_idr   r   r>   text_auto_scrolls    r   r   1BaseSideBar.bind_events.<locals>.text_auto_scroll   s     Ay  --.EF*.'Q		&&rAvx85a8T%%2244		&&q1ut/?/?/L/L/N'N'/15a8  &&r+;< $r   c                 d   < Sf+   V P                   oSP                  P                  ^ S4      oR # R # r   )rl   r:   r   )rf   r   r   r>   r   s   &r   b1_leave_handler1BaseSideBar.bind_events.<locals>.b1_leave_handler   s5     '.$$**1.>? ( /r   z
<B1-Leave>c                 N   < Se    SP                   P                  S4       R oR # R # r   )r:   r   )rf   r   r>   s   &r   b1_enter_handler1BaseSideBar.bind_events.<locals>.b1_enter_handler   s+     '2  --.EF*.' 3r   z
<B1-Enter>)            )r`   r
   r:   r{   rg   rt   )r>   r~   buttonrn   r   r   r   r   r   r   r   r   r   r   s   f        @@@@@r   r;   BaseSideBar.bind_events   s   &*&A&A		"# 	k4+F+FG 	nd.L.LM	7
 #F!)&3!0:!#F884!
 !J	! "1:!0:!
 !5=fXQ3GI! #" 
  #'	M	; 	; 	l,@A	J 	13EF	; 	m_=	= 	=&	@ 	@ 	l,<=	/ 	l,<=r   )r5   r8   r:   r7   r
   N)__name__
__module____qualname____firstlineno____doc__r?   r9   r<   r=   r   rP   rT   rZ   r`   rg   ro   rt   r;   __static_attributes____classdictcell____classdict__s   @r   r2   r2   C   sP     /""""!
"
"3
|> |>r   r2   c                   >   a  ] tR tRt o RtR tRR ltRR ltRtV t	R# )	EndLineDelegatori	  zuGenerate callbacks with the current end line number.

The provided callback is called after every insert and delete.
c                >    \         P                  ! V 4       Wn        R # r   )r   r?   changed_callback)r>   r   s   &&r   r?   EndLineDelegator.__init__  s    4  0r   Nc                    V P                   P                  WV4       V P                  \        V P                   4      4       R # r   )delegater   r   r   )r>   r   charstagss   &&&&r   r   EndLineDelegator.insert  s.    U400?@r   c                    V P                   P                  W4       V P                  \        V P                   4      4       R # r   )r   deleter   r   )r>   index1index2s   &&&r   r   EndLineDelegator.delete  s,    V,0?@r   )r   r   )
r   r   r   r   r   r?   r   r   r   r   r   s   @r   r   r   	  s!     1AA Ar   r   c                   Z   a a ] tR tRt oRtV 3R ltR tR tR tR t	R t
R	 tR
tVtV ;t# )LineNumbersi  z(Line numbers support for editor windows.c                   < \         SV `  V4       \        V P                  4      pV P                  P
                  P                  VV P                  P                  R 7       R# )r   N)superr?   r   update_sidebar_textr5   perinsertfilterafterundo)r>   r5   end_line_delegator	__class__s   && r   r?   LineNumbers.__init__  sQ    !-d.F.FG 	**+=151B1B 	+ 	Dr   c           
        \        V P                  4      w  r\        P                  ! V P                  ^\        P
                  ^V^ ^ R7      V n        V P                  P                  \        P                  R7       ^V n	        \        V P                  R,          4      V n        \        V P                  4      ;_uu_ 4        V P                  P                  RRR4       RRR4       V P                  P                  RRR	7       V P                  P                  R\        P                  R
7       \!        V P                  4      pV P#                  V4       V P                  #   + '       g   i     L; i)   )widthwrapr   r   borderwidthhighlightthicknessr+   r   r   1
linenumberNF)	takefocusexportselection)justify)r)   r
   r#   Textr7   NONEsidebar_textconfigr/   prev_endtype_sidebar_width_typer0   r   
tag_configRIGHTr   r   )r>   _padxr   r   s   &   r   r9   LineNumbers.init_widgets&  s   (3GGDKKqrww)*01aI 	  r{{ 3#'(9(9'(B#C $T%6%677$$XsLA 8  5% H$$\288$D +  %    87s   E!!E1	c                ^    V P                   P                  ^^ \        P                  R7       R# )r   rowcolumnstickyN)r   r   r#   NSEWrD   s   &r   r   LineNumbers.grid9  s!    1Qrww?r   c                f    \         P                  ! V P                  R R4      pWP                  R&   R# )mainEditorWindowfontN)r   GetFontr
   r   )r>   r   s   & r   r<   LineNumbers.update_font<  s(    		6>B$(&!r   c                    \         P                  ! \         P                  ! 4       R4      pVR,          pVR,          pV P                  P	                  W#W#VR7       R# )rK   r   
foreground
background)fgbgselectforegroundselectbackgroundinactiveselectbackgroundN)r   GetHighlightCurrentThemer   r   )r>   colorsr   r   s   &   r   r=   LineNumbers.update_colors@  sS    &&x'<'<'>ML)
L)
  '%/ 	! 	
r   c                   WP                   8X  d   R# \        \        V4      4      \        \        V P                   4      4      ,
          pV'       dL   \        \	        V P
                  R,          4      4      pW2,           pV P                  V4      V P
                  R&   \        V P
                  4      ;_uu_ 4        WP                   8  dv   RP                  \        P                  ! R.\        \        \        V P                   ^,           V^,           4      4      4      4      pV P
                  P                  RVR4       M&V P
                  P                  V^,            R2R4       RRR4       Wn         R#   + '       g   i     L; i)z
Perform the following action:
Each line sidebar_text contains the linenumber for that line
Synchronize with editwin.text so that both sidebar_text and
editwin.text contain the same number of linesNr   
 zend -1cr   z.0 -1c)r   lenstrr   r	   r   r   r0   join	itertoolschainr"   ranger   r   )r>   r   width_difference	cur_width	new_widthnew_texts   &&    r   r   LineNumbers.update_sidebar_textK  s    --s3x=3s4==/A+BBE$"3"3G"<=>I!4I)-)A)A))LDg&$T%6%677]]"99Y__DU4==1#4cAg>?&  !!((7X|L!!((CE7&)99E 8  87s   :B,E66F	c                J    V P                   P                  V^ ,          4       R# )    rc   )r   yview_movetorW   s   &*,r   rZ   LineNumbers.yscroll_eventf  s    &&tAw/r   )r   r   r   )r   r   r   r   r   r?   r9   r   r<   r=   r   rZ   r   r   __classcell__r   r   s   @@r   r   r     s2     2D!&@)	
6 r   r   c                   :   a  ] tR tRt o R tRR ltRR ltRtV tR# ) WrappedLineHeightChangeDelegatorik  c                >    \         P                  ! V 4       Wn        R# )z
callback - Callable, will be called when an insert, delete or replace
           action on the text widget may require updating the shell
           sidebar.
N)r   r?   callback)r>   r  s   &&r   r?   )WrappedLineHeightChangeDelegator.__init__l  s     	4  r   Nc                    R V9  pV'       d   \        W4      pV P                  P                  WV4       V'       d   \        W4      pVX8X  d   R# V P                  4        R# )r  N)r   r   r   r  )r>   r   r   r   is_single_linebefore_displaylinesafter_displayliness   &&&&   r   r   'WrappedLineHeightChangeDelegator.insertu  sQ    U*"24"?U40!1$!>!%88r   c                   Vf
   VR,           p\        W4      \        W4      8H  pV'       d   \        W4      pV P                  P                  W4       V'       d   \        W4      pVX8X  d   R # V P	                  4        R # )Nz+1c)r   r   r   r   r  )r>   r   r   r!  r"  r#  s   &&&   r   r   'WrappedLineHeightChangeDelegator.delete  sg    >e^F#D1Z5MM"24"@V,!1$!?!%88r   )r  r   )	r   r   r   r   r?   r   r   r   r   r   s   @r   r  r  k  s     ! r   r  c                   r   a a ] tR tRt oRtV 3R ltR tV 3R ltR tR t	R t
R	 tR
 tR tR tRtVtV ;t# )ShellSidebari  z0Sidebar for the PyShell window, for prompts etc.c                  < R V n         / V n        \        SV `  V4       \	        V P
                  4      pV P                  P                  P                  pVP                  V P                  Jd=   VP                  V P                  P                  P                  Jd   VP                  pK<  V P                  P                  P                  W#R7       RV n        R # )Nr   T)canvasline_promptsr   r?   r  change_callbackr5   r   topr   r
   bottomr   r8   )r>   r5   change_delegatordr   s   &&  r   r?   ShellSidebar.__init__  s    ! -T-A-AB 	 LL  ::TYY&**DLL$4$4$;$;;JJ**+;*Er   c                    \         P                  ! V P                  ^^ ^ RR7      V n        V P	                  4        V P                  4        V P                  # )   F)r   r   r   r   )r#   Canvasr7   r*  update_sidebarr   rD   s   &r   r9   ShellSidebar.init_widgets  sC    ii2,-!*/1 			{{r   c                   < \         SV `  4        V P                  P                  \        P
                  ! 4       '       d   R MRV P                  4       R# )z
<Button-2>z
<Button-3>N)r   r;   r:   r{   r   isAquaTkcontext_menu_event)r>   r   s   &r   r;   ShellSidebar.bind_events  s<    "OO--L<##	
r   c                ~  a  \         P                  ! S P                  ^ R7      p\        S P                  P                  RR4      4      pV 3R lpTP                  RV! R4      V'       d   RMRR	7       TP                  R
V! R4      V'       d   RMRR	7       VP                  VP                  VP                  4       R# )r  )tearoffr   r   c                    <a  V V3R  l# )c                  :   < SP                   P                  S 4      # r   )r
   rm   	eventnamer>   s   r   <lambda>@ShellSidebar.context_menu_event.<locals>.mkcmd.<locals>.<lambda>  s    49933I>r    r?  s   fr   mkcmd.ShellSidebar.context_menu_event.<locals>.mkcmd  s	    >>r   Copyz<<copy>>normaldisabled)labelcommandr,   zCopy with promptsz<<copy-with-prompts>>rc   )
r#   Menur:   boolr
   tag_nextrangeadd_commandtk_popupx_rooty_root)r>   rf   rmenuhas_selectionrD  s   f&   r   r9  ShellSidebar.context_menu_event  s    ((!4TYY44UEBC	?"'
"3,9z 	 	K 	 3"'(?"@,9z 	 	K 	u||U\\2r   c                b    V P                   P                  ^^ \        P                  ^^ R7       R# )r   )r   r   r   r   r   N)r*  r   r#   r   rD   s   &r   r   ShellSidebar.grid  s#    QqqqIr   c                N    V P                   '       d   V P                  4        R # R # r   )r8   r5  rD   s   &r   r,  ShellSidebar.change_callback  s    ===! r   c           	     v   V P                   pVP                  pV P                  p/ ;q@n        VP	                  \
        P                  4       VP                  R 4      pVP                  R^4      ^,          R8w  d   VP                  V R24      pVP                  V4      ;pe   V^,          pV! V R24      pRV9   d   RM
RV9   d   R	MRp	V	'       dP   VP                  ^V\
        P                  V	V P                  V P                  ^ ,          R
7       \        W4      p
WV
&   VP                  V R24      pK  R# )z@0,0.0z+1line linestartNz linestart -1cconsolez>>>stdinz...)anchorr
   r   fillz+1line)r
   	tag_namesr*  r+  r   r#   ALLr   split	dlineinfocreate_textNWr   r  r   )r>   r
   text_tagnamesr*  r+  r   lineinforl   prev_newline_tagnamespromptr   s   &          r   r5  ShellSidebar.update_sidebar  s#   yy+--(bff

6";;sAq!S(JJ%(89:E>>%00x=A$1UG>2J$K!"&;; $99 
 ""1aF(,		A # H#D0'-V$JJ%/0E >r   c                &    V P                  4        R# )r]   rc   )r,  rW   s   &*,r   rZ   ShellSidebar.yscroll_event  s    
 	r   c                $  a \         P                  ! V P                  RR4      p\        V P                  VR7      o\	        V3R lR 4       4      pV P
                  P                  V^,          ^,           R7       Wn        V P                  4        R# )rH   r   r   )r   c              3   F   <"   T F  pSP                  V4      x  K  	  R # 5ir   )measure).0chartk_fonts   & r   	<genexpr>+ShellSidebar.update_font.<locals>.<genexpr>  s     F:4..:s   !)r   N)r   rZ  )	r   r   r
   r   maxr*  r-   r   r,  )r>   r   
char_widthrr  s   &  @r   r<   ShellSidebar.update_font  sj    		6>Btyyt,F:FF
JNQ$67	r   c                :   \         P                  ! \         P                  ! 4       R4      p\         P                  ! \         P                  ! 4       R4      pVR,          pVR,          pW43V n        V P                  P                  VR7       V P                  4        R# )rK   r   r\  r   r   )r   N)r   r  r  r  r*  r-   r,  )r>   linenumbers_colorsprompt_colorsr   r   s   &    r   r=   ShellSidebar.update_colors  sx    %2283H3H3JLY --h.C.C.EyQ"<0
'5
!.4r   )r*  r  r   r8   r+  )r   r   r   r   r   r?   r9   r;   r9  r   r,  r5  rZ   r<   r=   r   r   r  r  s   @@r   r(  r(    s@     :$
J"14 r   r(  c           
         ^ RI Hp \        P                  ! V 4      p\        P                  ! V4      pVP                  \        P                  \        P                  RR7       VP                  ^^R7       VP                  ^^R7       \        P                  ! VRR4      p\        P                  ! V^P^\        P                  VR7      pVP                  ^^\        P                  R7       V! V4      p\        P                   ! V4      Vn        \%        V4      pVP'                  4        VP)                  R	R
P+                  R \-        ^^e4       4       4      4       R# )r  )Dummy_editwinT)sider_  expand)weightr   r   )r   heightr   r   r   r   r  c              3   4   "   T F  pR V,          x  K  	  R# 5i)r   NrC  )rp  is   & r   rs  ,_sidebar_number_scrolling.<locals>.<genexpr>  s      >1Qs   N)idlelib.idle_test.test_sidebarr}  r#   ToplevelFramer   LEFTBOTHrowconfigurecolumnconfigurer   r   r   r   r   r   	Scrollbarr^   r   rP   r   r  r  )r7   r}  r-  r6   r   r
   r5   linenumberss   &       r   _sidebar_number_scrollingr    s    <
++f
C#JOOrwwtO<Aa(q+C8D77:RtLDII!AbggI.D!G<<
+GLg&KKKtyy >a >>?r   __main__)r   zidlelib.idle_test.test_sidebarF)	verbosityexit)run)r   
contextlibry   r  tkinterr#   tkinter.fontr   idlelib.configr   idlelib.delegatorr   idlelibr   r   r   r   r)   contextmanagerr0   r2   r   r   r  r(  r  r   unittestr   idlelib.idle_test.htestr  rC  r   r   <module>r     s         # ' :&
84 * *C> C>LAy A$M+ M`&y &Rm; m`@, z	)QUC+!" r   