Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/idlelib/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/idlelib/__pycache__/codecontext.cpython-312.pyc

�

%Μg�,����dZddlZddlmZddlmZmZmZddl	m
Z
mZddlm
Z
hd�Zejd�fd	�Zd
�ZGd�d�Zej'�ed
k(rddlmZeddd��yy)a�codecontext - display the block context above the edit window

Once code has scrolled off the top of a window, it can be difficult to
determine which block you are in.  This extension implements a pane at the top
of each IDLE edit window which provides block structure hints.  These hints are
the lines which contain the block opening keywords, e.g. 'if', for the
enclosing block.  The number of hint lines is determined by the maxlines
variable in the codecontext section of config-extensions.def. Lines which do
not open blocks are not shown in the context hints pane.

For EditorWindows, <<toggle-code-context>> is bound to CodeContext(self).
toggle_code_context_event.
�N)�maxsize)�Frame�Text�TclError)�NSEW�SUNKEN)�idleConf>�if�def�for�try�elif�else�with�async�class�while�except�finallyz^(\s*)(\w*)c�@�|j|�j�S)z>Extract the beginning whitespace and first word from codeline.)�match�groups)�codeline�cs  �0/usr/local/lib/python3.12/idlelib/codecontext.py�get_spaces_firstwordrs���7�7�8��#�#�%�%�c��t|�\}}t|�}t|�|k(s||dk(rt}|tvxr|}|||fS)z�Return tuple of (line indent value, codeline, block start keyword).

    The indentation of empty lines (or comment lines) is INFINITY.
    If the line does not start a block, the keyword value is False.
    �#)r�len�INFINITY�BLOCKOPENERS)r�spaces�	firstword�indent�openers     r�
get_line_infor'sU��-�X�6��F�I�
��[�F�
�8�}���(�6�"2�c�"9���
�,�
&�
4�9�F��8�V�#�#rc�f�eZdZdZdZd�Zd�Zed��Zd�Z	dd�Z
dd	�Zd
�Zdd�Z
d�Zd
�Zd�Zy)�CodeContextz,Display block context above the edit window.�dc�T�||_|j|_|j�y)a
Initialize settings for context block.

        editwin is the Editor window for the context block.
        self.text is the editor window text widget.

        self.context displays the code context text above the editor text.
          Initially None, it is toggled via <<toggle-code-context>>.
        self.topvisible is the number of the top text line displayed.
        self.info is a list of (line number, indent level, line text,
          block keyword) tuples for the block structure above topvisible.
          self.info[0] is initialized with a 'dummy' line which
          starts the toplevel 'block' of the module.

        self.t1 and self.t2 are two timer events on the editor text widget to
          monitor for changes to the context text or editor font.
        N)�editwin�text�_reset)�selfr,s  r�__init__zCodeContext.__init__1s��"����L�L��	����
rc�L�d|_d|_d|_d|_dg|_y)N�)r����F)�context�cell00�t1�
topvisible�info�r/s rr.zCodeContext._resetFs(��������������'�(��	rc�B�tjddddd��|_y)z!Load class variables from config.�
extensionsr)�maxlines�int�)�type�defaultN)r	�	GetOption�
context_depth)�clss r�reloadzCodeContext.reloadMs#��%�.�.�|�]�/9��79�;��rc��|j�.	|jj|j�d|_yy#t$rY�wxYw)zCancel scheduled events.N)r7r-�after_cancelrr:s r�__del__zCodeContext.__del__TsI���7�7��
��	�	�&�&�t�w�w�/��D�G����
��
�s�%<�	A�ANc
�>�|j���|jj|jjf}d}d}|D]�}||jjur|j	�n|j�}||jj|d�z
}||jj|jd��z
}||jj|jd��z
}��t|jjddd||td��x}|_|j�|j�|jd|j�|j�|j!ddt"�	�t%j&t%j(�d
�}t+|jj|d��|_|j,j!ddt"�	�d
}	ny|jj/�d|_|j,j/�d|_|jj1|j2�|j5�d}	|jj7dd|	�d���y)aToggle code context display.

        If self.context doesn't exist, create it to match the size of the editor
        window text (toggle on).  If it does exist, destroy it (toggle off).
        Return 'break' to complete the processing of the binding.
        Nr�padx�borderr2�disabled)�height�width�highlightthicknessrJrK�relief�statez<ButtonRelease-1>)�row�column�sticky�
linenumber�
background��bg�Hide�Show�optionsz*ode*ontextz
 Code Context)�menu�index�label�break)r5r,r-�
text_frame�	grid_info�	pack_info�tk�getint�cgetrr�update_font�update_highlight_colors�bind�
jumptoline�timer_event�gridrr	�GetHighlight�CurrentThemerr6�destroyrGr7r.�update_menu_label)
r/�event�widgetsrJrK�widgetr9r5�line_number_colors�menu_statuss
          r�toggle_code_context_eventz%CodeContext.toggle_code_context_event]s1���<�<���l�l�'�'����)@�)@�@�G��D��F�!��!�T�\�\�%6�%6�6��(�(�*�#�-�-�/����	�	�(�(��f��6�6����	�	�(�(����V�)<�=�=���&�)�)�*�*�6�;�;�x�+@�A�A��
"�&*����'�'���#$��&��z�&K�
K�G�d�l�
�����(�(�*��L�L�,�d�o�o�>������L�L�Q�q��L�6�!)�!6�!6�x�7L�7L�7N�7C�"E������ 7� 7�+=�l�+K�M�D�K��K�K����1�T��:� �K��L�L� � �"��D�L��K�K���!��D�K��I�I�"�"�4�7�7�+��K�K�M� �K����&�&�I�]�0;�}�M�-J�	'�	L�rc�F�|dkDsJ�g}t}t||dz
d�D]l}|jj|�d�|�d��}t	|�\}}	}
||ks�:|}|
dvr|dz
}|
r||kr||k\r|j|||	|
f�||ks�ln|j
�||fS)azReturn a list of block line tuples and the 'last' indent.

        The tuple fields are (linenum, indent, text, opener).
        The list represents header lines from new_topvisible back to
        stopline with successively shorter indents > stopindent.
        The list is returned ordered by line number.
        Last indent returned is the smallest indent observed.
        rr2r3�.0z.end)rr)r!�ranger-�getr'�append�reverse)r/�new_topvisible�stopline�
stopindent�lines�
lastindent�linenumrr%r-r&s           r�get_contextzCodeContext.get_context�s����!�|��|����
��^�X�a�Z��<�G��y�y�}�}��y��^��y��5E�F�H�#0��#:� �F�D�&��
�"�#�
��-�-��!�O�J��g��6�6�Z�;O��L�L�'�6�4��!@�A���+��=�	�
�
���j� � rc���|jjd�}|j|k(ry|j|krX|j||j�\}}|jdd|k\r�|jd=|jdd|k\r�#n�|jdddz}|jdd|k\r5|jdd}|jd=|jdd|k\r�5|j||jdddz|�\}}|jj|�||_|j|jdD�cgc]}|d��	}}|drdnd}t|�|z
|jd<d|jd	<|jjd
d�|jjddj||d��d
|jd	<ycc}w)aLUpdate context information and lines visible in the context pane.

        No update is done if the text hasn't been scrolled.  If the text
        was scrolled, the lines that should be shown in the context will
        be retrieved and the context area will be updated with the code,
        up to the number of maxlines.
        z@0,0Nr3r2r�rM�normalrQz1.0�end�
rL)r,�	getlinenor8r�r9�extendrCr r5�delete�insert�join)r/r|rr�r~�x�context_strings�	showfirsts        r�update_code_contextzCodeContext.update_code_context�s������/�/��7���?�?�n�,���?�?�^�+� $� 0� 0��15���!B��E�:��)�)�B�-��"�j�0��I�I�b�M��)�)�B�-��"�j�0����2��q�)�A�-�J��)�)�B�-��"�n�4�!�Y�Y�r�]�1�-�
��I�I�b�M��)�)�B�-��"�n�4�!%� 0� 0��15���2��q�1A�!�1C�1;�!=��E�:�	
�	�	�����(���)-���D�4F�4F�3F�3G�)H�I�)H�A�1�Q�4�)H��I�(��+�A��	�!$�_�!5�	�!A����X�� (����W�������E�5�)������E�4�9�9�_�Y�Z�-H�#I�J� *����W���Js�G4c��	|jjd�y#t$r�t|j�}|dk(rd}n^tt
|jjd���}td||jz
�dz
}|j||zd}|jj|�d��|j�YywxYw)z� Show clicked context line at top of editor.

        If a selection was made, don't jump; allow copying.
        If no visible context, show the top line of the file.
        z	sel.firstr2r�rrwN)r5r]rr r9r>�float�maxrCr-�yviewr�)r/rpr�newtop�contextline�offsets      rrizCodeContext.jumptoline�s���
	'��L�L���{�+���	'���	�	�N�E���z���"�%����(:�(:�8�(D�"E�F���Q���(:�(:� :�;�a�?�����6�K�#7�8��;���I�I�O�O�v�h�b�M�*��$�$�&�	'�s��B2C�Cc��|j�F|j�|jj|j|j
�|_yy)z>Event on editor text widget triggered every UPDATEINTERVAL ms.N)r5r�r-�after�UPDATEINTERVALrjr7r:s rrjzCodeContext.timer_event�s?���<�<�#��$�$�&��i�i�o�o�d�&9�&9�4�;K�;K�L�D�G�$rc�~�|j�1tj|jdd�}||jd<yy)N�main�EditorWindow�font)r5r	�GetFontr-)r/r�s  rrfzCodeContext.update_font�s7���<�<�#��#�#�D�I�I�v�~�F�D�#'�D�L�L�� �$rc�\�|j�Ltjtj�d�}|d|jd<|d|jd<|j�Htjtj�d�}|jj|d��yy)Nr5rV�
foregroundrUrW)r5r	rlrmr6�config)r/�colorsrss   rrgz#CodeContext.update_highlight_colors�s����<�<�#��*�*�8�+@�+@�+B�I�N�F�)/��)=�D�L�L��&�)/��)=�D�L�L��&��;�;�"�!)�!6�!6�x�7L�7L�7N�7C�"E���K�K���"4�\�"B��C�#r)N)r2r)�__name__�
__module__�__qualname__�__doc__r�r0r.�classmethodrErHrur�r�rirjrfrg�rrr)r)-sT��2��N��*)��;��;��6�p!�<&+�P'�*M�(�
	Drr)�__main__)r�z"idlelib.idle_test.test_codecontextr�F)�	verbosity�exit)r��re�sysrr!�tkinterrrr�tkinter.constantsrr�idlelib.configr	r"�compilerr'r)rEr��unittestr�r�rr�<module>r�s{���
�#�)�)�*�#�>��&0�R�Z�Z��%?�&�
$�WD�WD�t�����z����	-���G�r

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists