a
    If
                    @   s  d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ddlm0Z0 ddl1m2Z3 ddlm4Z4 ddl5m6Z6m7Z7 ddl8m9Z9 dd	l:m;Z; dd
l<m=Z= ddl>m?Z?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddlImJZJ ddlKmLZL ddlAmMZM e7 ZNeDeFeHeJeLfZOG dd deZPdaQG dd de#ZRG dd de#ZSG dd de#ZTG dd de#ZUG dd de#ZVG d d! d!e#ZWG d"d# d#e$ZXG d$d% d%ZYeY ZZd&Z[d'd(d)d*d+d,Z\d-d. Z]G d/d0 d0e#Z^e_d1krdd2l`maZa ead3d4d5d6 dd7lbmcZc eceP dS )8a  IDLE Configuration Dialog: support user customization of IDLE by GUI

Customize font faces, sizes, and colorization attributes.  Set indentation
defaults.  Customize keybindings.  Colorization and keybindings can be
saved as user defined sets.  Select startup options including shell/editor
and default window size.  Define additional help sources.

Note that tab width in IDLE is currently fixed at eight due to Tk issues.
Refer to comments in EditorWindow autoindent code for details.

    N)ToplevelListboxScaleCanvas	StringVar
BooleanVarIntVarTRUEFALSETOPBOTTOMRIGHTLEFTSOLIDGROOVENONEBOTHXYWEEWNSNSEWNW
HORIZONTALVERTICALANCHORACTIVEENDTclError)Frame
LabelFrameButtonCheckbuttonEntryLabel
OptionMenuNotebookRadiobutton	ScrollbarStyleSpinboxCombobox)colorchooser)
messagebox)idleConfConfigChanges)GetKeysDialog)DynOptionMenu)macosx)SectionName
HelpSource)	view_text)AutoComplete)CodeContext)
ParenMatch)FormatParagraph)Squeezer)ScrollableTextFramec                       sr   e Zd ZdZddddddZdd Zd	d
 Zdd Zdd Zdd Z	 fddZ
dd Zdd Zdd Z  ZS )ConfigDialogzConfig dialog for IDLE.
     F)_htest_utestc                C   s   t | | || _|ri |_|s(|   | |p2d | d }| |sPdnd }| d| d|  | 	  | j
ttd | | | d| j | jj  t  |s|   |   |   dS )	a  Show the tabbed dialog for user configuration.

        Args:
            parent - parent of this dialog
            title - string which is the title of this popup dialog
            _htest - bool, change box location when running htest
            _utest - bool, don't wait_window when running unittest

        Note: Focus set on font page fontlist.

        Methods:
            create_widgets
            cancel: Bound to DELETE_WINDOW protocol.
        zIDLE Preferences         +heightwidthZWM_DELETE_WINDOWN)r   __init__parentinstance_dictZwithdrawtitleZwinfo_rootxZwinfo_rootyZgeometrycreate_widgetsZ	resizabler
   Z	transientZprotocolcancelfontpagefontlistZ	focus_settracersattachZgrab_setZwm_deiconifyZwait_window)selfrJ   rL   r@   rA   xy rV   %lib/python3.9/idlelib/configdialog.pyrI   1   s(    
zConfigDialog.__init__c                 C   s  t | dd | _}| jjdd t| | _}t|| _t|| j| _t	|| j| _
t|| j| _t|| _t|| _|j| j
dd |j| jdd |j| jdd |j| jd	d |j| jd
d |j| jdd |  |jtttd |  jtd dS )a   Create and place widgets for tabbed dialog.

        Widgets Bound to self:
            frame: encloses all other widgets
            note: Notebook
            highpage: HighPage
            fontpage: FontPage
            keyspage: KeysPage
            winpage: WinPage
            shedpage: ShedPage
            extpage: ExtPage

        Methods:
            create_action_buttons
            load_configs: Load pages except for extensions.
            activate_config_changes: Tell editors to reload.
        Z5pxpaddingZnwes)sticky
Fonts/Tabstext
Highlightsz Keys z	 Windows z
 Shell/Ed 
Extensionssideexpandfillra   N)r!   framegridr(   noteExtPageextpageHighPagehighpageFontPagerO   KeysPageZkeyspageWinPageZwinpageShedPageZshedpageaddZenable_traversalpackr   r	   r   create_action_buttonsr   )rS   re   rg   rV   rV   rW   rM   `   s$    


zConfigDialog.create_widgetsc                 C   s   t  ri }nddi}t| jdd}t|dd}i | _d| jfd| jfd| jfd| jffD ]:\}}t	|f||t
d	|| j|< | j| jtd
d qZt|dddjtd |jtd |S )a  Return frame of action buttons for dialog.

        Methods:
            ok
            apply
            cancel
            help

        Widget Structure:
            outer: Frame
                buttons: Frame
                    (no assignment): Button (ok)
                    (no assignment): Button (apply)
                    (no assignment): Button (cancel)
                    (no assignment): Button (help)
                (no assignment): Frame
        rY   )         rX   ZOkZApplyZCancelZHelp)r]   command	takefocus   )ra   padxr   )rG   borderwidthrd   )r4   ZisAquaTkr!   re   ZbuttonsokapplyrN   helpr#   r
   rq   r   r   r   )rS   Zpadding_argsZouterZbuttons_frameZtxtcmdrV   rV   rW   rr      s(    
z"ConfigDialog.create_action_buttonsc                 C   s   |    |   dS )z*Apply config changes, then dismiss dialog.N)r|   destroyrS   rV   rV   rW   r{      s    zConfigDialog.okc                 C   s&   |    t  | j  |   dS )z+Apply config changes and leave dialog open.N)deactivate_current_configchangessave_allri   save_all_changed_extensionsactivate_config_changesr   rV   rV   rW   r|      s    
zConfigDialog.applyc                 C   s   t   |   dS )zPDismiss config dialog.

        Methods:
            destroy: inherited
        N)r   clearr   r   rV   rV   rW   rN      s    zConfigDialog.cancelc                    s&   | j jdda|   t   d S )N1.0end)rO   font_samplegetfont_sample_textZgrab_releasesuperr   r   	__class__rV   rW   r      s    zConfigDialog.destroyc                 C   s8   | j j| j  dd }t| dtt|d d dS )zCreate textview for config dialog help.

        Attributes accessed:
            note
        Methods:
            view_text: Method from textview module.
        r]   )ZoptionzHelp for IDLE preferencesr?   )rL   contentsN)rg   ZtabZselectstripr7   help_common
help_pagesr   )rS   ZpagerV   rV   rW   r}      s    zConfigDialog.helpc                 C   s"   | j j }|D ]}|  qdS )zRemove current key bindings.
        Iterate over window instances defined in parent and remove
        the keybindings.
        N)rJ   rK   keysZRemoveKeybindings)rS   win_instancesinstancerV   rV   rW   r      s    z&ConfigDialog.deactivate_current_configc                 C   s\   | j j }|D ]4}|  |  |  |  |  |  qt	D ]}|
  qJdS )zApply configuration changes to current windows.

        Dynamically update the current parent window instances
        with some of the configuration changes.
        N)rJ   rK   r   ZResetColorizerZ	ResetFontZset_notabs_indentwidthZApplyKeybindingsZreset_help_menu_entriesZupdate_cursor_blinkreloadablesreload)rS   r   r   klassrV   rV   rW   r      s    
z$ConfigDialog.activate_config_changes)r?   )__name__
__module____qualname____doc__rI   rM   rr   r{   r|   rN   r   r}   r   r   __classcell__rV   rV   r   rW   r>   -   s   /&(	r>   u^  <ASCII/Latin1>
AaBbCcDdEeFfGgHhIiJj
1234567890#:+=(){}[]
¢£¥§©«®¶½ĞÀÁÂÃÄÅÇÐØß

<IPA,Greek,Cyrillic>
ɐɕɘɞɟɤɫɮɰɷɻʁʃʆʎʞʢʫʭʯ
ΑαΒβΓγΔδΕεΖζΗηΘθΙιΚκ
БбДдЖжПпФфЧчЪъЭэѠѤѬӜ

<Hebrew, Arabic>
אבגדהוזחטיךכלםמןנסעף
ابجدهوزحطي٠١٢٣٤٥٦٧٨٩

<Devanagari, Tamil>
०१२३४५६७८९अआइईउऊएऐओऔ
௦௧௨௩௪௫௬௭௮௯அஇஉஎ

<East Asian>
〇一二三四五六七八九
汉字漢字人木火土金水
가냐더려모뵤수유즈치
あいうえおアイウエオ
c                       sF   e Zd Z fddZdd Zdd Zdd Zd	d
 ZdddZ  Z	S )rl   c                    s(   t  | |j| _|   |   d S N)r   rI   highlight_samplecreate_page_fontload_font_cfg)rS   masterrk   r   rV   rW   rI   "  s    zFontPage.__init__c           	      C   s  t t| | j| _t t| | j| _t t| | j| _t| dt	dd}t| dt	dd}t
|}t
|}t|tdd}t|ddtd	| _| jd
| j | jd| j | jd| j t|}|j| jjd | jj|jd t|dd}t|| jd| _t|| jdddd| _t|}|j| _| jjtddd | jtt  | j!ddd | j"ddd |j#ddddd |j#ddddddd |j$t%ddt&d |j$t%ddt&d |j$t%t'd | jj$tt(t&d |j$tt)d  |j$tt'd | jj$tt'd | jj$tt'd!d" |j$t(t*d# dS )$aR  Return frame of widgets for Font tab.

        Fonts: Enable users to provisionally change font face, size, or
        boldness and to see the consequence of proposed choices.  Each
        action set 3 options in changes structuree and changes the
        corresponding aspect of the font sample on this page and
        highlight sample on highlight page.

        Function load_font_cfg initializes font vars and widgets from
        idleConf entries and tk.

        Fontlist: mouse button 1 click or up or down key invoke
        on_fontlist_select(), which sets var font_name.

        Sizelist: clicking the menubutton opens the dropdown menu. A
        mouse button 1 click or return key sets var font_size.

        Bold_toggle: clicking the box toggles var font_bold.

        Changing any of the font vars invokes var_changed_font, which
        adds all 3 font options to changes and calls set_samples.
        Set_samples applies a new font constructed from the font vars to
        font_sample and to highlight_sample on the highlight page.

        Widgets for FontPage(Frame):  (*) widgets bound to self
            frame_font: LabelFrame
                frame_font_name: Frame
                    font_name_title: Label
                    (*)fontlist: ListBox - font_name
                    scroll_font: Scrollbar
                frame_font_param: Frame
                    font_size_title: Label
                    (*)sizelist: DynOptionMenu - font_size
                    (*)bold_toggle: Checkbutton - font_bold
            frame_sample: LabelFrame
                (*)font_sample: Label
        ru   z Shell/Editor Font rz   reliefr]   z Font Sample (Editable) zFont Face :)Zjustifyr]      TrG   rw   exportselection<ButtonRelease-1>z<KeyRelease-Up>z<KeyRelease-Down>rv   )yscrollcommandzSize :r\   N   r   ZBold)variableonvalueoffvaluer]   )wraprH   rG   Zweightrx   )rowcolumnry   padyrt   nsew)r   r   Zrowspanry   r   rZ   ra   ry   r   rc   ra   anchorr`   )ra   rc   rB   ra   r   ry   )rb   rc   )+rQ   rp   r   var_changed_font	font_name	font_sizer   	font_boldr"   r   r!   r&   r   r   r
   rP   bindon_fontlist_selectr*   configyviewsetr3   sizelistr$   Zbold_toggler=   r]   r   r   insertr   r   columnconfigurerowconfigurerf   rq   r   r   r   r	   r   r   )	rS   Z
