Your IP : 18.191.223.30


Current Path : /opt/alt/python34/lib64/python3.4/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/idlelib/__pycache__/CodeContext.cpython-34.pyo

�
e f� �@s�dZddlZddlmZmZmZmZmZddlZddl	m
Zddlm
Z
dddd	d
ddd
dddhZdZdZejd�dd�ZGdd�d�ZdS)aICodeContext - Extension to 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 numlines
variable in the CodeContext section of config-extensions.def. Lines which do
not open blocks are not shown in the context hints pane.

�N)�TOP�LEFT�X�W�SUNKEN)�maxsize)�idleConf�class�def�elif�else�except�finally�for�if�try�while�with�di�z^(\s*)(\w*)cCs|j|�j�S)N)�match�groups)�s�c�r�8/opt/alt/python34/lib64/python3.4/idlelib/CodeContext.py�<lambda>src@s�eZdZdd gfgZejddddddd	�Zejddd
dddd�Zejddd
dddd�Zdd�Z	ddd�Z
dd�Zdddd�Zdd�Z
dd�Zdd�ZdS)!�CodeContextZoptions�!Code Conte_xt�<<toggle-code-context>>�
extensionsZnumlines�type�int�default��bgcolor�strZ	LightGray�fgcolorZBlackcCs�||_|j|_|jd|_d|_dg|_d|_tjdddd	d
dd�}|r�|j�|jj	dd
�n|jj
t|j�|jj
t
|j�dS)N�fontr��Frr�visibler �boolr"z<<toggle-code-context>>T���)rr,r)F)�editwin�text�textfont�label�info�
topvisibler�	GetOption�toggle_code_context_eventZsetvar�after�UPDATEINTERVAL�timer_event�FONTUPDATEINTERVAL�font_timer_event)�selfr-r*rrr�__init__"s			
zCodeContext.__init__NcCs�|jsC|jj|jjf}d}xM|D]E}|tt|j�d��7}|tt|jd���7}q.Wd}x-|D]%}|tt|jd���7}q�Wtj	|jj
dd|jddtdt
d	|jd
|jd|jddd|d|d
t�
|_|jjdtdtddd|jj�n|jj�d|_tjdddt|jdk	��tj�dS)Nr�padx�borderr.�
r(ZanchorZjustifyr'ZbgZfg�widthZreliefZsideZfill�expandFZbeforerrr*)r0r-r.Z
text_framer!r%Z	pack_infoZcget�tkinterZLabel�top�
context_depthrrr/r$r&rZpackrrZdestroyrZ	SetOptionZSaveUserCfgFiles)r:ZeventZwidgetsr<Zwidgetr=rrrr47s0	
 #
#	
	z%CodeContext.toggle_code_context_eventcCs�|jjd|d|�}t|�\}}|tko>|}t|�t|�kso|t|�dkrxt}nt|�}|||fS)z�Get the line indent value, text, and any block start keyword

        If the line does not start a block, the keyword value is False.
        The indentation of empty lines (or comment lines) is INFINITY.

        z%d.0z%d.end�#)r.�get�getspacesfirstword�BLOCKOPENERS�len�INFINITY)r:�linenumr.ZspacesZ	firstword�opener�indentrrr�
get_line_info[s.	zCodeContext.get_line_infor(rc
Cs�g}t}x�t||dd�D]�}|j|�\}}}	||kr#|}|	dkrl|d7}n|	r�||kr�||kr�|j||||	f�n||kr�Pq�q#q#W|j�||fS)z�Get context lines, starting at new_topvisible and working backwards.

        Stop when stopline or stopindent is reached. Return a tuple of context
        data and the indent level at the top of the region inspected.

        r(rrr,)zelsezelif)rI�rangerM�append�reverse)
r:�new_topvisibleZstopline�
stopindent�lines�
lastindentrJrLr.rKrrr�get_contextks

zCodeContext.get_contextcCs�t|jjd�jd�d�}|j|kr8dS|j|kr�|j||j�\}}x�|jdd|kr�|jd=qeWn�|j|kr|jd
dd}x6|jdd|kr�|jdd}|jd=q�W|j||jddd|�\}}n|jj|�||_dgtd|j	t
|j��}|dd�|j|j	d�D�7}d	j|�|jd
<dS)zKUpdate context information and lines visible in the context pane.

        z@0,0�.rNr(r)cSsg|]}|d�qS)�r)�.0�xrrr�
<listcomp>�s	z3CodeContext.update_code_context.<locals>.<listcomp>r>r.r,r,r,r,r,r,r,)
r!r.�index�splitr2rUr1�extend�maxrCrH�joinr0)r:rQrSrTrRZcontext_stringsrrr�update_code_context�s*%			&(zCodeContext.update_code_contextcCs0|jr|j�n|jjt|j�dS)N)r0r`r.r5r6r7)r:rrrr7�s	
zCodeContext.timer_eventcCs[|jd}|jrA||jkrA||_|j|jd<n|jjt|j�dS)Nr')r.r0r/r5r8r9)r:Znewtextfontrrrr9�s

	zCodeContext.font_timer_event)rr)�__name__�
__module__�__qualname__Zmenudefsrr3rCr$r&r;r4rMrUr`r7r9rrrrrs$ r)�__doc__rAZtkinter.constantsrrrrr�re�sysrrIZidlelib.configHandlerrrGr6r8�compilerFrrrrr�<module>s(

?>