python (3.12.0)

(root)/
lib/
python3.12/
idlelib/
__pycache__/
sidebar.cpython-312.pyc

̑eOPdZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
dZdZd	Zd
Zej$dZGdd
ZGddeZGddeZGddeZGddeZdZedk(r ddlmZedddddlmZeeyy)zLine numbering implementation for IDLE as an extension.
Includes BaseSideBar which can be extended for other sidebar based extensions
N)Font)idleConf)	Delegator)macosxcT|j|}|rtt|SdS)z7Return the line number of an index in a Tk text widget.N)indexintfloat)textr
text_indexs   C/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/idlelib/sidebar.py
get_linenors'E"J%/3uZ !9T9ct|dS)z7Return the number of the last line in a Tk text widget.zend-1c)rrs r
get_end_linenumberrsdH%%rcF|j|d|dd}|r|dSdS)z@Display height, in lines, of a logical line in a Tk text widget.z
 linestartz lineenddisplaylinesr)count)rrress   r
get_displaylinesrs9
**wj)wh'#%C3q6arc
|j}|dk(r|j}n$|dk(r|j}ntd|t	t|jj|d|jd|jdg}t	t|jj|d|jd|jdg}||fS)z;Get the total padding of a Tk widget, including its border.packgridzUnsupported geometry manager: padxborderpady)	
winfo_manager	pack_info	grid_info
ValueErrorsummaptkgetintcget)widgetmanagerinforrs     r
get_widget_paddingr*!s""$G&!	F	!9'CDDs699##VFH&D
s699##VFH&D
:rc#K|jtj	d|jtjy#|jtjwxYww)Nstate)	configurer$NORMALDISABLEDrs r
temp_enable_text_widgetr1;sDNNN#*
R[[)R[[)s!A.A	!A.	"A++A.c^eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZy)BaseSideBarz%A base class for sidebars using Text.c||_|j|_|j|_d|_|j|_|j|j|jyNF)
editwin
text_frameparentris_showninit_widgetsmain_widgetbind_eventsupdate_font
update_colors)selfr6s  r
__init__zBaseSideBar.__init__Fs]((LL	
,,.rct)z<Initialize the sidebar's widgets, returning the main widget.NotImplementedErrorr?s r
r:zBaseSideBar.init_widgetsT!!rct);Update the sidebar text font, usually after config changes.rBrDs r
r=zBaseSideBar.update_fontXrErct)=Update the sidebar text colors, usually after config changes.rBrDs r
r>zBaseSideBar.update_colors\rErct)z,Layout the widget, always using grid layout.rBrDs r
rzBaseSideBar.grid`rErcL|js|jd|_yy)NT)r9rrDs r
show_sidebarzBaseSideBar.show_sidebards}}IIK DMrc`|jr"|jjd|_yyr5)r9r;grid_forgetrDs r
hide_sidebarzBaseSideBar.hide_sidebaris'==((*!DMrct)z8Hook for vertical scrolling for sub-classes to override.rBr?argskwargss   r

yscroll_eventzBaseSideBar.yscroll_eventnrErcl|jjj||j|i|S)mRedirect vertical scrolling to the main editor text widget.

        The scroll bar is also updated.
        )r6vbarsetrTrQs   r
redirect_yscroll_eventz"BaseSideBar.redirect_yscroll_eventrs6
	t$!t!!42622rc8|jjy)z8Redirect focus-in events to the main editor text widget.break)r	focus_setr?events  r
redirect_focusin_eventz"BaseSideBar.redirect_focusin_eventzs		rc|jj|jj|d|jy)z<Redirect mouse button events to the main editor text widget.rxyr[)rr\event_generaterc)r?r^
event_names   r
redirect_mousebutton_eventz&BaseSideBar.redirect_mousebutton_events2				  qEGG <rcj|jjdd|j|jy)z7Redirect mouse wheel events to the editwin text widget.<MouseWheel>r)rbrcdeltar[)rrdrcrir]s  r
redirect_mousewheel_eventz%BaseSideBar.redirect_mousewheel_events.		  #$u{{	!	Drc	

jjd<jjdjjjdj
fd}dD]A}d|dd|dd	|d
fD]}|||d|dd
|dfD]}||d|dCddd	fd

fd}jjd|fd}jjd|
fd}jjd|	

fd
	
fd}jjd|	fd}jjd|y)Nyscrollcommandz	<FocusIn>rhctjj|}jj	||y)N)re)	functoolspartialrfr;bind)retarget_event_namehandlerr?s   r
bind_mouse_eventz1BaseSideBar.bind_events.<locals>.bind_mouse_events5''(G(G3DFG!!*g6r)z<Button->z<ButtonRelease-z<Bz-Motion>)rqz<Double-Button-z<Triple-Button-c0tjd|}t|g\}}jjdddjj	d|d|dzdjjd||k(r|n|dzdy)	z6Helper function for drag and selection event handlers.@0,sel1.0endz.0insertN)rrsorted
tag_removetag_addmark_set)y_coordlinenoabr?
start_lines    r
%drag_update_selection_and_insert_markzFBaseSideBar.bind_events.<locals>.drag_update_selection_and_insert_marks		S	?;F:v./DAqII  u5IIes"X!A#bz:IIx,2aK&VaZ!HK
Mrcttjjd|j|j|jy)Nrz)r	r
rrrc)r^rlast_yr?rs r
b1_mousedown_handlerz5BaseSideBar.bind_events.<locals>.b1_mousedown_handlers@U499??S	?#CDEJWWF1%'':rz
<Button-1>c^ddjjdd|jy)N<ButtonRelease-1>rra)rrdrc)r^rr?rs r
b1_mouseup_handlerz3BaseSideBar.bind_events.<locals>.b1_mouseup_handlers-
JFII$$%8A$IrrcHy|j|jyN)rc)r^rrs r
b1_drag_handlerz0BaseSideBar.bind_events.<locals>.b1_drag_handlers ~WWF1%'':rz<B1-Motion>c}|jjdy|dkr(jjd|zd|n_|jj	kDrBjjd|zjj	z
d|jjdy)z6Mimic Text auto-scrolling when dragging outside of it.Nrpixelsr~2)r;after_cancelryview_scrollwinfo_heightafter)rcauto_scrolling_after_idrrr?text_auto_scrolls r
rz1BaseSideBar.bind_events.<locals>.text_auto_scrollsAy  --.EF*.'Q		&&rAvx85a8T%%2244		&&q1ut/?/?/L/L/N'N'/15a8  &&r+;<
$rc\)|jjjdyy)Nr)rcr;r)r^rrr?rs r
b1_leave_handlerz1BaseSideBar.bind_events.<locals>.b1_leave_handlers5'.$$**1.>?(/rz
<B1-Leave>cFjjdyyr)r;r)r^rr?s r
b1_enter_handlerz1BaseSideBar.bind_events.<locals>.b1_enter_handlers+'2  --.EF*.'3rz
<B1-Enter>)rYrr;rpr_rj)r?rsbuttonrerrrrrrrrrrs`        @@@@@r
r<zBaseSideBar.bind_eventss&*&A&A		"#	
k4+F+FG	
nd.L.LM	7
#
	IF!)&3!0:!#F884!
K
!zJ	
K"1:!0:!
I
!5=fXQ3GI
I
	I"
#'	M	;	
l,@A	J	
13EF	;	
m_=	=	=&	@	
l,<=	/	
l,<=rN)__name__
__module____qualname____doc__r@r:r=r>rrLrOrTrYr_rfrjr<rr
r3r3DsG/""""!
"
"3
|>rr3c&eZdZdZdZddZddZy)EndLineDelegatorz}Generate callbacks with the current end line number.

    The provided callback is called after every insert and delete.
    c<tj|||_yr)rr@changed_callback)r?rs  r
r@zEndLineDelegator.__init__s4  0rNc|jj||||jt|jyr)delegaterrr)r?rcharstagss    r
rzEndLineDelegator.inserts0

UE400?@rc|jj|||jt|jyr)rdeleterr)r?index1index2s   r
rzEndLineDelegator.deletes.

VV,0?@rr)rrrrr@rrrrr
rr
s1AArrcFeZdZdZfdZdZdZdZdZdZ	dZ
xZS)	LineNumbersz(Line numbers support for editor windows.ct||t|j}|jj
j
||jjy)Nr)superr@rupdate_sidebar_textr6perinsertfilterafterundo)r?r6end_line_delegator	__class__s   r
r@zLineNumbers.__init__sQ
!-d.F.FG	
**+=151B1B	+	Drc	t|j\}}tj|jdtj
d|dd|_|jjtjd|_	t|jd|_t|j5|jjddd	ddd|jjd
d
|jjd	tjt!|j}|j#||jS#1swYxYw)
Nr~rtr)widthwraprrborderwidthhighlightthicknessr,rr1
linenumberF)	takefocusexportselection)justify)r*rr$Textr8NONEsidebar_textconfigr0prev_endtype_sidebar_width_typer1r
tag_configRIGHTrr)r?_padxrr}s    r
r:zLineNumbers.init_widgets's(3tGGDKKqrww)*01aI	
  r{{ 3
#'(9(9'(B#C 
$T%6%6
7	B$$XsLA	B  5% H$$\288$D +  %   	B	Bs5EEc\|jjddtjy)Nr~rrowcolumnsticky)rrr$NSEWrDs r
rzLineNumbers.grid:s!1Qrww?rcdtj|jdd}||jd<y)NmainEditorWindowfont)rGetFontrr)r?rs  r
r=zLineNumbers.update_font=s*		6>B$(&!rctjtjd}|d}|d}|jj	|||||y)rIr
foreground
background)fgbgselectforegroundselectbackgroundinactiveselectbackgroundN)rGetHighlightCurrentThemerr)r?colorsrrs    r
r>zLineNumbers.update_colorsAsW&&x'<'<'>ML)
L)
  j'*%/	!	
rc||jk(rytt|tt|jz
}|rDtt	|j
d}||z}|j
||j
d<t|j
5||jkDrldjtjdgttt|jdz|dz}|j
jd|dn"|j
j|dzddddd||_y#1swY||_yxYw)	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
r~zend -1crz.0 -1c)rlenstrr	r
rrr1join	itertoolschainr#rangerr)r?r}width_difference	cur_width	new_widthnew_texts      r
rzLineNumbers.update_sidebar_textLs-$--s3x=3s4==/A+BBE$"3"3G"<=>I!$44I)-)A)A))LDg&
$T%6%6
7	FT]]"99Y__DU4==1#4cAg>?&!!((7X|L!!((CE7&)99E	F
	F
s
BE

Ec@|jj|dy)Nrr[)ryview_movetorQs   r
rTzLineNumbers.yscroll_eventgs&&tAw/r)rrrrr@r:rr=r>rrT
__classcell__rs@r
rrs+2D!&@)	
6rrc"eZdZdZddZddZy) WrappedLineHeightChangeDelegatorc<tj|||_y)z
        callback - Callable, will be called when an insert, delete or replace
                   action on the text widget may require updating the shell
                   sidebar.
        N)rr@callback)r?rs  r
r@z)WrappedLineHeightChangeDelegator.__init__ms	4  
rNcd|v}|rt||}|jj||||rt||}|k(ry|jy)Nr)rrrr)r?rrris_single_linebefore_displaylinesafter_displayliness       r
rz'WrappedLineHeightChangeDelegator.insertvsWU*"24"?

UE40!1$!>!%88

rc||dz}t||t||k(}|rt||}|jj|||rt||}|k(ry|j	y)Nz+1c)rrrrr)r?rrrrrs      r
rz'WrappedLineHeightChangeDelegator.deletesq>e^F#D&1Zf5MM"24"@

VV,!1$!?!%88

rr)rrrr@rrrrr
rrls!rrc\eZdZdZfdZdZfdZdZdZdZ	dZ
d	Zd
ZdZ
xZS)ShellSidebarz0Sidebar for the PyShell window, for prompts etc.cd|_i|_t|
|t	|j
}|jjj}|j|jure|j|jjjur9|j}|j|jjjur9|jjj||d|_
y)NrT)canvasline_promptsrr@rchange_callbackr6rtoprrbottomrr9)r?r6change_delegatordrs    r
r@zShellSidebar.__init__s
!
-T-A-AB	
LL  ::TYY&**DLL$4$4$;$;;JJ**DLL$4$4$;$;;**+;1*E
rctj|jdddd|_|j	|j|jS)NrF)rrrr)r$Canvasr8rupdate_sidebarrrDs r
r:zShellSidebar.init_widgetssCii2,-!*/1	
		{{rct||jjt	j
rdnd|jy)Nz
<Button-2>z
<Button-3>)rr<r;rprisAquaTkcontext_menu_event)r?rs r
r<zShellSidebar.bind_eventss9
"OO-L<##	
rc`tjjd}tjjdd}fd}|j
d|d|rdnd	
|j
d|d|rdnd	
|j|j|jy
)Nr)tearoffr{r|cfdS)Nc:jjSr)rrd	eventnamer?sr
<lambda>z@ShellSidebar.context_menu_event.<locals>.mkcmd.<locals>.<lambda>s49933I>rrrs`r
mkcmdz.ShellSidebar.context_menu_event.<locals>.mkcmds	>>rCopyz<<copy>>normaldisabled)labelcommandr-zCopy with promptsz<<copy-with-prompts>>r[)
r$Menur;boolr
tag_nextrangeadd_commandtk_popupx_rooty_root)r?r^rmenu
has_selectionrs`    r
rzShellSidebar.context_menu_events((!4TYY44UEBC
	?
"'
"3,9z		K	 3"'(?"@,9z		K	u||U\\2rc`|jjddtjddy)Nr~rrt)rrrrr)rrr$rrDs r
rzShellSidebar.grids#QqqqIrc>|jr|jyyr)r9rrDs r
rzShellSidebar.change_callbacks==!rc	h|j}|j}|j}ix}|_|j	t
j|jd}|jddddk7r|j|d}|j|x}|d}||d}d|vrdnd	|vrd
nd}	|	rM|jd|t
j|	|j|jd
t||}
|	||
<|j|d}|j|x}yy)Nz@0,0.r~0z+1line linestartz linestart -1cconsolez>>>stdinz...rtr)anchorrrfillz+1line)r	tag_namesrrrr$ALLrsplit	dlineinfocreate_textNWrrr)r?r
text_tagnamesrrrlineinforcprev_newline_tagnamespromptrs           r
rzShellSidebar.update_sidebars:yy
+--t(

bff

6";;sAq!S(JJ%(89:E>>%00x=A$1UG>2J$K!"&;; $99

""1aF(,		A#H#D%0'-V$JJ%/0E >>%00x=rc$|jy)rVr[)rrQs   r
rTzShellSidebar.yscroll_events
	
rctj|jdd}t|j|t	fddD}|j
j
|dzdz||_|jy	)
rGrr)rc3@K|]}j|ywr)measure).0chartk_fonts  r
	<genexpr>z+ShellSidebar.update_font.<locals>.<genexpr>sF4.Fs)rxr,rurv)rN)	rrrrmaxrr.rr)r?r