frame_fontZframe_sampleZframe_font_nameZframe_font_paramZfont_name_titleZscroll_fontZfont_size_titleZfont_sample_framerV   rV   rW   r   (  s`    &zFontPage.create_page_fontc           	      C   s   t | dd}|d  }|d }|d dk}ttt| }|D ]}| jt	| qD| j
| dd |D }z>||}| j| | j| | j| | j| W n ty   Y n0 | jd	| | j| |   d
S )a  Load current configuration settings for the font options.

        Retrieve current font with idleConf.GetFont and font families
        from tk. Setup fontlist and set font_name.  Setup sizelist,
        which sets font_size.  Set font_bold.  Call set_samples.
        mainEditorWindowr   r   ru   Zboldc                 S   s   g | ]}|  qS rV   )lower).0srV   rV   rW   
<listcomp>      z*FontPage.load_font_cfg.<locals>.<listcomp>)789101112131416Z18Z20Z22Z25Z29Z34Z40N)r0   ZGetFontr   sortedr   tkfontZfamiliesrP   r   r   r   indexsee
select_setselect_anchorZactivate
ValueErrorr   SetMenur   set_samples)	rS   Zconfigured_fontr   r   r   ZfontsfontZlc_fontsZcurrent_font_indexrV   rV   rW   r     s,    
zFontPage.load_font_cfgc                 G   sZ   | j  }tddd| | j }tddd| | j }tddd| |   dS )zStore changes to font attributes.

        When one font attribute changes, save them all, as they are
        not independent from each other. In particular, when we are
        overriding the default font, we need to write out everything.
        r   r   r   z	font-sizez	font-boldN)r   r   r   
add_optionr   r   r   rS   paramsvaluerV   rV   rW   r     s    


zFontPage.var_changed_fontc                 C   s0   | j |jjdkrtnt}| j|  dS )zHandle selecting a font from the list.

        Event can result from either mouse click or Up or Down key.
        Set font_name and example displays to selection.
        Z
KeyReleaseN)	rP   r   typenamer   r   r   r   r   )rS   eventr   rV   rV   rW   r     s    zFontPage.on_fontlist_selectNc                 C   sH   | j  }| j rtjntj}|| j |f}|| jd< || jd< dS )zUpdate update both screen samples with the font settings.

        Called on font initialization and change events.
        Accesses font_name, font_size, and font_bold Variables.
        Updates font_sample and highlight page highlight_sample.
        r   N)	r   r   r   r   ZBOLDZNORMALr   r   r   )rS   r   r   Zfont_weightZnew_fontrV   rV   rW   r     s
    

zFontPage.set_samples)N)
r   r   r   rI   r   r   r   r   r   r   rV   rV   r   rW   rl      s   Y"
rl   c                       s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Z  ZS )+rj   c                    s:   t  | || _| | _t|| _|   |   d S r   )	r   rI   ri   winfo_toplevelcdr+   stylecreate_page_highlightload_theme_cfgrS   r   ri   r   rV   rW   rI     s    

zHighPage.__init__c                    s&  ddddddddd	d
ddddddd _ tt  j _tt  j _t  _	tt  j
 _tt  j _tt  j _t dtdd}t dtdd}t|tdd}|j } _|jddddtdtd |ddd  |dd d  d!}|D ]\}}|t|| qt|d"t }td|D ]0}	||	 d#|	tt | d$d%d& qH j D ].}
|
f fd'd(	}|! j |
 d d)| qd*|d+<  j"jd,dd-d. t#|d,d/ _$t#|}t% j$d0 j&d1 _'t( j$ jd2dd3 _)t*| j	dd4 j+d5 _,t*| j	dd6 j+d5 _- j	.d t%|d7 j/d1 _0t1|d8d9}t*| jd j2d:d; _3t*| jd j2d<d; _4t(| jd2d2d= _5t(| jd2d2d= _6t%|d> j7d1 _8t1|dd? _9|j:t;d@d@t<t=dA |j:t>d@d@t?dB  j$j:t>d@d@t?dB |j:t>d@ddC |j:t>d@d@t<t=dA  j'j:t>t<t?dDdEdF  j)j:t>t<t?dDdGdF  j,j:t;t@dH  j-j:tAtBdH  j0j:tCt?d@d@dI |j:t>tBd@d@dJ  j3j:t>tBd@dK  j4j:t>tBd@ddJ  j5j:t>t?d@d@dI  j6j:t>t?tBd@d@dL  j8j:t>t?d@d@dI  j9j:t>t?d@dM d2S )Na  Return frame of widgets for Highlights tab.

        Enable users to provisionally change foreground and background
        colors applied to textual tags.  Color mappings are stored in
        complete listings called themes.  Built-in themes in
        idlelib/config-highlight.def are fixed as far as the dialog is
        concerned. Any theme can be used as the base for a new custom
        theme, stored in .idlerc/config-highlight.cfg.

        Function load_theme_cfg() initializes tk variables and theme
        lists and calls paint_theme_sample() and set_highlight_target()
        for the current theme.  Radiobuttons builtin_theme_on and
        custom_theme_on toggle var theme_source, which controls if the
        current set of colors are from a builtin or custom theme.
        DynOptionMenus builtinlist and customlist contain lists of the
        builtin and custom themes, respectively, and the current item
        from each list is stored in vars builtin_name and custom_name.

        Function paint_theme_sample() applies the colors from the theme
        to the tags in text widget highlight_sample and then invokes
        set_color_sample().  Function set_highlight_target() sets the state
        of the radiobuttons fg_on and bg_on based on the tag and it also
        invokes set_color_sample().

        Function set_color_sample() sets the background color for the frame
        holding the color selector.  This provides a larger visual of the
        color for the current tag and plane (foreground/background).

        Note: set_color_sample() is called from many places and is often
        called more than once when a change is made.  It is invoked when
        foreground or background is selected (radiobuttons), from
        paint_theme_sample() (theme is changed or load_cfg is called), and
        from set_highlight_target() (target tag is changed or load_cfg called).

        Button delete_custom invokes delete_custom() to delete
        a custom theme from idleConf.userCfg['highlight'] and changes.
        Button save_custom invokes save_as_new_theme() which calls
        get_new_theme_name() and create_new() to save a custom theme
        and its colors to idleConf.userCfg['highlight'].

        Radiobuttons fg_on and bg_on toggle var fg_bg_toggle to control
        if the current selected color for a tag is for the foreground or
        background.

        DynOptionMenu targetlist contains a readable description of the
        tags applied to Python source within IDLE.  Selecting one of the
        tags from this list populates highlight_target, which has a callback
        function set_highlight_target().

        Text widget highlight_sample displays a block of text (which is
        mock Python code) in which is embedded the defined tags and reflects
        the color attributes of the current theme and changes for those tags.
        Mouse button 1 allows for selection of a tag and updates
        highlight_target with that tag value.

        Note: The font in highlight_sample is set through the config in
        the fonts tab.

        In other words, a tag can be selected either from targetlist or
        by clicking on the sample text within highlight_sample.  The
        plane (foreground/background) is selected via the radiobutton.
        Together, these two (tag and plane) control what color is
        shown in set_color_sample() for the current theme.  Button set_color
        invokes get_color() which displays a ColorChooser to change the
        color for the selected tag/plane.  If a new color is picked,
        it will be saved to changes and the highlight_sample and
        frame background will be updated.

        Tk Variables:
            color: Color of selected target.
            builtin_name: Menu variable for built-in theme.
            custom_name: Menu variable for custom theme.
            fg_bg_toggle: Toggle for foreground/background color.
                Note: this has no callback.
            theme_source: Selector for built-in or custom theme.
            highlight_target: Menu variable for the highlight tag target.

        Instance Data Attributes:
            theme_elements: Dictionary of tags for text highlighting.
                The key is the display name and the value is a tuple of
                (tag name, display sort order).

        Methods [attachment]:
            load_theme_cfg: Load current highlight colors.
            get_color: Invoke colorchooser [button_set_color].
            set_color_sample_binding: Call set_color_sample [fg_bg_toggle].
            set_highlight_target: set fg_bg_toggle, set_color_sample().
            set_color_sample: Set frame background to target.
            on_new_color_set: Set new color and add option.
            paint_theme_sample: Recolor sample.
            get_new_theme_name: Get from popup.
            create_new: Combine theme with changes and save.
            save_as_new_theme: Save [button_save_custom].
            set_theme_type: Command for [theme_source].
            delete_custom: Activate default [button_delete_custom].
            save_new: Save to userCfg['theme'] (is function).

        Widgets of highlights page frame:  (*) widgets bound to self
            frame_custom: LabelFrame
                (*)highlight_sample: Text
                (*)frame_color_set: Frame
                    (*)button_set_color: Button
                    (*)targetlist: DynOptionMenu - highlight_target
                frame_fg_bg_toggle: Frame
                    (*)fg_on: Radiobutton - fg_bg_toggle
                    (*)bg_on: Radiobutton - fg_bg_toggle
                (*)button_save_custom: Button
            frame_theme: LabelFrame
                theme_type_title: Label
                (*)builtin_theme_on: Radiobutton - theme_source
                (*)custom_theme_on: Radiobutton - theme_source
                (*)builtinlist: DynOptionMenu - builtin_name
                (*)customlist: DynOptionMenu - custom_name
                (*)button_delete_custom: Button
                (*)theme_message: Label
        )normalZ00)contextZ01)keywordZ02)
definitionZ03)builtinZ04)commentZ05)stringZ06)hiliteZ07)hitZ08)cursorZ09)breakr   )consoler   )errorr   )stdoutr   )stderrr   )
linenumberr   )zNormal Code or TextzCode ContextzPython KeywordszPython DefinitionszPython BuiltinszPython CommentszPython StringszSelected Textz
Found TextCursorzEditor BreakpointzShell Promptz
Error TextzShell User OutputzShell User ExceptionzLine Numberru   z Custom Highlighting r   z Highlighting Theme r   )r   rz   )Zcourier   r?   Zhand2r   )r   r   rH   rG   rw   highlightthicknessr   z<Double-Button-1>c                 S   s   dS Nr   rV   erV   rV   rW   <lambda>u  r   z0HighPage.create_page_highlight.<locals>.<lambda>z<B1-Motion>c                 S   s   dS r   rV   r  rV   rV   rW   r  v  r   )")z# Click selects item.r   
r   )zcode context sectionr   r  )z| cursorr   r  )defr   ) r   )funcr   )z(param):
  r   )z"Return None."r   )z

  var0 = r   )z'string'r   )z

  var1 = r   )z
'selected'r   )z

  var2 = r   )z'found'r   )z

  var3 = r   )listr   )(r   )Noner   )z)
r   )z  breakpoint("line")r   )z

r   z>>>r   )z	 3.14**2
r   )z9.8596r   r  r  )z pri r   )nr   )zt(
r   )SyntaxErrorr   r  r   z.0dr  r   c                    s    j | d S r   )highlight_targetr   )r   elemr   rV   rW   tem  s    z+HighPage.create_page_highlight.<locals>.temz<ButtonPress-1>disabledstateframe_color_set.TFrameZsolid)rz   r   )r   zChoose Color for :r]   rv   N)r   Z
Foreground)r   r   r]   rv   Z
BackgroundzSave as New Custom Themez	Select : r\   za Built-in Themer   r   rv   r]   za Custom Themer   zDelete Custom Themerz   rx   ra   ry   r   rb   rc   r   ra   ry   r         )ra   rb   rc   ry   r   rt   r   ra   rc   ry   r   ra   r   ry   r   r   )ra   rc   r   ry   r   )ra   rc   r   )Dtheme_elementsrQ   rp   r   var_changed_builtin_namebuiltin_namevar_changed_custom_namecustom_namer   fg_bg_togglevar_changed_colorcolorvar_changed_theme_sourcetheme_sourcevar_changed_highlight_targetr  r"   r   r=   r   r]   r   	configurer
   r   r   r   r   lenr   
splitlinesrangestrZtag_bindr   r!   frame_color_setr#   	get_colorZbutton_set_colorr3   
targetlistr)   set_color_sample_bindingfg_onbg_onr   save_as_new_themeZbutton_save_customr&   set_theme_typeZbuiltin_theme_oncustom_theme_onbuiltinlist
customlistdelete_custombutton_delete_customtheme_messagerq   r   r	   r   r   r   r   r   r   r   )rS   frame_customZframe_themeZsample_framer]   Zstring_tagsr   tagZn_lineslinenoelementr  Zframe_fg_bg_toggleZtheme_type_titlerV   r   rW   r     s   v











zHighPage.create_page_highlightc              	      s.   j tjdddddd t } j  rtdd}|   j	|| tdd}|  |s j
d	  jd
 qވ j	||d  nHtdd}|   j	|| tdd}|   j	||d     t j }|j fddd  j	||d        dS )a  Load current configuration settings for the theme options.

        Based on the theme_source toggle, the theme is set as
        either builtin or custom and the initial widget values
        reflect the current settings from idleConf.

        Attributes updated:
            theme_source: Set from idleConf.
            builtinlist: List of default themes from idleConf.
            customlist: List of custom themes from idleConf.
            custom_theme_on: Disabled if there are no custom themes.
            custom_theme: Message with additional information.
            targetlist: Create menu from self.theme_elements.

        Methods:
            set_theme_type
            paint_theme_sample
            set_highlight_target
        r   Themedefaultboolr   r   rB  	highlightuserr  - no custom themes -r   c                    s    j |  d S )Nr   )r  )rT   r   rV   rW   r    r   z)HighPage.load_theme_cfg.<locals>.<lambda>)keyN)r(  r   r0   	GetOptionZCurrentThemer   GetSectionListsortr8  r   r7  r  r#  r9  r6  r	  r  r   r1  paint_theme_sampleset_highlight_target)rS   current_option	item_listZtheme_namesrV   r   rW   r     s4    


zHighPage.load_theme_cfgc                 G   s   d}| j  }||vrXtddd|vr<tddd|d  tddd| d| jd< n*tddd| tdddd	 d	| jd< |   d
S )zProcess new builtin theme selection.

        Add the changed theme's name to the changed_items and recreate
        the sample with the values from the selected theme.
        )zIDLE ClassiczIDLE Newr   rA  r   r   name2zNew theme, see Helpr]   r?   N)r!  r   r0   rJ  r   r   r<  rM  )rS   r   Z
old_themesr   rV   rV   rW   r     s    

z!HighPage.var_changed_builtin_namec                 G   s.   | j  }|dkr*tddd| |   dS )zProcess new custom theme selection.

        If a new custom theme is selected, add the name to the
        changed_items and apply the theme to the sample.
        rH  r   rA  r   N)r#  r   r   r   rM  r   rV   rV   rW   r"    s    
z HighPage.var_changed_custom_namec                 G   s4   | j  }tddd| |r(|   n|   dS )zProcess toggle between builtin and custom theme.

        Update the default toggle value and apply the newly
        selected theme type.
        r   rA  rB  N)r(  r   r   r   r   r"  r   rV   rV   rW   r'  $  s
    

z!HighPage.var_changed_theme_sourcec                 G   s   |    dS )zProcess change to color choice.N)on_new_color_setrS   r   rV   rV   rW   r%  1  s    zHighPage.var_changed_colorc                 G   s   |    dS )z5Process selection of new target tag for highlighting.N)rN  rS  rV   rV   rW   r)  5  s    z%HighPage.var_changed_highlight_targetc                 C   s\   | j  r,d| jd< d| jd< | jd n,d| jd< | jd d| jd< | jd dS )a  Set available screen options based on builtin or custom theme.

        Attributes accessed:
            theme_source

        Attributes updated:
            builtinlist
            customlist
            button_delete_custom
            custom_theme_on

        Called from:
            handler for builtin_theme_on and custom_theme_on
            delete_custom
            create_new
            load_theme_cfg
        r   r  r  rG  z	!disabledN)r(  r   r8  r9  r;  r  r7  r   rV   rV   rW   r6  9  s    




zHighPage.set_theme_typec                 C   s   | j  }| j| jd d}tj| d| |d\}}|r||kr| j rzd}| |}|sbdS | 	| | j
| n| j
| dS )a  Handle button to select a new color for the target tag.

        If a new color is selected while using a builtin theme, a
        name must be supplied to create a custom theme.

        Attributes accessed:
            highlight_target
            frame_color_set
            theme_source

        Attributes updated:
            color

        Methods:
            get_new_theme_name
            create_new
        r   
backgroundzPick new color for : )rJ   rL   Zinitialcolorz_Your changes will be saved as a new Custom Theme. Enter a name for your new Custom Theme below.N)r  r   r   lookupr/  r.   Zaskcolorr(  get_new_theme_name
create_newr&  r   )rS   targetZ
prev_colorZ	rgbTupletZcolor_stringmessage	new_themerV   rV   rW   r0  U  s"    




zHighPage.get_colorc                 C   s   | j  }| jjd|d | j r(dnd}| j| j  d }| jj|fi ||i | j	 }|d | }t
d||| dS )	z4Display sample of new color selection on the dialog.r  rU  
foregroundrU  r   -rE  N)r&  r   r   r*  r$  r  r  r   
tag_configr#  r   r   )rS   Z	new_colorplaneZsample_elementthemeZtheme_elementrV   rV   rW   rR  {  s    

zHighPage.on_new_color_setc                 C   s,   t ddt dd }t| d||j}|S )z*Return name of new theme from query popup.rF  rE  rB  zNew Custom Themer0   rK  r5   result)rS   rZ  
used_namesr[  rV   rV   rW   rW    s    

zHighPage.get_new_theme_namec                 C   s   |  d}|r| | dS )zPrompt for new theme name and create the theme.

        Methods:
            get_new_theme_name
            create_new
        zNew Theme Name:N)rW  rX  )rS   new_theme_namerV   rV   rW   r5    s    
zHighPage.save_as_new_themec                 C   s   | j  rd}| j }nd}| j }t||}|td v rbtd | }|D ]}|| ||< qP| || tdd}|	  | j
|| | j d |   dS )a  Create a new custom theme with the given name.

        Create the new theme based on the previously active theme
        with the current changes applied.  Once it is saved, then
        activate the new theme.

        Attributes accessed:
            builtin_name
            custom_name

        Attributes updated:
            customlist
            theme_source

        Method:
            save_new
            set_theme_type
        rB  rF  rE  r   N)r(  r   r!  r#  r0   ZGetThemeDictr   save_newrK  rL  r9  r   r   r6  )rS   re  Z
theme_type
theme_namer[  Ztheme_changesr@  Zcustom_theme_listrV   rV   rW   rX    s     

zHighPage.create_newc                 C   sd   | j  dkr4| jd | jd | jd n$| jd | jd | jd |   dS )ah  Set fg/bg toggle and color based on highlight tag target.

        Instance variables accessed:
            highlight_target

        Attributes updated:
            fg_on
            bg_on
            fg_bg_toggle

        Methods:
            set_color_sample

        Called from:
            var_changed_highlight_target
            load_theme_cfg
        r   rG  r   rT  N)r  r   r3  r  r4  r$  r   set_color_sampler   rV   rV   rW   rN    s    zHighPage.set_highlight_targetc                 G   s   |    dS )zrChange color sample based on foreground/background toggle.

        Methods:
            set_color_sample
        N)rh  )rS   argsrV   rV   rW   r2    s    z!HighPage.set_color_sample_bindingc                 C   sH   | j | j  d }| j r"dnd}| j||}| jjd|d dS )a  Set the color of the frame background to reflect the selected target.

        Instance variables accessed:
            theme_elements
            highlight_target
            fg_bg_toggle
            highlight_sample

        Attributes updated:
            frame_color_set
        r   r]  rU  r  r\  N)r  r  r   r$  r   Ztag_cgetr   r*  )rS   r>  r`  r&  rV   rV   rW   rh    s    zHighPage.set_color_samplec                 C   s   | j  r| j }n
