ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/sidebar.cpython-37.pyc

B

� f5�@s�dZddlZddlZddlZddlmZddlmZdd�Z	dd�Z
Gd	d
�d
�ZGdd�de�ZGd
d�de�Z
dd�Zedkr�ddlmZedddd�ddlmZee�dS)z�Line numbering implementation for IDLE as an extension.
Includes BaseSideBar which can be extended for other sidebar based extensions
�N)�idleConf)�	DelegatorcCstt|�d���S)z:Utility to get the last line's number in a Tk text widget.zend-1c)�int�float�index)�text�r�4/opt/alt/python37/lib64/python3.7/idlelib/sidebar.py�get_end_linenumbersr
cCs�|��}|dkr|��}n |dkr,|��}ntd|����tt|jj|d|�d�|�d�g��}tt|jj|d|�d�|�d�g��}||fS)z;Get the total padding of a Tk widget, including its border.�pack�gridzUnsupported geometry manager: �padxZborder�pady)	Z
winfo_managerZ	pack_infoZ	grid_info�
ValueError�sum�map�tkZgetintZcget)ZwidgetZmanager�infor
rrrr	�get_widget_paddings



rc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�BaseSideBarz@
    The base class for extensions which require a sidebar.
    c	Csx||_|j|_|j|_t|j�\}}tj|jdtjd|ddd�|_|jj	tj
d�|j|jd<|��|�
�d|_dS)N��r)�width�wrapr
rZborderwidthZhighlightthickness)�stateZyscrollcommandF)�editwin�
text_frame�parentrrr�Text�NONE�sidebar_text�config�DISABLED�redirect_yscroll_event�update_font�
update_colors�is_shown)�selfrZ_padxrrrr	�__init__/szBaseSideBar.__init__cCst�|jdd�}|�|�dS)z;Update the sidebar text font, usually after config changes.�main�EditorWindowN)r�GetFontr�_update_font)r'�fontrrr	r$?szBaseSideBar.update_fontcCs||jd<dS)Nr-)r )r'r-rrr	r,DszBaseSideBar._update_fontcCs*t�t��d�}|j|d|dd�dS)z=Update the sidebar text colors, usually after config changes.Znormal�
foreground�
background)r.r/N)r�GetHighlight�CurrentTheme�_update_colors)r'�colorsrrr	r%Gs
zBaseSideBar.update_colorscCs|jj|||||d�dS)N)ZfgZbgZselectforegroundZselectbackgroundZinactiveselectbackground)r r!)r'r.r/rrr	r2MszBaseSideBar._update_colorscCs$|js |jjddtjd�d|_dS)Nrr)�row�column�stickyT)r&r rr�NSEW)r'rrr	�show_sidebarTszBaseSideBar.show_sidebarcCs|jr|j��d|_dS)NF)r&r Zgrid_forget)r'rrr	�hide_sidebarYs
zBaseSideBar.hide_sidebarcOs"|jjj|�|j�|d�dS)zmRedirect vertical scrolling to the main editor text widget.

        The scroll bar is also updated.
        r�break)r�vbar�setr �yview_moveto)r'�args�kwargsrrr	r#^sz"BaseSideBar.redirect_yscroll_eventcCs|j��dS)z8Redirect focus-in events to the main editor text widget.r:)r�	focus_set)r'�eventrrr	�redirect_focusin_eventgs
z"BaseSideBar.redirect_focusin_eventcCs"|j��|jj|d|jd�dS)z<Redirect mouse button events to the main editor text widget.r)�x�yr:)rr@�event_generaterD)r'rA�
event_namerrr	�redirect_mousebutton_eventls
z&BaseSideBar.redirect_mousebutton_eventcCs|jjdd|j|jd�dS)z7Redirect mouse wheel events to the editwin text widget.z<MouseWheel>r)rCrD�deltar:)rrErDrH)r'rArrr	�redirect_mousewheel_eventrsz%BaseSideBar.redirect_mousewheel_eventN)�__name__�
__module__�__qualname__�__doc__r(r$r,r%r2r8r9r#rBrGrIrrrr	r+s	rc@s,eZdZdZdd�Zd	dd�Zd
dd�ZdS)�EndLineDelegatorz\Generate callbacks with the current end line number after
       insert or delete operationscCst�|�||_dS)z�
        changed_callback - Callable, will be called after insert
                           or delete operations with the current
                           end line number.
        N)rr(�changed_callback)r'rOrrr	r(|s
zEndLineDelegator.__init__NcCs$|j�|||�|�t|j��dS)N)�delegate�insertrOr
)r'r�charsZtagsrrr	rQ�szEndLineDelegator.insertcCs"|j�||�|�t|j��dS)N)rP�deleterOr
)r'Zindex1Zindex2rrr	rS�szEndLineDelegator.delete)N)N)rJrKrLrMr(rQrSrrrr	rNys	
rNc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�LineNumbersz(Line numbers support for editor windows.cCs�t�||�d|_t|jd�|_|jjtjd�|j�	ddd�|jjtj
d�|jjddd�|jjdtjd	�|�
�t|j�}|�|�t|j�}|�|jjj�|jj�|�|jjj}x||k	r�|��|j}q�Wd|_dS)
Nrr)rrQ�1�
linenumberF)Z	takefocusZexportselection)Zjustify)rr(�prev_end�typer �_sidebar_width_typer!r�NORMALrQr"Z
tag_configZRIGHT�bind_eventsr
r�update_sidebar_textrNZsetdelegaterZundorPZper�topZ
resetcacher&)r'r�endZend_line_delegatorZ	delegatorrrr	r(�s&





