Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/idlelib/__pycache__/codecontext.cpython-37.opt-1.pyc

B

� f>,�@s�dZddlZddlmZddlZddlmZmZddl	m
Z
dddd	d
ddd
ddddhZe�d�fdd�Z
dd�ZGdd�d�Ze��edkr�ddlmZedddd�dS)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.
�N)�maxsize)�NSEW�SUNKEN)�idleConf�class�def�if�elif�else�while�for�try�except�finally�with�asyncz^(\s*)(\w*)cCs|�|���S)z>Extract the beginning whitespace and first word from codeline.)�match�groups)�codeline�c�r�8/opt/alt/python37/lib64/python3.7/idlelib/codecontext.py�get_spaces_firstwordsrcCsFt|�\}}t|�}t|�|ks,||dkr0t}|tko:|}|||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)rZspacesZ	firstword�indent�openerrrr�
get_line_infosrc@sveZdZdZdZdd�Zdd�Zedd��Zd	d
�Z	ddd
�Z
ddd�Zdd�Zddd�Z
dd�Zdd�Zdd�ZdS)�CodeContextz,Display block context above the edit window.�dcCs||_|j|_|��dS)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"rrr�__init__.szCodeContext.__init__cCs$d|_d|_d|_d|_dg|_dS)N�)r����F)�context�cell00�t1�
topvisible�info)r%rrrr$Cs
zCodeContext._resetcCstjdddddd�|_dS)z!Load class variables from config.�
extensionsr Zmaxlines�int�)�type�defaultN)rZ	GetOption�
context_depth)�clsrrr�reloadJszCodeContext.reloadcCs>|jdk	r:y|j�|j�Wntjk
r2YnXd|_dS)zCancel scheduled events.N)r,r#�after_cancel�tkinter�TclError)r%rrr�__del__Qs
zCodeContext.__del__Nc

Cs~|jdk�r(|jj|jjf}d}d}xh|D]`}||jjkrB|��n|��}||j�|d�7}||j�|�d��7}||j�|�d��7}q*Wt	j
|jjddd||tdd�}|_|��|�
�|�d|j�|��|jddtd	�t�t��d
�}t	j|jj|dd�|_|jjddtd	�d
}	n:|j��d|_|j��d|_|j�|j�|��d}	|jjdd|	�d�d�dS)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�borderr'�disabled)�height�widthZhighlightthicknessr;r<Zrelief�statez<ButtonRelease-1>)�row�columnZsticky�
linenumber�
background)�bgZHideZShowZoptionsz* Code Contextz
 Code Context)Zmenu�indexZlabel�break)r*r"r#Z
text_frameZ	grid_infoZ	pack_infoZtkZgetintZcgetr8ZTextr�update_font�update_highlight_colorsZbind�
jumptoline�timer_eventZgridrr�GetHighlight�CurrentThemeZFramer+Zdestroyr7r,r$Zupdate_menu_label)
r%�eventZwidgetsr;r<Zwidgetr.r*�line_number_colorsZmenu_statusrrr�toggle_code_context_eventZsJ





z%CodeContext.toggle_code_context_eventr'rcCs�g}t}x�t||dd�D]x}|j�|�d�|�d��}t|�\}}	}
||kr|}|
dkrb|d7}|
r�||kr�||kr�|�|||	|
f�||krPqW|��||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.
        r'r(z.0z.end)r
r	)r�ranger#�getr�append�reverse)r%�new_topvisibleZstopline�
stopindent�lines�
lastindentZlinenumrrr#rrrr�get_context�s
zCodeContext.get_contextcCsJ|j�d�}|j|krdS|j|krX|�||j�\}}x�|jdd|krT|jd=q8Wn`|jddd}x,|jdd|kr�|jdd}|jd=qlW|�||jddd|�\}}|j�|�||_dd�|j|jd�D�}|dr�dnd}t|�||jd<d	|jd
<|j�	dd�|j�
dd
�||d���d|jd
<dS)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,0Nr(r'rcSsg|]}|d�qS)�r)�.0�xrrr�
<listcomp>�sz3CodeContext.update_code_context.<locals>.<listcomp>r>Znormalr@z1.0�end�
r=)r"Z	getlinenor-rYr.�extendr4rr*�delete�insert�join)r%rUrWrXrVZcontext_stringsZ	showfirstrrr�update_code_context�s0



zCodeContext.update_code_contextcCs�y|j�d�Wn�tjk
r�t|j�}|dkr:d}n:tt|j�d���}td||j	�d}|j||d}|j
�|�d��|��YnXdS)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.firstr'rbrz.0N)
r*rFr8r9rr.r0�float�maxr4r#Zyviewrd)r%rNrWZnewtopZcontextline�offsetrrrrJ�s
zCodeContext.jumptolinecCs*|jdk	r&|��|j�|j|j�|_dS)z>Event on editor text widget triggered every UPDATEINTERVAL ms.N)r*rdr#Zafter�UPDATEINTERVALrKr,)r%rrrrK�s
zCodeContext.timer_eventcCs(|jdk	r$t�|jdd�}||jd<dS)N�mainZEditorWindow�font)r*rZGetFontr#)r%rjrrrrH�s
zCodeContext.update_fontcCsf|jdk	r6t�t��d�}|d|jd<|d|jd<|jdk	rbt�t��d�}|jj|dd�dS)Nr*rDZ
foregroundrC)rE)r*rrLrMr+Zconfig)r%ZcolorsrOrrrrI�s


z#CodeContext.update_highlight_colors)N)r'r)N)�__name__�
__module__�__qualname__�__doc__rhr&r$�classmethodr6r:rPrYrdrJrKrHrIrrrrr *s	
8
(
r �__main__)riz"idlelib.idle_test.test_codecontextrZF)�	verbosity�exit)rn�re�sysrrr8Ztkinter.constantsrrZidlelib.configrr�compilerrr r6rkZunittestrirrrr�<module>
s[

Hacked By AnonymousFox1.0, Coded By AnonymousFox