| j }| jD ]}| j| d }t||}|dkr`t|dd |d< |td v rtd | }|d |v r||d  |d< |d |v r||d  |d< | jj	|fi | q&| 
  d	S )
a  Apply the theme colors to each element tag in the sample text.

        Instance attributes accessed:
            theme_elements
            theme_source
            builtin_name
            custom_name

        Attributes updated:
            highlight_sample: Set the tag elements to the theme.

        Methods:
            set_color_sample

        Called from:
            var_changed_builtin_name
            var_changed_custom_name
            load_theme_cfg
        r   r   r   rU  rE  z-foregroundr]  z-backgroundN)r(  r   r!  r#  r  r0   ZGetHighlightr   r   r_  rh  )rS   ra  Zelement_titler@  ZcolorsZ
theme_dictrV   rV   rW   rM    s(    


zHighPage.paint_theme_samplec                 C   s:   t jd | |D ] }|| }t jd ||| qdS )zSave a newly created theme to idleConf.

        theme_name - string, the name of the new theme
        theme - dictionary containing the new theme
        rE  Nr0   userCfgZ
AddSection	SetOption)rS   rg  ra  r@  r   rV   rV   rW   rf    s    zHighPage.save_newc                 O   s   t j|i |S r   r/   askyesnorS   ri  kwargsrV   rV   rW   rn  *  s    zHighPage.askyesnoc                 C   s   | j  }d}| jd|| | ds&dS | j  td| tdd}|	  |sp| j
d | j|d n| j||d	  | jtjd
 dd | jtjd
 dd t  | j  | j  |   dS )a!  Handle event to delete custom theme.

        The current theme is deactivated and the default theme is
        activated.  The custom theme is permanently removed from
        the config file.

        Attributes accessed:
            custom_name

        Attributes updated:
            custom_theme_on
            customlist
            theme_source
            builtin_name

        Methods:
            deactivate_current_config
            save_all_changed_extensions
            activate_config_changes
            set_theme_type
        z.Are you sure you wish to delete the theme %r ?zDelete ThemerJ   NrE  rF  rG  rH  r   r   rA  rB  r   )r#  r   rn  r   r   r   delete_sectionr0   rK  rL  r7  r  r9  r   r(  r   
defaultCfgGetr!  r   ri   r   r   r6  )rS   rg  delmsgrP  rV   rV   rW   r:  .  s(    




zHighPage.delete_custom)r   r   r   rI   r   r   r   r"  r'  r%  r)  r6  r0  rR  rW  r5  rX  rN  r2  rh  rM  rf  rn  r:  r   rV   rV   r   rW   rj     s.      4&((rj   c                       s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zedd Zdd  Zd!d" Z  ZS )#rm   c                    s0   t  | || _| | _|   |   d S r   )r   rI   ri   r   r   create_page_keysload_key_cfgr   r   rV   rW   rI   `  s
    