char_widthrBs   @r
r=zShellSidebar.update_fontsl		6>Btyyt,F:FF
JNQ$67	rc"tjtjd}tjtjd}|d}|d}||f|_|jj||j
y)rIrr.rr)rN)rrrrrr.r)r?linenumbers_colors
prompt_colorsrrs     r
r>zShellSidebar.update_colorssz%2283H3H3JLY --h.C.C.EyQ
"<0
'5
!:.4r)rrrrr@r:r<rrrrrTr=r>rrs@r
rrs9:$
J"14rrc
ddlm}tj|}tj|}|jtjtjd|jdd|jddtj|dd}tj|d	d
tj|}|jddtj||}tj ||_t%|}|j'|j)d
dj+dt-ddDy)Nr)
Dummy_editwinT)sider1expandr~)weightrrP)rheightrrrr|rc3&K|]	}d|zyw)rNr)r@is  r
rCz._linenumbers_drag_scrolling.<locals>.<genexpr>s >1Q >se)idlelib.idle_test.test_sidebarrJr$ToplevelFramerLEFTBOTHrowconfigurecolumnconfigurerrrrrr	ScrollbarrWrrLrrr)r8rJtoplevelr7rrr6linenumberss        r
_linenumbers_drag_scrollingr^s<{{6"H(#JOOrwwtO<Aa(q+Hfn=D
77:RtLDII!AbggI.D!G<<
+GLg&KKKtyy >a
 >>?r__main__)rzidlelib.idle_test.test_sidebarrtF)	verbosityexit)run)r
contextlibrnrtkinterr$tkinter.fontridlelib.configridlelib.delegatorridlelibrrrrr*contextmanagerr1r3rrrrr^runittestridlelib.idle_test.htestrbrrr
<module>rls#':&
 4**C>C>LAyA$M+M`&y&Rm;m`@,z	)QUC+#$r