[ @sdZddlZddlmZmZmZmZmZddlZddl m Z ddl m Z dddd d d d d dddh ZdZdZejdddZGdddZdS)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)TOPLEFTXWSUNKEN)maxsize)idleConfclassdefelifelseexceptfinallyforiftrywhilewithdiz ^(\s*)(\w*)cCs|j|jS)N)matchgroups)scr)/usr/lib/python3.4/idlelib/CodeContext.pysrc@seZdZdd gfgZejddddddd Zejddd dd dd Zejddd dd ddZddZ dddZ ddZ ddddZ ddZ ddZddZdS)! CodeContextZoptions!Code Conte_xt<> extensionsZnumlinestypeintdefaultbgcolorstrZ LightGrayfgcolorZBlackcCs||_|j|_|jd|_d|_dg|_d|_tjdddd d d d}|r|j|jj d d n|jj t |j |jj t |jdS)NfontrFrrvisibler boolr"z<>T)rr,r)F)editwintexttextfontlabelinfo topvisibler GetOptiontoggle_code_context_eventZsetvarafterUPDATEINTERVAL timer_eventFONTUPDATEINTERVALfont_timer_event)selfr-r*rrr__init__"s       zCodeContext.__init__NcCs|jsC|jj|jjf}d}xM|D]E}|tt|jd7}|tt|jd7}q.Wd}x-|D]%}|tt|jd7}qWtj |jj dd|j ddt dt d |jd |jd |jd dd|d|d t |_|jjdtdtddd|jjn|jjd|_tjdddt|jdk tjdS)Nrpadxborderr. r(ZanchorZjustifyr'ZbgZfgwidthZreliefZsideZfillexpandFZbeforerrr*)r0r-r.Z text_framer!r%Z pack_infoZcgettkinterZLabeltop 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)zGet 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.getgetspacesfirstword BLOCKOPENERSlenINFINITY)r:linenumr.ZspacesZ firstwordopenerindentrrr get_line_info[s.  zCodeContext.get_line_infor(rc Cs|dkstg}t}xt||ddD]}|j|\}}} ||kr5|}| dkr~|d7}n| r||kr||kr|j|||| fn||krPqq5q5W|j||fS)zGet 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. rr(r r r,)zelsezelif)AssertionErrorrIrangerMappendreverse) r:new_topvisibleZstopline stopindentlines lastindentrJrLr.rKrrr get_contextks      zCodeContext.get_contextcCst|jjdjdd}|j|kr8dS|j|kr|j||j\}}x|jd d|kr|jd =qeWn|j|kr|jd dd}x6|jdd|kr|jdd}|jd=qW|j||jddd|\}}n|jj|||_dgtd|j t |j}|dd|j|j dD7}d j ||j d s z3CodeContext.update_code_context..r>r.r,r,r,r,r,r,r,) r!r.indexsplitr2rVr1extendmaxrCrHjoinr0)r:rRrTrUrSZcontext_stringsrrrupdate_code_contexts*%   &(zCodeContext.update_code_contextcCs0|jr|jn|jjt|jdS)N)r0rar.r5r6r7)r:rrrr7s  zCodeContext.timer_eventcCs[|jd}|jrA||jkrA||_|j|jd s (