zKeysPage.__init__c                    s"  t t| | j| _t t| | j| _t t| | j| _	t t| | j
| _t| dtdd}t| dtdd t|}t|dd}t|}t|td}t|ttd| _| jd	| j | jj|d
< | jj|d
< |j| jd< |j| jd< t|d| jdd| _ fddtdD }t|d | j	d| jdd| _ t|d | j	d| jdd| _!t"|d | jddd| _#t"|d | jddd| _$t|d d| j%d| _&t|d d| j'd| _(t|d dd| _)|j*t+ddt,t-d  j*t+ddt-d | jj*t+t.ddd  |j*t/ddt,t-d |j0ddd! |j1ddd! |j2dddt3d" | jj2ddt4d# |j2ddt5d# |j2ddt6d# | j j2ddt3t5 d# | j!j2ddt3t5 d# | j#j2ddt4d# | j$j2ddt4d# | j)j2ddt4ddd$ | j&j*t/t.d%dd& | j(j*t/t.d%dd& |d j*t7t-d%d' |d j*t7t.d%dd( dS ))a  Return frame of widgets for Keys tab.

        Enable users to provisionally change both individual and sets of
        keybindings (shortcut keys). Except for features implemented as
        extensions, keybindings are stored in complete sets called
        keysets. Built-in keysets in idlelib/config-keys.def are fixed
        as far as the dialog is concerned. Any keyset can be used as the
        base for a new custom keyset, stored in .idlerc/config-keys.cfg.

        Function load_key_cfg() initializes tk variables and keyset
        lists and calls load_keys_list for the current keyset.
        Radiobuttons builtin_keyset_on and custom_keyset_on toggle var
        keyset_source, which controls if the current set of keybindings
        are from a builtin or custom keyset. DynOptionMenus builtinlist
        and customlist contain lists of the builtin and custom keysets,
        respectively, and the current item from each list is stored in
        vars builtin_name and custom_name.

        Button delete_custom_keys invokes delete_custom_keys() to delete
        a custom keyset from idleConf.userCfg['keys'] and changes.  Button
        save_custom_keys invokes save_as_new_key_set() which calls
        get_new_keys_name() and create_new_key_set() to save a custom keyset
        and its keybindings to idleConf.userCfg['keys'].

        Listbox bindingslist contains all of the keybindings for the
        selected keyset.  The keybindings are loaded in load_keys_list()
        and are pairs of (event, [keys]) where keys can be a list
        of one or more key combinations to bind to the same event.
        Mouse button 1 click invokes on_bindingslist_select(), which
        allows button_new_keys to be clicked.

        So, an item is selected in listbindings, which activates
        button_new_keys, and clicking button_new_keys calls function
        get_new_keys().  Function get_new_keys() gets the key mappings from the
        current keyset for the binding event item that was selected.  The
        function then displays another dialog, GetKeysDialog, with the
        selected binding event and current keys and allows new key sequences
        to be entered for that binding event.  If the keys aren't
        changed, nothing happens.  If the keys are changed and the keyset
        is a builtin, function get_new_keys_name() will be called
        for input of a custom keyset name.  If no name is given, then the
        change to the keybinding will abort and no updates will be made.  If
        a custom name is entered in the prompt or if the current keyset was
        already custom (and thus didn't require a prompt), then
        idleConf.userCfg['keys'] is updated in function create_new_key_set()
        with the change to the event binding.  The item listing in bindingslist
        is updated with the new keys.  Var keybinding is also set which invokes
        the callback function, var_changed_keybinding, to add the change to
        the 'keys' or 'extensions' changes tracker based on the binding type.

        Tk Variables:
            keybinding: Action/key bindings.

        Methods:
            load_keys_list: Reload active set.
            create_new_key_set: Combine active keyset and changes.
            set_keys_type: Command for keyset_source.
            save_new_key_set: Save to idleConf.userCfg['keys'] (is function).
            deactivate_current_config: Remove keys bindings in editors.

        Widgets for KeysPage(frame):  (*) widgets bound to self
            frame_key_sets: LabelFrame
                frames[0]: Frame
                    (*)builtin_keyset_on: Radiobutton - var keyset_source
                    (*)custom_keyset_on: Radiobutton - var keyset_source
                    (*)builtinlist: DynOptionMenu - var builtin_name,
                            func keybinding_selected
                    (*)customlist: DynOptionMenu - var custom_name,
                            func keybinding_selected
                    (*)keys_message: Label
                frames[1]: Frame
                    (*)button_delete_custom_keys: Button - delete_custom_keys
                    (*)button_save_custom_keys: Button -  save_as_new_key_set
            frame_custom: LabelFrame
                frame_target: Frame
                    target_title: Label
                    scroll_target_y: Scrollbar
                    scroll_target_x: Scrollbar
                    (*)bindingslist: ListBox - on_bindingslist_select
                    (*)button_new_keys: Button - get_new_keys & ..._name
        ru   z Custom Key Bindings r   z	 Key Set zAction - Key(s)r\   Zorient)rw   r   r   rv   r   ZxscrollcommandzGet New Keys for Selectionr  )r]   rv   r  c                    s   g | ]}t  d ddqS )ru   r   )rY   rz   )r!   )r   iZframe_key_setsrV   rW   r     s   z-KeysPage.create_page_keys.<locals>.<listcomp>r   r   zUse a Built-in Key Setr  zUse a Custom Key SetNr   zDelete Custom Key Setr  zSave as New Custom Key Setr  rx   r  r   r  r   )r   r   Z
