Hacked By AnonymousFox

Current Path : /opt/alt/python36/lib64/python3.6/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/idlelib/__pycache__/codecontext.cpython-36.opt-1.pyc

3

� f�(�@s�dZddlZddlmZddlZddlmZmZm	Z	ddl
mZdddd	d
ddd
ddddhZdZ
dZejd�fdd�Zdd�ZGdd�d�Zej�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)�TOP�X�SUNKEN)�idleConf�class�def�elif�else�except�finally�for�if�try�while�with�async�di�z^(\s*)(\w*)cCs|j|�j�S)z>Extract the beginning whitespace and first word from codeline.)�match�groups)�codeline�c�r�8/opt/alt/python36/lib64/python3.6/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r!c@sbeZdZdZdd�Zedd��Zdd�Zdd	d
�Zdd
d�Z	dd�Z
ddd�Zdd�Zdd�Z
dS)�CodeContextz,Display block context above the edit window.cCs^||_|j|_|jd|_tj|_d|_d|_dg|_|jj	t
|j�|_|jj	t
|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.textfont is the editor window font.

        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.
        �fontN�r�F���)rr&r%F)�editwin�text�textfontr"�colors�
contextcolors�context�
topvisible�info�after�UPDATEINTERVAL�timer_event�t1�CONFIGUPDATEINTERVAL�config_timer_event�t2)�selfr'rrr�__init__0szCodeContext.__init__cCs,tjdddddd�|_tjtj�d�|_dS)	z!Load class variables from config.�
extensionsr"Zmaxlines�int�)�type�defaultr,N)rZ	GetOption�
context_depthZGetHighlightZCurrentThemer*)�clsrrr�reloadMszCodeContext.reloadc	Cs2y |jj|j�|jj|j�WnYnXdS)zCancel scheduled events.N)r(Zafter_cancelr2r5)r6rrr�__del__Ts
zCodeContext.__del__NcCs�|js�|jj|jjf}d}d}xP|D]H}||jj|j�d�7}||jj|jd��7}||jj|jd��7}q$Wtj	|jj
|j|jd|jddd||t
dd�
|_|jjd	|j�|jjttd
|jjd�n|jj�d|_d
S)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.
        r�padx�border�
background�
foregroundr$�disabled)	r#ZbgZfg�height�widthrArBZrelief�statez<ButtonRelease-1>F)ZsideZfill�expandZbeforeN�break)r,r'r(Z
text_frameZtkZgetintZ	pack_infoZcget�tkinterZText�topr)r+rZbind�
jumptolineZpackrrZdestroy)r6�eventZwidgetsrArBZwidgetrrr�toggle_code_context_event\s*


z%CodeContext.toggle_code_context_eventr$rcCs�g}t}x�t||dd�D]x}|jj|�d�|�d��}t|�\}}	}
||kr|}|
dkrb|d7}|
r�||kr�||kr�|j|||	|
f�||krPqW|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.
        r$z.0z.endr
r	r&)r
r	)r�ranger(�getr!�append�reverse)r6�new_topvisibleZstopline�
stopindent�lines�
lastindentZlinenumrrr(r rrr�get_context�s
zCodeContext.get_contextcCsZt|jjd�jd�d�}|j|kr(dS|j|krf|j||j�\}}x�|jdd|krb|jd=qFWn`|jddd}x,|jdd|kr�|jdd}|jd=qzW|j||jddd|�\}}|jj|�||_dd�|j|jd�D�}|d�rdnd}t	|�||j
d<d	|j
d
<|j
jdd�|j
jdd
j
||d���d|j
d
<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,0�.rNr$cSsg|]}|d�qS)�r)�.0�xrrr�
<listcomp>�sz3CodeContext.update_code_context.<locals>.<listcomp>rFZnormalrHz1.0�end�
rEr&r&r&r&r&r&r&)r9r(�index�splitr-rXr.�extendr=rr,�delete�insert�join)r6rTrVrWrUZcontext_stringsZ	showfirstrrr�update_code_context�s0



zCodeContext.update_code_contextcCspt|j�}|dkrd}n:tt|jjd���}td||j�d}|j||d}|jj	|�d��|j
�dS)z+Show clicked context line at top of editor.r$rdrz.0N)rr.r9�floatr,r`�maxr=r(Zyviewrf)r6rNrVZnewtopZcontextline�offsetrrrrM�s
zCodeContext.jumptolinecCs$|jr|j�|jjt|j�|_dS)z>Event on editor text widget triggered every UPDATEINTERVAL ms.N)r,rfr(r/r0r1r2)r6rrrr1�szCodeContext.timer_eventcCsv|jd}|jr`||jks&tj|jkr`||_tj|_|j|jd<|jd|jd<|jd|jd<|jjt|j�|_	dS)zDEvent on editor text widget triggered every CONFIGUPDATEINTERVAL ms.r#rCrDN)
r(r,r)r"r*r+r/r3r4r5)r6Znewtextfontrrrr4�s
zCodeContext.config_timer_event)N)r$r)N)�__name__�
__module__�__qualname__�__doc__r7�classmethodr?r@rOrXrfrMr1r4rrrrr"-s
&
(
r"�__main__)�mainz"idlelib.idle_test.test_codecontextrZF)�	verbosity�exit)rm�re�sysrrrKZtkinter.constantsrrrZidlelib.configrrr0r3�compilerr!r"r?rjZunittestrprrrr�<module>s"=

Hacked By AnonymousFox1.0, Coded By AnonymousFox