zLineNumbers.__init__cs@�j�d�j��j�d�j��fdd�}xzdD]r}x6d|�d�d|�d�d	|�d
�fD]}|||d�qZWx4d|�d�d
|�d�fD]}||d|�d�d�q�Wq2Wd�d����fdd�}�j�d|����fdd�}�j�d|���fdd������fdd�}�j�d|�����fdd�}�j�d|�dS)Nz	<FocusIn>z<MouseWheel>cs"tj�j|d�}�j�||�dS)N)rF)�	functools�partialrGr �bind)rF�target_event_nameZhandler)r'rr	�bind_mouse_event�sz1LineNumbers.bind_events.<locals>.bind_mouse_event)r���z<Button-�>z<ButtonRelease-z<Bz-Motion>)rbz<Double-Button-z<Triple-Button-csltt�j�d|j�����}�j�ddd��j�d|�d�|d�d���j�d|d�d��|�dS)Nz@0,�selz1.0r^z.0rrQ)	rrr rrDr�
tag_remove�tag_add�mark_set)rA�lineno)r'�
start_linerr	�b1_mousedown_handler�s
 z5LineNumbers.bind_events.<locals>.b1_mousedown_handlerz
<Button-1>csd�d�d�dS)Nr)rA)�last_y�
last_yviewrmrr	�b1_mouseup_handler�sz3LineNumbers.bind_events.<locals>.b1_mouseup_handlerz<ButtonRelease-1>cs�tt�j�d|�����}t�|g�\}}�j�ddd��j�d|�d�|d�d���j�d||krn|n|d�d��dS)	z6Helper function for drag and selection event handlers.z@0,rhz1.0r^z.0rrQN)	rrr r�sortedrrirjrk)Zy_coordrl�a�b)r'rmrr	�%drag_update_selection_and_insert_mark�s zFLineNumbers.bind_events.<locals>.drag_update_selection_and_insert_markcsJ|j��j���d�kr*�j��ks<n�j��d��|j�dS)Nr)rDr �yviewZwinfo_heightrr=)rAr>)rurorpr'rr	�b1_drag_handler�s

z0LineNumbers.bind_events.<locals>.b1_drag_handlerz<B1-Motion>cs:�dkrdS�j��}|�kr6�j�|d����dS)Nr)r rvrr=)rArv)rurorpr'rr	�selection_handler
s
z2LineNumbers.bind_events.<locals>.selection_handlerz
<<Selection>>)r rarBrI)r'rcZbuttonrFrnrqrwrxr)rurorpr'rmr	r[�s.


	zLineNumbers.bind_eventscCs*t�t��d�}|j|d|dd�dS)z=Update the sidebar text colors, usually after config changes.rVr.r/)r.r/N)rr0r1r2)r'r3rrr	r%s
zLineNumbers.update_colorscCs�||jkrdStt|��tt|j��}|rVtt|jd��}||}|�|�|jd<|jjtj	d�||jkr�d�
t�dgt
tt|jd|d����}|j�d|d�n|j�|d�d	�d�|jjtjd�||_dS)
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�
�rzend -1crVz.0 -1c)rW�len�strrrr rYr!rrZ�join�	itertools�chainr�rangerQrSr")r'r^Zwidth_differenceZ	cur_widthZ	new_widthZnew_textrrr	r\s 

zLineNumbers.update_sidebar_textN)rJrKrLrMr(r[r%r\rrrr	rT�s
jrTc	Cs�ddlm}t�|�}t�|�}|jtjtjdd�|jddd�|j	ddd�t
�|dd�}tj|d	d
tj
|d�}|jddtjd�||�}t�|�|_t|�}|��|�d
d�dd�tdd�D���dS)Nr)�
Dummy_editwinT)ZsideZfill�expandr)Zweightr)r*�P�)rZheightrr-)r4r5r6z1.0rycss|]}d|VqdS)rsNr)�.0�irrr	�	<genexpr>Msz._linenumbers_drag_scrolling.<locals>.<genexpr>�e)Zidlelib.idle_test.test_sidebarr�rZToplevelZFramerZLEFTZBOTHZrowconfigureZcolumnconfigurerr+rrrr7Z	Scrollbarr;rTr8rQr}r�)rr�Ztoplevelrr-rrZlinenumbersrrr	�_linenumbers_drag_scrolling:s

r��__main__)r)zidlelib.idle_test.test_sidebarrF)�	verbosity�exit)�run)rMr_r~ZtkinterrZidlelib.configrZidlelib.delegatorrr
rrrNrTr�rJZunittestr)Zidlelib.idle_test.htestr�rrrr	�<module>s"N-

Zerion Mini Shell 1.0