columnspanrZ   r   r   rZ   )r   r   rZ   ry   r   T)ra   rc   rb   ry   ra   rc   rb   )ra   rc   rb   r   )8rQ   rp   r   r   r!  r"  r#  r   var_changed_keyset_sourcekeyset_sourcevar_changed_keybinding
keybindingr"   r   r!   r&   r*   r   r   r
   bindingslistr   on_bindingslist_selectr   Zxviewr   r#   get_new_keysbutton_new_keysr-  r)   set_keys_typeZbuiltin_keyset_oncustom_keyset_onr3   r8  r9  delete_custom_keysbutton_delete_custom_keyssave_as_new_key_setZbutton_save_custom_keyskeys_messagerq   r   r	   r   r   r   r   r   rf   r   r   r   r   r   )rS   r=  Zframe_targetZtarget_titleZscroll_target_yZscroll_target_xZframesrV   rz  rW   rv  g  s    R




zKeysPage.create_page_keysc              	   C   s   | j tjdddddd t }| j  rtdd}|  | j	|| tdd}|  |s| j
d	 | jd
 q| j	||d  nHtdd}|  | j	|| tdd}|  | j	|t  |   t }| | dS )z?Load current configuration settings for the keybinding options.r   KeysrB  rC  r   rD  r   rF  rG  - no custom keys -r   N)r~  r   r0   rJ  ZCurrentKeysr   rK  rL  r8  r   r  r  r#  r9  default_keysr  load_keys_list)rS   rO  rP  keyset_namerV   rV   rW   rw    s.    


zKeysPage.load_key_cfgc                 G   s   d}| j  }||vrXtddd|vr<tddd|d  tddd| d| jd< n*tddd| tdddd	 d	| jd< | | d
S )z%Process selection of builtin key set.)zIDLE Classic WindowszIDLE Classic UnixzIDLE Classic MaczIDLE Classic OSXr   r  r   r   rQ  zNew key set, see Helpr]   r?   N)r!  r   r0   rJ  r   r   r  r  )rS   r   Zold_keysr   rV   rV   rW   r   &  s    

z!KeysPage.var_changed_builtin_namec                 G   s0   | j  }|dkr,tddd| | | dS )z$Process selection of custom key set.r  r   r  r   N)r#  r   r   r   r  r   rV   rV   rW   r"  :  s    
z KeysPage.var_changed_custom_namec                 G   s4   | j  }tddd| |r(|   n|   dS )z:Process toggle between builtin key set and custom key set.r   r  rB  N)r~  r   r   r   r   r"  r   rV   rV   rW   r}  A  s
    

z"KeysPage.var_changed_keyset_sourcec                 G   sj   | j  }| j }| jt d }t|rDt	d||| n"t
|}|d }t	d||| dS )zStore change to a keybinding.r   r   Z_cfgBindings
extensionsN)r  r   r#  r  r   splitr0   ZIsCoreBindingr   r   ZGetExtnNameForEvent)rS   r   r   Zkey_setr   ext_nameZext_keybind_sectionrV   rV   rW   r  J  s    



zKeysPage.var_changed_keybindingc                 C   s\   | j  r,d| jd< d| jd< | jd n,d| jd< | jd d| jd< | jd dS )z@Set available screen options based on builtin or custom key set.r   r  r  rG  rT  N)r~  r   r8  r9  r  r  r  r   rV   rV   rW   r  V  s    




zKeysPage.set_keys_typec                 C   sF  | j t}| j |}| d }| j r:| j }n
| j }t	 }|t
d v r~t
d | }|D ]}||  ||< qht| }t| d||j}	|	r*| j rd}
| |
}|s| j | | j | dS | | | j | | j ||d |	  | j | | j | | j|	 n| j | | j | dS )a^  Handle event to change key binding for selected line.

        A selection of a key/binding in the list of current
        bindings pops up a dialog to enter a new binding.  If
        the current key set is builtin and a binding has
        changed, then a name for a custom key set needs to be
        entered for the change to be applied.
        r   r   zGet New KeyszcYour changes will be saved as a new Custom Key Set. Enter a name for your new Custom Key Set below.N - )r  r   r   r   r  r~  r!  r#  r0   ZGetCurrentKeySetr   r	  valuesr2   rc  get_new_keys_namer   r   create_new_key_setdeleter   r  r   )rS   
list_indexbinding	bind_nameZcurrent_key_set_nameZcurrent_bindingskey_set_changesr   Zcurrent_key_sequencesnew_keysrZ  
new_keysetrV   rV   rW   r  b  s>    	




zKeysPage.get_new_keysc                 C   s,   t ddt dd }t| d||j}|S )z)Return new key set name from query popup.rF  r   rB  zNew Custom Key Setrb  )rS   rZ  rd  r  rV   rV   rW   r    s    

zKeysPage.get_new_keys_namec                 C   s   |  d}|r| | dS )z@Prompt for name of new key set and save changes using that name.zNew Key Set Name:N)r  r  )rS   Znew_keys_namerV   rV   rW   r    s    
zKeysPage.save_as_new_key_setc                 C   s   | j d dS )z6Activate button to assign new keys to selected action.rT  N)r  r  rS   r   rV   rV   rW   r    s    zKeysPage.on_bindingslist_selectc           
      C   s   | j  r| j }n
| j }t|}i }|D ]&}|dd }d|| }|||< q2|td v rtd | }|D ]}|| ||< qv| || t	dd}	|	
  | j|	| | j d |   dS )zCreate a new custom key set with the given name.

        Copy the bindings/keys from the previously active keyset
        to the new keyset and activate the new custom keyset.
        ru   r  r   rF  r   N)r~  r   r!  r#  r0   ZGetCoreKeysjoinr   save_new_key_setrK  rL  r9  r   r   r  )
rS   Znew_key_set_nameZprev_key_set_nameZ	prev_keysr  r   Z
event_namer  r  Zcustom_key_listrV   rV   rW   r    s&    



zKeysPage.create_new_key_setc                 C   s   d}| j  rd}| j t}t|}t| }|  | j 	dt
 |D ]`}d|| }|dd }|td v r|td | v rtd | | }| j t
|d |  qN|r| j | | j | | j | d	S )
zReload the list of action/key binding pairs for the active key set.

        An action/key binding can be selected to change the key binding.
        FTr   r  ru   r  r   r  N)r  curselectionr   r   r0   Z	GetKeySetr	  r   rL  r  r   r  r   r   r   r   r   )rS   r  Zreselectr  keysetZ
bind_namesr  rI  rV   rV   rW   r    s&    

zKeysPage.load_keys_listc                 C   s:   t jd |  |D ] }|| }t jd | || qdS )aQ  Save a newly created core key set.

        Add keyset to idleConf.userCfg['keys'], not to disk.
        If the keyset doesn't exist, it is created.  The
        binding/keys are taken from the keyset argument.

        keyset_name - string, the name of the new key set
        keyset - dictionary containing the new keybindings
        r   Nrj  )r  r  r   r   rV   rV   rW   r    s    zKeysPage.save_new_key_setc                 O   s   t j|i |S r   rm  ro  rV   rV   rW   rn    s    zKeysPage.askyesnoc                 C   s   | j  }d}| jd|| | ds&dS | j  td| tdd}|	  |sp| j
d | j|d n| j||d	  | jtjd
 dd | jtjd
 ddpt  t  | j  | j  |   dS )zHandle event to delete a custom key set.

        Applying the delete deactivates the current configuration and
        reverts to the default.  The custom key set is permanently
        deleted from the config file.
        z0Are you sure you wish to delete the key set %r ?zDelete Key Setrq  Nr   rF  rG  r  r   r   r  rB  r   )r#  r   rn  r   r   r   rr  r0   rK  rL  r  r  r9  r   r~  r   rs  rt  r!  r  r   ri   r   r   r  )rS   r  ru  rP  rV   rV   rW   r    s0    




zKeysPage.delete_custom_keys)r   r   r   rI   rv  rw  r   r"  r}  r  r  r  r  r  r  r  r  staticmethodr  rn  r  r   rV   rV   r   rW   rm   ^  s&    !	,
rm   c                       s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	rn   c                    s(   t  | |   |   |   d S r   )r   rI   init_validatorscreate_page_windowsload_windows_cfgrS   r   r   rV   rW   rI     s    zWinPage.__init__c                    s*   t d  fdd}| |df| _d S )N[0-9]*c                    s     | duS z+Return 's is blank or contains only digits'N	fullmatchr   Zdigits_or_empty_rerV   rW   is_digits_or_empty  s    z3WinPage.init_validators.<locals>.is_digits_or_empty%Precompileregisterdigits_onlyrS   r  rV   r  rW   r    s    
zWinPage.init_validatorsc                 C   s  t t| d| _t t| d| _t t| d| _t t| d| _t t| d| _	t t| d| _
t t| d| _t t| d| _t t| d	| _t t| d
| _t| dtdd}t|dd}t|dd}t|| jddd| _t|| jddd| _t|dd}t|dd}t|dd}t|| jd| jdd| _t|dd}t|| jd| jdd| _t|dd}t|dd}	z t|| jddd| jdd| _W n4 ty   t|| jdttdd dd!| _Y n0 t|d"d}
t |d#| j	d$| _!t|dd}t|d%d}t|| j
d&| jdd| _"t|dd}t|d'd}t#|| jd(d)d*d(| _$t|dd}t|d+d}t|| jd&| jdd| _%t |d,| jd$| _&t|dd}t|d-d}t|| jd.| jdd| _'|j(t)d/d/t*t+d0 |j(t)d/dt,d1 |j(t-t.d/d/d2 | jj(t/t.d/d/d2 | jj(t/t.d/d/d2 |j(t)d/dt,d1 |j(t-t.d/d/d2 | jj(t/t0dd/d2 |j(t/t0d/d3 | jj(t/t0dd/d2 |j(t/t0d/d3 |j(t)d/dt,d1 |	j(t-t.d/d4 | jj(t-t.dd4 | j!j(t/t0d5d/d2 |j(t)d/dt,d1 |j(t-t.d/d/d2 | j"j(t)dd/d6 |j(t)d/dt,d1 |j(t-t.d/d/d2 | j$j(t)dd/d6 |j(t)d/dt,d1 |j(t-t.d/d4 | j&j(t/t0d5d/d2 | j%j(t)t.d5d/d2 |j(t)d/dt,d1 |j(t-t.d/d/d2 | j'j(t)dd/d6 d7S )8aD  Return frame of widgets for Windows tab.

        Enable users to provisionally change general window options.
        Function load_windows_cfg initializes tk variable idleConf.
        Radiobuttons startup_shell_on and startup_editor_on set var
        startup_edit. Entry boxes win_width_int and win_height_int set var
        win_width and win_height.  Setting var_name invokes the default
        callback that adds option to changes.

        Widgets for WinPage(Frame):  > vars, bound to self
            frame_window: LabelFrame
                frame_run: Frame
                    startup_title: Label
                    startup_editor_on: Radiobutton > startup_edit
                    startup_shell_on: Radiobutton > startup_edit
                frame_win_size: Frame
                    win_size_title: Label
                    win_width_title: Label
                    win_width_int: Entry > win_width
                    win_height_title: Label
                    win_height_int: Entry > win_height
                frame_cursor: Frame
                    indent_title: Label
                    indent_chooser: Spinbox (Combobox < 8.5.9) > indent_spaces
                    blink_on: Checkbutton > cursor_blink
                frame_autocomplete: Frame
                    auto_wait_title: Label
                    auto_wait_int: Entry > autocomplete_wait
                frame_paren1: Frame
                    paren_style_title: Label
                    paren_style_type: OptionMenu > paren_style
                frame_paren2: Frame
                    paren_time_title: Label
                    paren_flash_time: Entry > flash_delay
                    bell_on: Checkbutton > paren_bell
                frame_format: Frame
                    format_width_title: Label
                    format_width_int: Entry > format_width
        )r   Generaleditor-on-startup)r   r   rH   )r   r   rG   )r   Indent
num-spaces)r   r   cursor-blink)r  r8   	popupwait)r  r:   r   )r  r:   flash-delay)r  r:   bell)r  r;   	max-widthru   z Window Preferencesr   r   r  z
At Startupr\   r   zOpen Edit Windowr   r   r]   zOpen Shell Windowz$Initial Window Size  (in characters)ZWidthrt   rI  textvariablerH   validatecommandvalidateZHeightzIndent spaces (4 is standard)
   )r  Zfrom_torH   r  r  readonly   )r  r  r  rH   zCursor BlinkzCursor blink)r]   r   z%Completions Popup Wait (milliseconds)rs   zParen Match StyleZ
expressionZopenerZparensz;Time Match Displayed (milliseconds)
(0 is until next input)zBell on MismatchzFormat Paragraph Max Widthr  rx   r  r   r  ra   r   r   r   r   r  N)1rQ   rp   r   startup_editr   	win_width
win_heightindent_spacesr   cursor_blinkautocomplete_waitparen_styleflash_delay
paren_bellformat_widthr"   r   r!   r&   r)   Zstartup_editor_onZstartup_shell_onr%   r  Zwin_width_intZwin_height_intr,   Zindent_chooserr    r-   r	  r-  r$   Zcursor_blink_boolZauto_wait_intr'   Zparen_style_typeZparen_flash_timeZbell_onZformat_width_intrq   r   r	   r   r   r   r   r   r   )rS   Zframe_windowZ	frame_runZstartup_titleZframe_win_sizeZwin_size_titleZwin_width_titleZwin_height_titleZframe_cursorZindent_titleZcursor_blink_titleZframe_autocompleteZauto_wait_titleZframe_paren1Zparen_style_titleZframe_paren2Zparen_time_titleZframe_formatZformat_width_titlerV   rV   rW   r    s   )zWinPage.create_page_windowsc                 C   s   | j tjddddd | jtjddddd | jtjddd	dd | jtjdd
ddd | jtjddddd | jtjddddd | j	tddd | j
tjddddd | jtddd | jtjddddd d S )Nr   r  r  rC  r   r   rH   intrG   r  r  r  r  r8   r  r:   r   r  r  r;   r  )r  r   r0   rJ  r  r  r  r  r  r  r  r  r  r   rV   rV   rW   r    s<    









zWinPage.load_windows_cfg)r   r   r   rI   r  r  r  r   rV   rV   r   rW   rn     s
    +rn   c                       s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	ro   c                    s(   t  | |   |   |   d S r   )r   rI   r  create_page_shedload_shelled_cfgr  r   rV   rW   rI     s    zShedPage.__init__c                    s*   t d  fdd}| |df| _d S )Nr  c                    s     | duS r  r  r  r  rV   rW   r    s    z4ShedPage.init_validators.<locals>.is_digits_or_emptyr  r  r  rV   r  rW   r    s    
zShedPage.init_validatorsc                 C   sT  t t| d| _t t| d| _t t| d| _t t| d| _t	| dt
dd}t	| dt
dd}t|d	d
}t|dd}t|d| j| jdd| _t|d	d
}t|dd}t|| jd	dd| _t|| jddd| _t|d	d
}t|dd}t|| jdd| _t|d	d
}	t|	dd}
t|	| jd| jdd| _|jtddtd t|   |jtddtd |jtdd	td |jttddd | jjtddd |jtdd	td |jttddd | jjttddd | jjttddd |jtdd	td |jttddd | jjtddd |	jtdd	td |
jttddd | jjtddd dS )ac  Return frame of widgets for Shell/Ed tab.

        Enable users to provisionally change shell and editor options.
        Function load_shed_cfg initializes tk variables using idleConf.
        Entry box auto_squeeze_min_lines_int sets
        auto_squeeze_min_lines_int.  Setting var_name invokes the
        default callback that adds option to changes.

        Widgets for ShedPage(Frame):  (*) widgets bound to self
            frame_shell: LabelFrame
                frame_auto_squeeze_min_lines: Frame
                    auto_squeeze_min_lines_title: Label
                    (*)auto_squeeze_min_lines_int: Entry -
                       auto_squeeze_min_lines
            frame_editor: LabelFrame
                frame_save: Frame
                    run_save_title: Label
                    (*)save_ask_on: Radiobutton - autosave
                    (*)save_auto_on: Radiobutton - autosave
                frame_format: Frame
                    format_width_title: Label
                    (*)format_width_int: Entry - format_width
                frame_line_numbers_default: Frame
                    line_numbers_default_title: Label
                    (*)line_numbers_default_bool: Checkbutton - line_numbers_default
                frame_context: Frame
                    context_title: Label
                    (*)context_int: Entry - context_lines
        )r   PyShellauto-squeeze-min-lines)r   r  autosave)r   r   line-numbers-default)r  r9   maxlinesru   z Shell Preferencesr   z Editor Preferencesr   r  zAuto-Squeeze Min. Lines:r\   r  rI  )rH   r  r  r  zAt Start of Run (F5)  zPrompt to Saver  r   z	No Promptz Show line numbers in new windows)r   rH   zMax Context Lines :rt   r  rx   r   r  r  N)rQ   rp   r   auto_squeeze_min_linesr   r  r   line_numbers_defaultcontext_linesr"   r   r!   r&   r%   r  Zauto_squeeze_min_lines_intr)   Zsave_ask_onZsave_auto_onr$   Zline_numbers_default_boolZcontext_intrq   r   r   r   r   r   r   )rS   Zframe_shellZframe_editorZframe_auto_squeeze_min_linesZauto_squeeze_min_lines_titleZ
frame_saveZrun_save_titleZframe_line_numbers_defaultZline_numbers_default_titleZframe_contextZcontext_titlerV   rV   rW   r    s    zShedPage.create_page_shedc              	   C   sn   | j tjddddd | jtjddddd	d
 | jtjdddd	d | jtjddddd d S )Nr   r  r  r  r  r  r  r   rC  )rB  r   r   r  r  r9   r  )r  r   r0   rJ  r  r  r  r   rV   rV   rW   r  Y  s    




zShedPage.load_shelled_cfg)r   r   r   rI   r  r  r  r   rV   rV   r   rW   ro     s   hro   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )rh   c                    sD   t  | tjd | _tjd | _| t| _| 	  | 
  d S )Nr  )r   rI   r0   rs  ext_defaultCfgrk  ext_userCfgr  is_intload_extensionscreate_page_extensionsr  r   rV   rW   rI   g  s    zExtPage.__init__c                 C   s~  t | | _t| dtdd}t| dtdd| _|jddd |jddd t|| jdd	| _	| j	
d
| j t|| j	jd}|j| j	_t|ddd| _| j	jdddd |jdddd | jjdddddgd |jdd i | _d| _| | _| j	| _d}t| jD ] }| | |d | d }q| j| | j	d | d |jdddd t| jddd | jjdddd dS )a  Configure IDLE feature extensions and help menu extensions.

        List the feature extensions and a configuration box for the
        selected extension.  Help menu extensions are in a HelpFrame.

        This code reads the current configuration using idleConf,
        supplies a GUI interface to change the configuration values,
        and saves the changes using idleConf.

        Some changes may require restarting IDLE.  This depends on each
        extension's implementation.

        All values are treated as text, and it is up to the user to
        supply reasonable values. The only exception to this are the
        'enable*' options, which are boolean, and can be toggled with a
        True/False button.

        Methods:
            extension_selected: Handle selection from list.
            create_extension_frame: Hold widgets for one extension.
            set_extension_value: Set in userCfg['extensions'].
            save_all_changed_extensions: Call extension page Save().
        ru   z Feature Extensions r   z Help Menu Extensions r   r   r   Zbrowse)ZlistvariableZ
selectmodez<<ListboxSelect>>r      )rH   rG   Znwsr   r   rZ   nsr   r  )r   r   rZ   ry   rX   Nr?   {z} r{  )r   r   Zsew)r   Zextension_namesr"   r   	HelpFrameZ
frame_helpr   r   r   extension_listr   extension_selectedr*   r   r   r   details_framerf   r*  config_framecurrent_extensionZ
outerframeZtabbed_page_setr   r  create_extension_frameZselection_setr&   )rS   Z	frame_extZscrollZ	ext_namesr  rV   rV   rW   r  o  sD    



zExtPage.create_page_extensionsc           
      C   sF  i | _ tjddD ]}g | j |< q| j D ]}t| j|}dd |D }|D ]}|| qP|| }|D ]}| jj||dd}zddd| }d}W n> ty   zt	|}d	}W n t
y   |}d
}Y n0 Y n0 z| jj|||d|d}W n t
y
   |}Y n0 t| }	|	t| | j | |||||	d qlq(d
S )zAFill self.extensions with data from the default and user configs.F)Zactive_onlyc                 S   s   g | ]}| d r|qS )enable)
startswith)r   opt_namerV   rV   rW   r     s   
z+ExtPage.load_extensions.<locals>.<listcomp>T)raw)TrueFalserC  r  N)r   r  rB  )r   r   rB  r   var)r  r0   ZGetExtensionsr   r  ZGetOptionListremovert  KeyErrorr  r   r  r   r   r.  append)
rS   r  Zopt_listZenablesr  Zdef_strZdef_objZopt_typer   r  rV   rV   rW   r    sL    

zExtPage.load_extensionsc                 C   s   | j  }|r| j |}|du s,|| jkrV| jrV| jjdd | j| j   d| _|r| jj|d | j| jdddd || _dS )z/Handle selection of an extension from the list.Nr?   r\   r   r   r  )	r  r  r   r  r  r   r  Zgrid_forgetrf   )rS   r   ZnewselrV   rV   rW   r    s    
zExtPage.extension_selectedc                 C   s   t | jddd}|| j|< |j}t| j| D ]\}}t||d d}|j|dtd |d }|d d	krt	||d
dddj|dt
dd q.|d dkrt||d| jdfddj|dtdd q.t||ddj|dtdd q.dS )z=Create a frame holding the widgets to configure one extensionr  rF   r   r\   r   r{  r  r   rC  r  r  r  )r   r   r   rH   r      )r   r   rZ   ry   r  rI  r  r  )r  r  r  rH   r   )r  rH   N)VerticalScrolledFramer  r  interior	enumerater  r&   rf   r   r$   r   r%   r  r   )rS   r  fZ
entry_arear   optZlabelr  rV   rV   rW   r    s.    

zExtPage.create_extension_framec                 C   sX   |d }|d }|d    p"|}|d | ||krH| j||S | j|||S )zReturn True if the configuration was added or changed.

        If the value is the same as the default, then remove it
        from user config file.
        r   rB  r  )r   r   r   r  ZRemoveOptionrl  )rS   Zsectionr  r   rB  r   rV   rV   rW   set_extension_value  s    zExtPage.set_extension_valuec                 C   sF   d}| j D ](}| j | }|D ]}| ||rd}qq
|rB| j  dS )zSave configuration changes to the user config file.

        Attributes accessed:
            extensions

        Methods:
            set_extension_value
        FTN)r  r   r  ZSave)rS   Zhas_changesr  Zoptionsr  rV   rV   rW   r     s    	

z#ExtPage.save_all_changed_extensions)r   r   r   rI   r  r  r  r  r   r   r   rV   rV   r   rW   rh   f  s   ?.rh   c                       s\   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Z  ZS )r  c                    s(   t  j|fi | |   |   d S r   )r   rI   create_frame_helpload_helplist)rS   r   Zcfgr   rV   rW   rI   +  s    zHelpFrame.__init__c                 C   s  t | }t|ddtd| _t|}| jj|d< |j| jd< | jd| j t | }t	|ddd	| j
d
| _t	|dd	| jd| _t	|ddd	| jd
| _|jtddttd | jjttttd |jtttd |jtddtd | jjttdd | jjttd | jjttdd dS )a8  Create LabelFrame for additional help menu sources.

        load_helplist loads list user_helplist with
        name, position pairs and copies names to listbox helplist.
        Clicking a name invokes help_source selected. Clicking
        button_helplist_name invokes helplist_item_name, which also
        changes user_helplist.  These functions all call
        set_add_delete_state. All but load call update_help_changes to
        rewrite changes['main']['HelpFiles'].

        Widgets for HelpFrame(LabelFrame):  (*) widgets bound to self
            frame_helplist: Frame
                (*)helplist: ListBox
                scroll_helplist: Scrollbar
            frame_buttons: Frame
                (*)button_helplist_edit
                (*)button_helplist_add
                (*)button_helplist_remove
        rx   Tr   rv   r   r   ZEditr  r  )r]   r  rH   rv   ZAdd)r]   rH   rv   ZRemover  )ra   r   rb   rc   )ra   r   rc   r   r  r   N)r!   r   r
   helplistr*   r   r   r   help_source_selectedr#   helplist_item_editbutton_helplist_edithelplist_item_addZbutton_helplist_addhelplist_item_removebutton_helplist_removerq   r   r	   r   r   r   r   r   r   )rS   Zframe_helplistZscroll_helplistZframe_buttonsrV   rV   rW   r  0  s:    zHelpFrame.create_frame_helpc                 C   s   |    dS )z+Handle event for selecting additional help.N)set_add_delete_stater  rV   rV   rW   r  b  s    zHelpFrame.help_source_selectedc                 C   sh   | j  dk r(| jd | jd n<| j  rL| jd | jd n| jd | jd dS )zAToggle the state for the help list buttons based on list entries.r   rG  rT  N)r  sizer  r  r	  r  r   rV   rV   rW   r
  f  s    
zHelpFrame.set_add_delete_statec                 C   s:   t | dj}|r6| j| | jt|d  |   dS )zHandle add button for the help list.

        Query for name and location of new help sources and add
        them to the list.
        zNew Help Sourcer   N)r6   rc  user_helplistr  r  r   r   update_help_changes)rS   help_sourcerV   rV   rW   r  s  s
    zHelpFrame.helplist_item_addc                 C   sx   | j t}| j| }t| d|d |d dj}|rt||krt|| j|< | j | | j ||d  |   | 	  dS )zHandle edit button for the help list.

        Query with existing help source information and update
        config if the values are changed.
        zEdit Help Sourcer   r   )ZmenuitemfilepathN)
r  r   r   r  r6   rc  r  r   r  r
  )rS   
item_indexr  Znew_help_sourcerV   rV   rW   r    s    

zHelpFrame.helplist_item_editc                 C   s4   | j t}| j|= | j | |   |   dS )z`Handle remove button for the help list.

        Delete the help list item from config.
        N)r  r   r   r  r  r  r
  )rS   r  rV   rV   rW   r    s
    zHelpFrame.helplist_item_removec                 C   sV   i t d d< tdt| jd D ]0}t ddt|d| j|d  dd  q dS )z2Clear and rebuild the HelpFiles section in changesr   Z	HelpFilesr   ;Nru   )r   r-  r+  r  r   r.  r  )rS   ZnumrV   rV   rW   r    s    
