%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/idlelib/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/idlelib/__pycache__/codecontext.cpython-38.pyc

U

qa,@sdZddlZddlmZddlmZmZmZddl	m
Z
mZddlm
Z
ddd	d
ddd
dddddhZedfddZddZGdddZeedkrddlmZedddddS) acodecontext - 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)FrameTextTclError)NSEWSUNKEN)idleConfclassdefifelifelsewhilefortryexceptfinallywithasyncz^(\s*)(\w*)cCs||S)z>Extract the beginning whitespace and first word from codeline.)matchgroups)codelinecr//usr/local/lib/python3.8/idlelib/codecontext.pyget_spaces_firstwordsrcCsFt|\}}t|}t||ks,||dkr0t}|tko:|}|||fS)zReturn 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.
    #)rlenINFINITYBLOCKOPENERS)rZspacesZ	firstwordindentopenerrrr
get_line_infosr"c@sveZdZdZdZddZddZeddZd	d
Z	ddd
Z
dddZddZdddZ
ddZddZddZdS)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)editwintext_reset)selfr%rrr__init__1szCodeContext.__init__cCs$d|_d|_d|_d|_dg|_dS)N)rF)contextcell00t1
topvisibleinfor(rrrr'Fs
zCodeContext._resetcCstjdddddd|_dS)z!Load class variables from config.
extensionsr#Zmaxlinesint)typedefaultN)rZ	GetOption
context_depth)clsrrrreloadMs
zCodeContext.reloadcCs<|jdk	r8z|j|jWntk
r0YnXd|_dS)zCancel scheduled events.N)r/r&after_cancelrr2rrr__del__Ts
zCodeContext.__del__Nc

Csv|jdkr |jj|jjf}d}d}|D]`}||jjkr@|n|}||j|d7}||j|d7}||j|d7}q(t	|jjddd||t
dd}|_|||
d|j||jddtd	ttd
}t|jj|dd|_|jjddtd	d
}	n:|jd|_|jd|_|j|j|d}	|jjdd|	dddS)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.
        Nrpadxborderr*disabled)heightwidthZhighlightthicknessr=r>Zreliefstatez<ButtonRelease-1>)rowcolumnZsticky
linenumber
backgroundbgZHideZShowoptionsz*ode*ontextz
 Code Context)ZmenuindexZlabelbreak)r-r%r&Z
text_frameZ	grid_infoZ	pack_infoZtkZgetintZcgetrrupdate_fontupdate_highlight_colorsbind
jumptolinetimer_eventZgridrrGetHighlightCurrentThemerr.Zdestroyr;r/r'Zupdate_menu_label)
r(eventZwidgetsr=r>Zwidgetr1r-line_number_colorsZmenu_statusrrrtoggle_code_context_event]s\





z%CodeContext.toggle_code_context_eventr*rcCs|dkstg}t}t||ddD]z}|j|d|d}t|\}}	}
||kr$|}|
dkrl|d7}|
r||kr||kr||||	|
f||kr$qq$|||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.
        rr*r+.0z.end)r
r)AssertionErrorrranger&getr"appendreverse)r(new_topvisibleZstopline
stopindentlines
lastindentZlinenumrr r&r!rrrget_contexts 	zCodeContext.get_contextcCsB|jd}|j|krdS|j|krT|||j\}}|jdd|kr|jd=q6n\|jddd}|jdd|kr|jdd}|jd=qf|||jddd|\}}|j|||_dd|j|jdD}|drdnd}t|||jd<d	|jd
<|j	dd|j
dd
||dd|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|]}|dqS)r).0xrrr
<listcomp>sz3CodeContext.update_code_context.<locals>.<listcomp>r@ZnormalrBz1.0end
r?)r%Z	getlinenor0r`r1extendr8rr-deleteinsertjoin)r(r\r^r_r]Zcontext_stringsZ	showfirstrrrupdate_code_contexts4



zCodeContext.update_code_contextcCsz|jdWntk
rt|j}|dkr8d}n:tt|jd}td||jd}|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*rirrVN)r-rJrrr1r4floatmaxr8r&Zyviewrk)r(rSr^ZnewtopZcontextlineoffsetrrrrOs
zCodeContext.jumptolinecCs*|jdk	r&||j|j|j|_dS)z>Event on editor text widget triggered every UPDATEINTERVAL ms.N)r-rkr&ZafterUPDATEINTERVALrPr/r2rrrrPs
zCodeContext.timer_eventcCs(|jdk	r$t|jdd}||jd<dS)NmainZEditorWindowfont)r-rZGetFontr&)r(rqrrrrLs
zCodeContext.update_fontcCsf|jdk	r6ttd}|d|jd<|d|jd<|jdk	rbttd}|jj|dddS)Nr-rFZ
foregroundrErG)r-rrQrRr.Zconfig)r(ZcolorsrTrrrrMs


z#CodeContext.update_highlight_colors)N)r*r)N)__name__
__module____qualname____doc__ror)r'classmethodr:r<rUr`rkrOrPrLrMrrrrr#-s
	
8
(
r#__main__)rpz"idlelib.idle_test.test_codecontextraF)	verbosityexit)ruresysrrtkinterrrrZtkinter.constantsrrZidlelib.configrrcompilerr"r#r:rrZunittestrprrrr<module>s(
[

Zerion Mini Shell 1.0