zHelpFrame.update_help_changesc                 C   sB   t  | _| jdd | jD ]}| jt|d  q|   d S )Nr   r   )r0   ZGetAllExtraHelpSourcesListr  r  r  r   r   r
  )rS   Z	help_itemrV   rV   rW   r    s
    

zHelpFrame.load_helplist)r   r   r   rI   r  r  r
  r  r  r  r  r  r   rV   rV   r   rW   r  )  s   2r  c                   @   sD   e Zd ZdZdd Zdd Zdd Zedd	 Zd
d Z	dd Z
dS )VarTracez"Maintain Tk variables trace state.c                 C   s   g | _ g | _dS )a  Store Tk variables and callbacks.

        untraced: List of tuples (var, callback)
            that do not have the callback attached
            to the Tk var.
        traced: List of tuples (var, callback) where
            that callback has been attached to the var.
        N)untracedtracedr   rV   rV   rW   rI     s    	zVarTrace.__init__c                 C   s   | j   | j  dS )zClear lists (for tests).N)r  r   r  r   rV   rV   rW   r     s    
zVarTrace.clearc                 C   s*   t |tr| ||}| j||f |S )a_  Add (var, callback) tuple to untraced list.

        Args:
            var: Tk variable instance.
            callback: Either function name to be used as a callback
                or a tuple with IdleConf config-type, section, and
                option names used in the default callback.

        Return:
            Tk variable instance.
        )
isinstancetuplemake_callbackr  r  rS   r  callbackrV   rV   rW   rp     s    
zVarTrace.addc                    s    fdd}|S )zCReturn default callback function to add values to changes instance.c                     s   t jg   R   dS )z&Add config values to changes instance.N)r   r   r   )r   r   r  rV   rW   default_callback  s    z0VarTrace.make_callback.<locals>.default_callbackrV   )r  r   r  rV   r  rW   r    s    zVarTrace.make_callbackc                 C   s6   | j r2| j  \}}|d| | j||f q dS )z0Attach callback to all vars that are not traced.writeN)r  popZ	trace_addr  r  r  rV   rV   rW   rR     s    zVarTrace.attachc                 C   sB   | j r>| j  \}}|d| d d  | j||f q dS )z!Remove callback from traced vars.r  r   r   N)r  r  Ztrace_removeZ
trace_infor  r  r  rV   rV   rW   detach  s    zVarTrace.detachN)r   r   r   r   rI   r   rp   r  r  rR   r  rV   rV   rV   rW   r    s   
r  a7  When you click either the Apply or Ok buttons, settings in this
dialog that are different from IDLE's default are saved in
a .idlerc directory in your home directory. Except as noted,
these changes apply to all versions of IDLE installed on this
machine. [Cancel] only cancels changes made since the last save.
u  
Font sample: This shows what a selection of Basic Multilingual Plane
unicode characters look like for the current font selection.  If the
selected font does not define a character, Tk attempts to find another
font that does.  Substitute glyphs depend on what is available on a
particular system and will not necessarily have the same size as the
font selected.  Line contains 20 characters up to Devanagari, 14 for
Tamil, and 10 for East Asia.

Hebrew and Arabic letters should display right to left, starting with
alef, א and ا.  Arabic digits display left to right.  The
Devanagari and Tamil lines start with digits.  The East Asian lines
are Chinese digits, Chinese Hanzi, Korean Hangul, and Japanese
Hiragana and Katakana.

You can edit the font sample. Changes remain until IDLE is closed.
z
Highlighting:
The IDLE Dark color theme is new in October 2015.  It can only
be used with older IDLE releases if it is saved as a custom
theme, with a different name.
z
Keys:
The IDLE Modern Unix key set is new in June 2016.  It can only
be used with older IDLE releases if it is saved as a custom
key set, with a different name.
a_  
General:

AutoComplete: Popupwait is milliseconds to wait after key char, without
cursor movement, before popping up completion box.  Key char is '.' after
identifier or a '/' (or '\' on Windows) within a string.

FormatParagraph: Max-width is max chars in lines after re-formatting.
Use with paragraphs in both strings and comment blocks.

ParenMatch: Style indicates what is highlighted when closer is entered:
'opener' - opener '({[' corresponding to closer; 'parens' - both chars;
'expression' (default) - also everything in between.  Flash-delay is how
long to highlight if cursor is not moved (0 means forever).

CodeContext: Maxlines is the maximum number of code context lines to
display when Code Context is turned on for an editor window.

Shell Preferences: Auto-Squeeze Min. Lines is the minimum number of lines
of output to automatically "squeeze".
a  
ZzDummy: This extension is provided as an example for how to create and
use an extension.  Enable indicates whether the extension is active or
not; likewise enable_editor and enable_shell indicate which windows it
will be active on.  For this extension, z-text is the text that will be
inserted at or removed from the beginning of the lines of selected text,
or the current line if no selection.
)r[   r^   r  r  r_   c                 C   s0   | sdS zt |  W dS  ty*   Y dS 0 dS )z(Return 's is blank or represents an int'TFN)r  r   r  rV   rV   rW   r  3	  s    r  c                   @   s   e Zd ZdZdd ZdS )r  zA pure Tkinter vertically scrollable frame.

    * Use the 'interior' attribute to place widgets inside the scrollable frame
    * Construct and pack/place/grid normally
    * This frame only allows vertical scrolling
    c                    s   t j| |g|R i | t| td}|jtttd t| dd|j	dd  jt
ttd |j jd  d  d t   | _ jddtd fd	d
}d|  fdd} d| d S )Nrx  )rc   ra   rb   r      )rz   r   r   rH   r|  r   )Zwindowr   c                    s$      f} jd| d d S )Nz	0 0 %s %s)Zscrollregion)winfo_reqwidthZwinfo_reqheightr   )r   r  )canvasr  rV   rW   _configure_interiorZ	  s    z;VerticalScrolledFrame.__init__.<locals>._configure_interiorz<Configure>c                    s&       kr" j  d d S )N)rH   )r   Zwinfo_widthZitemconfigure)r   r!  r  Zinterior_idrV   rW   _configure_canvas`	  s    z9VerticalScrolledFrame.__init__.<locals>._configure_canvas)r!   rI   r*   r   rq   r   r   r
   r   r   r   r   r	   r   r   Zxview_movetoZyview_movetor  Zcreate_windowr   r   )rS   rJ   ri  kwZ
vscrollbarr"  r$  rV   r#  rW   rI   E	  s"    

zVerticalScrolledFrame.__init__N)r   r   r   r   rI   rV   rV   rV   rW   r  >	  s   r  __main__)r   z#idlelib.idle_test.test_configdialogru   F)	verbosityexit)run)dr   r  Ztkinterr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    Ztkinter.ttkr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   Ztkinter.fontr   r   r/   Zidlelib.configr0   r1   Zidlelib.config_keyr2   Zidlelib.dynoptionr3   Zidlelibr4   Zidlelib.queryr5   r6   Zidlelib.textviewr7   Zidlelib.autocompleter8   Zidlelib.codecontextr9   Zidlelib.parenmatchr:   Zidlelib.formatr;   Zidlelib.squeezerr<   r=   r   r   r>   r   rl   rj   rm   rn   ro   rh   r  r  rQ   r   r   r  r  r   Zunittestr   Zidlelib.idle_test.htestr)  rV   rV   rV   rW   <module>   s|   < W +        4 S  D =>+
