Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/idlelib/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/idlelib/__pycache__/editor.cpython-312.opt-1.pyc

�

%Μg���L�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddl�ddlm
Z
ddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddlm$Z$dZ%dejL�zZ'ejdk(Z(d�Z)Gd�d�Z*d�Z+ejXd�Z-d�Z.Gd�d�Z/d �Z0d!d"d#d$�Z1d%�Z2d&�Z3d'�Z4e5d(k(r dd)l6m7Z7e7d*d+d,�-�dd.l8m9Z9e9e4�yy)/�N)�*)�Font)�	Scrollbar)�simpledialog)�
messagebox)�idleConf)�configdialog)�grep)�help)�
help_about)�macosx)�MultiCallCreator)�pyparse)�query)�replace)�search)�wheel_event)�
py_extensions)�window�z (%s)�darwinc��tj\}}}}}|�|��}||�z
}|dk(r
|d|��z
}|S|dk7r||d�|��z
}|S)zYFormat sys.version_info to produce the Sphinx version string used to install the chm docs�	candidate�rc�finalr)�sys�version_info)�major�minor�micro�level�serial�releases      �+/usr/local/lib/python3.12/idlelib/editor.py�_sphinx_versionr%&sw��),�)9�)9�&�E�5�%������w��G��%���G�����R��x�=� ���N�
�'�	��e�A�h�Z��x�(�(���N�c��eZdZddlmZddlmZmZddlm	Z	ddl
mZmZddl
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZmZmZddl m!Z!ddl"m#Z#e$jJ�Z&dZ'dZ(dZ)dZ*dwd�Z+dxd�Z,d�Z-d�Z.d�Z/d�Z0dxd�Z1	gd�Z2d�Z3d�Z4d�Z5d�Z6d�Z7dZ8d�Z9d gZ:d!�Z;d"�Z<d#�Z=d$�Z>dxd%�Z?dxd&�Z@dxd'�ZAdxd(�ZBd)�ZCd*�ZDd+�ZEdxd,�ZFdxd-�ZGd.�ZHd/�ZId0�ZJd1�ZKd2�ZLd3�ZMd4�ZNd5�ZOd6�ZPd7�ZQd8�ZRdxd9�ZSdxd:�ZTdxd;�ZUd<�ZVd=�ZWd>�ZXd?�ZYd@�ZZdA�Z[dB�Z\dC�Z]e^j�e^j�zdDzZadE�ZbdF�ZcdG�ZddH�ZedI�ZfdJ�ZgdK�ZhdL�ZidxdM�ZjdN�ZkdO�ZldP�ZmdQ�ZndR�ZodS�ZpdT�ZqdU�ZrdydV�ZsdW�ZtdydX�ZudY�ZvdZ�Zwd[�Zxd\�Zyd]�Zzd^�Z{d_�Z|d`�Z}da�Z~dbdciZdd�Z�dxde�Z�dzdf�Z�dg�Z�dxdh�Z�dxdi�Z�dj�Z�dk�Z�dl�Z�dm�Z�d{dn�Z�do�Z�dp�Z�dq�Z�dr�Z�ds�Z�dt�Z�du�Z�dxdv�Z�y)|�EditorWindowr)�
Percolator)�ColorDelegator�color_config)�
UndoDelegator)�	IOBinding�encoding)�mainmenu)�MultiStatusBar)�AutoComplete)�
AutoExpand)�Calltip)�CodeContext)�LineNumbers)�FormatParagraph�FormatRegion�Indents�Rstrip)�
ParenMatch)�
ZoomHeightNTc�d"�ddlm}tj���tj
j
tjdd�}tjjd�r`ddtjddzz}tj
jd	�rd
}n�d}tj
j
||dd�}n�tjdddk(rYddl
}	d
}
dtj�d�}	|	j|	j |�}
tj
j'|
�rD|
}nAtjdk(r.tj
j
tjd�}tj
j)|�}tj
j'|�r;|t_tjdk(r<dtjzt_ndtjddzt_||_|xs|j,}||_t/|�|_t3j4||j0��x|_}|r-|j8|_|j<|j6_ni|_i|j6_t@jBxr.tj
j
t@jBd�|_"d
|_#tI|�x|_%}
tM|
d��x|_'}tAjPdddd��}ddd d|d!tAjPddd"d��d#�}tStT�|
fi|��x|_+}|jV|j6_,|j[�|j]�|j6j_d$|j`�|j6jcd%|jd�tgjh�rU|jcd%|jd�|jcd&|jj�|jcd'|jj�n|jcd(|jj�|jcd)tl�|jnd*k(r,|jcd+tl�|jcd,tl�|jcd-|jp�|jcd.|jr�|jcd/|jt�|jcd0|jv�|jcd1|jx�|jcd2|jz�|jcd3|j|�|jcd4|j~�|jcd5|j��|jcd6|j��|jcd7d8��|jcd9|j��|jcd:|j��|jcd;|j��|jcd<|j��|jcd=|j��|jcd>|j��|jcd?|j��|jcd@|j��|jcdA|j��|jcdB|j��|jcdC|j��|j�|�x|_N}|jcdD|j��|jcdE|j��|jcdF|j��|jcdG|j��|jcdH|j��|jcdI|j��|j�|�}|jcdJ|j��|jcdK|j��|jcdL|j�d��|jcdM|j�dN��|jcdO|j��|jcdP|j��|jcdQ|j��|r�||j<|<|r||j�|<|jcdR|j��|jcdS|j*j��|jcdT|j��|jcdU|j��|jcdV|j��|j��|
j�t�t�dN�W�|
j�dNdN�X�|
j�dNdN�X�|j�|dY<|j�dNdt��Z�|j�|d[<tAj�|j,dd�|d\<|j�dNdNt��Z�|j��|j��tAjPdd]d^d_��}||_od`|_p|j�|_q|j��t�t@da�s|jVdbt@_t|j��dc|_v|j�|�x|_x}|j��x|_z}|j�|�|j�|_||j�|_}|j�|j��|�j|�x|_�}|�j|�j�dd|_�|�jdd�d|_�d|_�d|_�|r�tj
�j|�r]tj
j|�s>|�j|�rEde|_�|�j|�}|�j|�n|�j|�de|_�|�j�|j��|�j�|�j�|�j �j#df�}|rY|�j%dg�}|�dh}|dk\r|�j'�|dNz}||_�t3�j*|�j,��t.�j0|_��t2�j4|_��t2�j6|_�|�j9didj�|�j9dkdldmdn�|�j9dodp�|�j9dqdr�|�j9dsdrdtdu�|�j;||�j<�}|jcdi|�j>�|jcdk|�j@�|jcdv|�jB�|jcdw|�jE|��jF�|jcdx|�jI|��jJ�|�jM|�}|jcdy|�jN�|jcds|�jP�||�}|jcdz|�jR�|jcd{|�jT�|jcd||�jV�|jcd}|�jY|��jZ�|�j]|�x|_�}|jcdo|�j`�|jcdq|�jb�|jcd~|�jd�|jcd|�jg|��jh�|�jjr@|�jm|�|_�|jcd�|�j�jn�n|�jqd�d�d��|�jrr_|�ju|�|_�tAjPddd�d_��r|�jw�|jcd�|�jv�y|�jqd�d�d��y#t"$r1	|	j|	j$|�}
n#t"$rYnwxYwY��wxYw)�Nr)�
ScriptBinding�Docz
index.html�linuxzpython-docs-z%s.%s.%s�z/var/www/html/python/z/var/www/html/python/index.htmlz/usr/share/doc/�win�zSoftware\Python\PythonCore\z\Help\Main Python Documentationrz0Resources/English.lproj/Documentation/index.htmlzfile://zhttps://docs.python.org/%d.%d/�)�menuzrecent-files.lst�vbar)�name�mainr(�width�int��type�text��none�
wordprocessor�height)rF�padx�wrap�highlightthicknessrH�tabstylerP�WM_DELETE_WINDOW�<<close-window>>z<Control-Button-1>z<2>z<3>z<MouseWheel>�x11z
<Button-4>z
<Button-5>z<Configure>z<<cut>>z<<copy>>z	<<paste>>z<<center-insert>>z<<help>>z<<python-docs>>z<<about-idle>>z<<open-config-dialog>>�<<open-module>>z<<do-nothing>>c��y�N�break�)�events r$�<lambda>z'EditorWindow.__init__.<locals>.<lambda>�s��'r&z<<select-all>>z<<remove-selection>>z<<find>>z<<find-again>>z<<find-in-files>>z<<find-selection>>z<<replace>>�
<<goto-line>>z<<smart-backspace>>z<<newline-and-indent>>z<<smart-indent>>z<<indent-region>>z<<dedent-region>>z<<comment-region>>z<<uncomment-region>>z<<tabify-region>>z<<untabify-region>>z<<toggle-tabs>>�<<change-indentwidth>>z<Left>z<Right>�z<<del-word-left>>z<<del-word-right>>z<<beginning-of-line>>z<<open-new-window>>z<<close-all-windows>>z<<open-class-browser>>z<<open-path-browser>>z<<open-turtle-demo>>)�side�fill�expand)�weight�command)�row�column�sticky�yscrollcommand�font�Indentz
use-spaces�boolr�blink_off_time�
insertofftime)�2i�i@KLFTr�end���z<<autocomplete>>z	<Key-Tab>z<<try-open-completions>>z<KeyRelease-period>z<KeyRelease-slash>z<KeyRelease-backslash>z<<try-open-calltip>>z<KeyRelease-parenleft>z<<refresh-calltip>>z<KeyRelease-parenright>z<<paren-closed>>z<KeyRelease-bracketright>z<KeyRelease-braceright>z<<force-open-completions>>z<<expand-word>>z<<format-paragraph>>z<<flash-paren>>z<<check-module>>z<<run-module>>z<<run-custom>>z
<<do-rstrip>>z<<force-open-calltip>>z<<zoom-height>>z<<toggle-code-context>>�optionsz*ode*ontext�disabledzline-numbers-defaultz<<toggle-line-numbers>>�*ine*umbers)��idlelib.runscriptr=r(�help_url�os�path�joinr�base_prefix�platform�countr�isdir�winreg�winver�
QueryValue�HKEY_CURRENT_USER�FileNotFoundError�HKEY_LOCAL_MACHINE�isfile�normpath�flist�root�Menu�menubarr�ListedToplevel�top�vars�tkinter_vars�inversedict�
instance_dictr�userdir�recent_files_path�prompt_last_line�Frame�
text_framerrE�	GetOptionr�TextrL�focused_widget�
createmenubar�apply_bindings�protocol�close�bind�close_eventr
�isAquaTk�right_menu_eventr�_windowingsystem�handle_winconfig�cut�copy�paste�center_insert_event�help_dialog�python_docs�about_dialog�
config_dialog�open_module_event�
select_all�remove_selection�
find_event�find_again_event�find_in_files_event�find_selection_event�
replace_event�goto_line_event�smart_backspace_event�newline_and_indent_event�smart_indent_eventr7�fregion�indent_region_event�dedent_region_event�comment_region_event�uncomment_region_event�tabify_region_event�untabify_region_eventr8�toggle_tabs_event�change_indentwidth_event�move_at_edge_if_selection�
del_word_left�del_word_right�
home_callback�dict�new_callback�close_all_callback�open_module_browser�open_path_browser�open_turtle_demo�set_status_bar�pack�LEFT�BOTH�rowconfigure�columnconfigure�handle_yview�grid�NSEW�set�GetFont�	focus_set�	set_width�usetabs�tabwidth�indentwidth�set_notabs_indentwidth�hasattrrn�update_cursor_blink�num_context_linesr)�perr,�undo�insertfilter�undo_block_start�undo_block_stop�set_saved_change_hook�saved_change_hookr-�io�set_filename_change_hook�filename_change_hook�	good_load�set_indentation_params�color�code_context�line_numbers�exists�loadfile�ispythonsource�set_filename�ResetColorizer�update_recent_files_list�load_extensions�menudict�get�index�
add_separator�	wmenu_end�register_callback�postwindowsmenur�
askintegerr�askyesno�	showerror�	event_addr1�user_input_insert_tags�autocomplete_event�try_open_completions_event�force_open_completions_eventr2�expand_word_eventr6�format_paragraph_eventr:�flash_paren_event�paren_closed_event�check_module_event�run_module_event�run_custom_eventr9�	do_rstripr3�ctip�try_open_calltip_event�refresh_calltip_event�force_open_calltip_eventr;�zoom_height_event�allow_code_contextr4�toggle_code_context_event�update_menu_state�allow_line_numbersr5�toggle_line_numbers_event)�selfr��filename�keyr�r=�dochome�pyver�basepathr�docfile�KEYr�r�rErH�text_optionsrLr��indents�	usespacesr�r�r��	is_py_srcrDrq�autocomplete�
parenmatch�
scriptbindingrs                               r$�__init__zEditorWindow.__init__Js[
��3�� � �(��w�w�|�|�C�O�O�U�L�I�G��|�|�!�!�'�*�&��c�6F�6F�r��6J�)J�J���7�7�=�=�!8�9�?�G�0�H� �g�g�l�l�8�U�+0�,�@�G����b�q�!�U�*����5�c�j�j�\�:�;���$�/�/��0H�0H�#�N�G��7�7�>�>�'�*�%�G�����)��'�'�,�,�s���J�L���g�g�&�&�w�/�G��w�w�~�~�g�&�(/��%��<�<�8�+�,5��8M�8M�,M�L�)�)I�+.�+;�+;�B�Q�+?�*@��%���
��!�u�z�z����	��D�z����.�.�t�$�,�,�G�G���3�� %�
�
�D��&+�%6�%6�D�H�H�"� "�D��%'�D�H�H�"�!)�!1�!1�"6�b�g�g�l�l�� � �"4�76���!#���',�S�z�1���*�$�Z�f�=�=��	�D��"�"�6�>�7��O�����&'��+�"�,�,����u�F�	��2�+�D�1�*�M��M�M��	�D�"&�)�)������������������,�d�j�j�9����
�
�(�$�*:�*:�;��?�?���I�I�(�$�*:�*:�;�
�I�I�*�4�+@�+@�A��I�I�e�T�2�2�3�
�I�I�e�D�1�1�2��	�	�.�+�.�� � �E�)��I�I�l�K�0��I�I�l�K�0��	�	�-��!6�!6�7��	�	�)�T�X�X�&��	�	�*�d�i�i�(��	�	�+�t�z�z�*��	�	�%�t�'?�'?�@��	�	�*�d�.�.�/��	�	�#�T�%5�%5�6��	�	�"�D�$5�$5�6��	�	�*�D�,>�,>�?��	�	�#�T�%;�%;�<��	�	�"�$9�:��	�	�"�D�O�O�4��	�	�(�$�*?�*?�@��	�	�*�d�o�o�.��	�	�"�D�$9�$9�:��	�	�%�t�'?�'?�@��	�	�&��(A�(A�B��	�	�-��!3�!3�4��	�	�/�4�#7�#7�8��	�	�'��(B�(B�C��	�	�*�4�+H�+H�I��	�	�$�T�%<�%<�=�!%�!2�!2�4�!8�8���w��	�	�%�w�'B�'B�C��	�	�%�w�'B�'B�C��	�	�&��(D�(D�E��	�	�(�'�*H�*H�I��	�	�%�w�'B�'B�C��	�	�'��)F�)F�G��,�,�t�$���	�	�#�W�%>�%>�?��	�	�*�G�,L�,L�M��	�	�(�D�:�:�1�=�>��	�	�)�T�;�;�A�>�?��	�	�%�t�'9�'9�:��	�	�&��(;�(;�<��	�	�)�4�+=�+=�>��&)�E���d�#��"&��
�
�3���I�I�+�T�->�->�?��I�I�-�t�z�z�/L�/L�M��I�I�.��0H�0H�I��I�I�-�t�/E�/E�F��I�I�,�d�.C�.C�D��������T��Q��7�����!��,��"�"�1�Q�"�/��+�+��Y���	�	�a��$�	�/�!%����
���'�'��	�	�6�>�J��V���	�	�a��$�	�/����������&�&�v�x�'3�&�B�	�$�}�����
� �=�=����#�#�%��x�!1�2�&*�i�i��&@�H�#�� � �"�"2�������.�.���3��-�-�/�/��	�D������ $� 5� 5���#�3�3����"�"�4�#9�#9�:��~�~�d�+�+���"�
�#�#�D�$=�$=�>�����#�#�E�*���
� ��� �����w�w�~�~�h�'����
�
�h�0G��;�;�x�(�%)�D�N� $� 3� 3�H� =�I��/�/�	�:�����)�!%���������� ��%�%�'������}�}� � ��*����*�*�U�#�C��{����a�x��"�"�$��A�g�� �D�N��$�$�T�%9�%9�:�'�1�1���"�+�+��
�#�-�-���	
���)�;�7����1�3H�+�-E�	G����-�/G�H����,�.G�H����)�+D�2�4M�	O�
�(�(��t�/J�/J�K���	�	�$�l�&E�&E�F��	�	�,��9�9�	;��	�	�.��;�;�	=��	�	�#�T�_�_�T�%:�%L�%L�M��	�	�(��&�&�t�,�C�C�	E��_�_�T�*�
��	�	�#�Z�%A�%A�B��	�	�$�j�&C�&C�D�%�d�+�
��	�	�$�m�&F�&F�G��	�	�"�M�$B�$B�C��	�	�"�M�$B�$B�C��	�	�/�4�;�;�t�#4�#>�#>�?��<�<��-�-��	�D��	�	�(�$�*E�*E�F��	�	�'��)C�)C�D��	�	�*�D�,I�,I�J��	�	�#�T�_�_�T�%:�%L�%L�M��"�"� $� 0� 0�� 6�D���I�I�/��'�'�A�A�
C�
�"�"�9�m�Z�H��"�"� $� 0� 0�� 6�D���!�!�&�.�"8�v�G��.�.�0��I�I�/��1O�1O�P��"�"�9�m�Z�H��W)���"(�"3�"3�F�4M�4M�47�#9���,�����	�sG�7AC5�C5	AD/�C?AD�DAD/�D	AD(�D%AD/�D'AD(�D(AD/�D.AD/c�$�|j�y�N)r��rr]s  r$r�zEditorWindow.handle_winconfigms�����r&c	�D�|j}tt|jj|jd�|jd�g��}|j
�d|zz
}t||jd���jd�}||z|_	y)N�borderrQrCrk)rk�0)
rL�sum�map�tk�getint�cget�winfo_widthr�measurerH)rrL�
inner_padding�pixel_width�zero_char_widths     r$r�zEditorWindow.set_widthps����y�y���C���������8�1D�15���6�1B�1D�E�F�
��&�&�(�1�}�+<�<��
��D�I�I�f�-�.�6�6�s�;�	� �O�3��
r&c�t�|jj�\}}|jj|�yrZ)r��defaultfilenamer��new)rr]�dirname�basenames    r$r�zEditorWindow.new_callback}s,�� �G�G�3�3�5�����
�
���w��r&c��|jdzdk7r|jdk(ry|jjd�rq|jj	ddd�rT|jj	ddd�r7t|jjd�j
d�d	�}nI|jjdd�}tt|��D]}||d
vs�nt|�}t|jjd�j
d�d	�}||k(rd}dt|�zd
z}|jd	zdk(r|jjddd��nQ|jjd�s|jjdd�n�|jj	|jjd�d|jjd��r|jjdd�n|jjdd�|jj|�}|jjd�}|jj	|d|�r||}}|jjddd�|jjd||�|jjd|�|jjd�y)N�r�Home�iomark�<=zinsert lineend�insert linestart�.ra)� �	�insertzinsert linestart+�c�sel�1.0rq�	sel.first�	my_anchor�<�sel.last�>r[)�state�keysymrLr��comparerI�splitr��range�len�str�
tag_remove�mark_set�tag_add�see)rr]�insertpt�line�lineat�dest�first�lasts        r$r�zEditorWindow.home_callback�sK���K�K�!�O��!�e�l�l�f�&<���9�9�?�?�8�$��9�9���X�t�-=�>��9�9���/��x�@��4�9�9�?�?�8�4�:�:�3�?��B�C�H��9�9�=�=�!3�5E�F�D�!�#�d�)�,����>��3��-��T����T�Y�Y�_�_�X�.�4�4�S�9�!�<�=���v���H�"�3�x�=�0��4���K�K��M�a���I�I� � ���u�5��9�9�?�?�;�/��	�	�"�"�;��9��9�9�$�$�T�Y�Y�_�_�[�%A�3�%)�Y�Y�_�_�X�%>�@��I�I�&�&�{�K�@��I�I�&�&�{�J�?��I�I�O�O�D�)�E��9�9�?�?�;�/�D��y�y� � ��s�4�0�!�%�d���I�I� � ���u�5��I�I���e�U�D�1��	�	���8�T�*��	�	�
�
�h��r&c��|j|j�|_t|jddd��}tj
dk(r"|jj
ddt��|jj
dd	t��|jj
d
dt��|jjtt��|jtt��|jjd
|j�|jjd
dd�|jj|j�y)Nra�grey75)rP�borderwidth�
backgroundr�	_padding1z    )rbrhzCol: ?rXzLn: ?)rbrcz<<set-line-and-column>>z<KeyRelease>z<ButtonRelease>)r0r��
status_barr�rr|�	set_label�RIGHTr��BOTTOM�XrLr��set_line_and_columnr��
after_idle)r�seps  r$r�zEditorWindow.set_status_bar�s����-�-�d�h�h�7����D�H�H�Q�A�(�K���<�<�8�#�
�O�O�%�%�k�6��%�F����!�!�(�H�5�!�A����!�!�&�'��!�>������&�q��1����f�1��%��	�	���0�$�2J�2J�K��	�	���5�*�,=�	?��	�	���T�5�5�6r&c���|jjt�jd�\}}|jjdd|z�|jjdd|z�y)Nr@rhzCol: %srXzLn: %s)rLr��INSERTrOrbrc)rr]rXrhs    r$rgz EditorWindow.set_line_and_column�sT���y�y���v�.�4�4�S�9���f����!�!�(�I��,>�?����!�!�&�(�T�/�:r&))�file�_File)�edit�_Edit)�format�F_ormat)�run�_Run)rs�_Options)r�_Window)r�_Helpc�t�|j}ix|_}|jD]K\}}t|�\}}t	||�d�d�}t||d|��x||<}|j
|||���Mtj�r&t|dd��x|d<}|j
d	|�
�|j�t|jd��|_
|jdjd
dd|j��|jdjt�|_|j�y)aPopulate the menu bar widget for the editor window.

        Each option on the menubar is itself a cascade-type Menu widget
        with the menubar as the parent.  The names, labels, and menu
        shortcuts for the menubar items are stored in menu_specs.  Each
        submenu is subsequently populated in fill_menus(), except for
        'Recent Files' which is added to the File menu here.

        Instance variables:
        menubar: Menu widget containing first level menu items.
        menudict: Dictionary of {menuname: Menu instance} items.  The keys
            represent the valid menu items for this window and may be a
            subset of all the menudefs available.
        recent_files_menu: Menu widget contained within the 'file' menudict.
        �_menu_postcommandNr)rF�tearoff�postcommand)�labelrD�	underline�apple)rFry�application�IDLE)r{rD�ryrlr@zRecent Files)r{r|rDr)r�r��
menu_specs�prepstr�getattrr��add_cascader
�
isCarbonTk�
fill_menus�recent_files_menu�insert_cascader��END�base_helpmenu_length�reset_help_menu_entries)r�mbarr�rFr{r|rzrDs        r$r�zEditorWindow.createmenubar�s6�� �|�|��#%�%��
���?�?�K�D�%�&�u�~��I�u�!�$�4�&�0A�(B�D�I�K�$(��D�!�5@�%B�
B�H�T�N�T����5�t�y��I�+�����-1�$�W�:;�.=�
=�H�]�#�d����6���5�����!%�d�l�l�A�!>����
�
�f��,�,�Q�n�78�26�2H�2H�	-�	J�%)�M�M�&�$9�$?�$?��$D��!��$�$�&r&c���|jd}|jd�}|�d}||jkDr|j|jdz|�t	j
|�y)zSCallback to register window.

        Only called when Window menu exists.
        rrqNrrra)r�r�r��deleter�add_windows_to_menu)rrDrqs   r$r�zEditorWindow.postwindowsmenus[��
�}�}�X�&���j�j�����;��C�������K�K����q�(�#�.��"�"�4�(r&c�H�|j|}|j||��y)z$Update label for menu item at index.)r{N�r��entryconfig)rrDr�r{�menuitems     r$�update_menu_labelzEditorWindow.update_menu_label�#���=�=��&�����U�%��0r&c�H�|j|}|j||��y)z$Update state for menu item at index.�rLNr�)rrDr�rLr�s     r$rzEditorWindow.update_menu_stater�r&c���|dk(rCt|d�}t|jd�|z�|jd�z
}d}|df}|jj|g|���y)zHandle scrollbar.�movetorrq�@0,0�scroll�unitsr[)�float�round�	getlinenorL�yview)rr]�args�fraction�liness     r$r�zEditorWindow.handle_yviewsi���H���T�!�W�~�H��4�>�>�%�0�8�;�<��^�^�F�+�,�E��E��7�#�D���	�	����%��%�r&c��|j}|jd|j�d|j���}	|j	dd|�xr|j	|dd�}|s%|j
ddd	�|jd
|�|js|j�|j}||_
tjdddk(}|r|jd
��|jD]0}	|\}}	}
|
��
t!||
��}|j#||���2|j%|j&|j(�|r|jjd��y#t
$rd}Y��wxYw#t$rY��wxYw)N�@�,rGr>rJFrErFrqrCr@rA�arrow)�cursorr��ibeamr[)rLr��x�yrN�TclErrorrSrT�rmenu�
make_rmenur]rr|�config�rmenu_specs�
ValueErrorr��entryconfigure�tk_popup�x_root�y_root)rr]rL�newdex�in_selectionr��iswin�itemr{�	eventname�verify_staterLs            r$r�zEditorWindow.right_menu_event)st���y�y�����a����y��%�'�'��3�4��	!� �L�L��d�F�C�C��<�<���z�B�
���O�O�E�5�%�0��M�M�(�F�+��z�z��O�O���
�
����
����R�a� �E�)����K�K�w�K�'��$�$�D�
�15�.��y�,��#��/�G�D�,�/�1�E�� � ��e� �4�%�	���u�|�|�U�\�\�2���I�I���G��,���7�	!� �L�	!�� �
��
�s#�(E%�1E7�%E4�3E4�7	F�F)�CloserVNc���t|jd��}|jD]B}|d|d}}|�$|j|fd�}|j||���3|j	��D||_y)Nrr�rac�&�|j|�yr&��event_generate�rLr�s  r$rfz(EditorWindow.make_rmenu.<locals>.commandVs���'�'�	�2r&�r{rf)r�rLr��add_commandr�r�)rr�r�r{r�rfs      r$r�zEditorWindow.make_rmenuQso���T�Y�Y��*���$�$�D�#�A�w��Q��9�E�� �!%���i�3��!�!��w�!�?��#�#�%�%���
r&c�"�|j�Sr&)�rmenu_check_copy�rs r$�rmenu_check_cutzEditorWindow.rmenu_check_cut]s���$�$�&�&r&c�d�	|jjd�}|rdSdS#t$rYywxYw)NrG�normalrt�rLr�r�)r�indxs  r$r�zEditorWindow.rmenu_check_copy`s<��	4��9�9�?�?�;�/�D� $�8�3��3���	��	�s�#�	/�/c��	|jjjd|jd�y#t$rYywxYw)Nztk::GetSelection�	CLIPBOARDr�rt)rLr-�callr�r�s r$�rmenu_check_pastezEditorWindow.rmenu_check_pastehs?��	��I�I�L�L���0�$�)�)�[�I����	��	�s�14�	A�Ac�B�tj|j�y)zHandle Help 'About IDLE' event.r[)r�AboutDialogr�r's  r$r�zEditorWindow.about_dialogps��	���t�x�x�(�r&c�D�tj|jd�y)z&Handle Options 'Configure IDLE' event.�Settingsr[)r	�ConfigDialogr�r's  r$r�zEditorWindow.config_dialogvs��	�!�!�$�(�(�:�6�r&c�x�|jr
|j}n|j}tj|�y)zHandle Help 'IDLE Help' event.r[)r�r�r�
show_idlehelp)rr]�parents   r$r�zEditorWindow.help_dialog|s.���9�9��Y�Y�F��X�X�F����6�"�r&c�2�tjdddk(r!	tj|j�ytj|j�y#t
$r5}t
jdt|�|j��Yd}~yd}~wwxYw)Nr@rA�Document Start Failure��title�messager�r[)rr|rx�	startfilerw�OSErrorrr�rRrL�
webbrowser�open)rr]�whys   r$r�zEditorWindow.python_docs�s~���<�<����u�$�
8����T�]�]�+��
�O�O�D�M�M�*����
8��$�$�+C���H�T�Y�Y�8�8���
8�s�A�	B�!+B�Bc�:�|jjd�y)Nz<<Cut>>r[�rLr�r's  r$r�zEditorWindow.cut�s���	�	� � ��+�r&c�r�|jjd�sy|jjd�y)NrEz<<Copy>>r[)rL�
tag_rangesr�r's  r$r�zEditorWindow.copy�s,���y�y�#�#�E�*���	�	� � ��,�r&c�p�|jjd�|jjd�y)Nz	<<Paste>>rCr[)rLr�rVr's  r$r�zEditorWindow.paste�s'���	�	� � ��-��	�	�
�
�h��r&c��|jjddd�|jjdd�|jjd�y)NrErFzend-1crCr[)rLrUrTrVr's  r$r�zEditorWindow.select_all�s?���	�	���%���1��	�	���8�U�+��	�	�
�
�h��r&c�t�|jjddd�|jjd�y)NrErFrqrCr[)rLrSrVr's  r$r�zEditorWindow.remove_selection�s+���	�	���U�E�5�1��	�	�
�
�h��r&c�z�����|jj�|jj�d�����fd�}|S)z�Cursor move begins at start or end of selection

        When a left/right cursor key is pressed create and return to Tkinter a
        function which causes a cursor move from the associated edge of the
        selection.

        )zsel.first+1czsel.last-1cc�t��|jdzdk(r	�d��d���yy#t$rYywxYw)NrMrrGrC)rLr�)r]�
edge_index�edges_table�self_text_index�self_text_mark_sets ����r$�move_at_edgez<EditorWindow.move_at_edge_if_selection.<locals>.move_at_edge�sH������a��A�%��#�K�0�&�x��Z�1H�I�&�� ����s�+�	7�7)rLr�rT)rr�r�r�r�r�s ` @@@r$r�z&EditorWindow.move_at_edge_if_selection�s4����)�)�/�/��!�Y�Y�/�/��5��	��r&c�:�|jjd�y)Nz
<Meta-Delete>r[r�r's  r$r�zEditorWindow.del_word_left�s���	�	� � ��1�r&c�:�|jjd�y)Nz<Meta-d>r[r�r's  r$r�zEditorWindow.del_word_right�s���	�	� � ��,�r&c�B�tj|j�yrZ)r�findrLr's  r$r�zEditorWindow.find_event�s�����D�I�I��r&c�B�tj|j�yrZ)r�
find_againrLr's  r$r�zEditorWindow.find_again_event�s�����$�)�)�$�r&c�B�tj|j�yrZ)r�find_selectionrLr's  r$r�z!EditorWindow.find_selection_event�s�����d�i�i�(�r&c�n�tj|j|j|j�yrZ)r
rLr�r�r's  r$r�z EditorWindow.find_in_files_event�s!���	�	�$�)�)�T�W�W�d�j�j�1�r&c�B�tj|j�yrZ)rrLr's  r$r�zEditorWindow.replace_event�s������	�	�"�r&c���|j}tj|dd�j}|�I|j	ddd�|jd|�d��|j
d�|j�y)	Nz
Go To Linez/Enter a positive integer
('big' = end of file):rErFrqrC�.0r[)rLr�Goto�resultrSrTrVrg)rr]rL�linenos    r$r�zEditorWindow.goto_line_event�st���y�y������l�)���&�		�
���O�O�E�5�%�0��M�M�(�v�h�b�M�2��H�H�X���$�$�&�r&c�b�	|jjdd�j�}t	j
|jdd|�j}|�D|jr|jj|�|S|jj|�|S#t$rd}Y��wxYw)z�Get module name from user and open it.

        Return module path or None for calls by open_module_browser
        when latter is not invoked in named editor window.
        rGrJrBzOpen ModulezAEnter the name of a Python module
to search on sys.path and open:)rLr��stripr�r�
ModuleNamer�r�r�r�r�)rrF�	file_paths   r$�open_modulezEditorWindow.open_module�s���	��9�9�=�=��j�9�?�?�A�D��$�$��	�	�=�2��	��f�		�
� ��z�z��
�
���	�*������ � ��+�����	��D�	�s�*B � B.�-B.c�$�|j�yrZ)rr's  r$r�zEditorWindow.open_module_events������r&c���|jj}|jjdk(r|s|j	�}|�yddlm}|j|j|�y)N�PyShellEditorWindowr[r)�browser)	r�r�	__class__�__name__r�idlelibr�
ModuleBrowserr�)rr]rrs    r$r�z EditorWindow.open_module_browsersX���7�7�#�#�����'�'�+@�@���'�'�)�H����#����d�i�i��2�r&c�F�ddlm}|j|j�y)Nr)�pathbrowserr[)r
r
�PathBrowserr�)rr]r
s   r$r�zEditorWindow.open_path_browsers��'�����	�	�*�r&c�X�ddl}tjddg}|j|d��y)Nrz-cz,from turtledemo.__main__ import main; main()F)�shellr[)�
subprocessr�
executable�Popen)rr]r�cmds    r$r�zEditorWindow.open_turtle_demos1����~�~��=�?��	����E��*�r&c���|�p|dkDrj|jjdd|z�|jjddd�|jjddd�|j	�yyy)NrrCz%d.0rErFrqz
insert +1l)rLrTrSrU�center)rr�s  r$�gotolinezEditorWindow.gotolinesc����&�1�*��I�I���x��&��9��I�I� � ���u�5��I�I���e�X�|�<��K�K�M�	#-�r&c�v�|rtjj|�rytjjtjj	|��\}}tjj|�tvry|jjdd�}|jd�xrd|vS)NTrFz1.0 lineendz#!�python)
rxryr~�splitextr9�normcaserrLr��
startswith)rr�base�extrXs     r$r�zEditorWindow.ispythonsource&s����2�7�7�=�=��2���G�G�$�$�R�W�W�%5�%5�h�%?�@�	��c�
�7�7���C� �M�1���y�y�}�}�U�M�2�����t�$�9��T�)9�9r&c�b�|jr#|jj|�d|_yyr&)r��unregister_maybe_terminater�s r$�
close_hookzEditorWindow.close_hook/s'���:�:��J�J�1�1�$�7��D�J�r&c��||_yr&)r!)rr!s  r$�set_close_hookzEditorWindow.set_close_hook4s	��$��r&c���|jr|jj|�|j�|jj	|�|j�yr&)r��filename_changed_editr�r��update_windowlist_registryr�r�s r$r�z!EditorWindow.filename_change_hook7sE���:�:��J�J�,�,�T�2���� ����+�+�D�1����r&c��|jry|j|jj�r|j	�|_|jr2|j
j
|j|j��yy)N)�filter�after)r�r�r�rr*r��insertfilterafterr�r�s r$�
_addcolorizerzEditorWindow._addcolorizer>s_���:�:�����t�w�w�/�/�0��,�,�.�D�J��:�:��H�H�&�&�d�j�j��	�	�&�J�r&c��|jsy|jj�|jj|j�d|_yr&)r��removecolorsr��removefilterr�s r$�_rmcolorizerzEditorWindow._rmcolorizerGs9���z�z���
�
���!������d�j�j�)���
r&c��|j�|j�tj|j�|j
�|j
j
�|j�|jj�yy)zUpdate the color themeN)	r/r+r(r+rLr��update_highlight_colorsr��
update_colorsr�s r$r�zEditorWindow.ResetColorizerNso��	
���������!�!�$�)�)�,����(����5�5�7����(����+�+�-�)r&�_c�0�|jd|�|j|�}|r$||jvr|jd|dz|�d|j|�k(r|jd|�n|jd|dz�|j	|�y)N�ERRORz
 wordstart�
rCz+1c)rUr��
IDENTCHARSrTrV)rrL�pos�chars    r$�colorize_syntax_errorz"EditorWindow.colorize_syntax_error]s{�����W�c�"��x�x��}���D�D�O�O�+��L�L��#��"4�c�:��4�8�8�C�=� ��M�M�(�C�(��M�M�(�C�%�K�0�����
r&c��tjdddd��}|sd|jd<ytj|jd<y)	z&Update the cursor blink configuration.rGr(zcursor-blinkrmrJrroN)rr�rLrn)r�cursorblinks  r$r�z EditorWindow.update_cursor_blinkhsC���(�(����V�E���)*�D�I�I�o�&�*2�)@�)@�D�I�I�o�&r&c��|j�|jj�|j�|jj�tj|j
dd�}||jd<|j�y)z.Update the text widgets' font if it is changedNrGr(rk)r��update_fontr�rr�r�rLr�)r�new_fonts  r$�	ResetFontzEditorWindow.ResetFontrsr�����(����)�)�+����(����)�)�+��#�#�D�I�I�v�~�F��$��	�	�&�����r&c�|�tj�x|j_}|j	�D]"\}}|j
j|g|����$|j�D]O}tj|�}|s�|j	�D]"\}}|j
j|g|����$�Qy)zgRemove the virtual, configurable keybindings.

        Leaves the default Tk Text keybindings.
        N)	r�GetCurrentKeySetr/�default_keydefs�itemsrL�event_delete�get_standard_extension_names�GetExtensionBindings)r�keydefsr]�keylist�
extensionName�xkeydefss      r$�RemoveKeybindingszEditorWindow.RemoveKeybindings�s���3;�2K�2K�2M�M��
�
�%��%�m�m�o�N�E�7�"�D�I�I�"�"�5�3�7�3�.�!�>�>�@�M��4�4�]�C�H��&.�n�n�&6�N�E�7�*�D�I�I�*�*�5�;�7�;�'7�Ar&c�
�tj�x|j_}|j	�|j�D]+}tj|�}|s�|j	|��-i}|jjD]4}i||d<|dD]"}|s�|d||dt|d�d<�$�6|jD]�}|j|}|jt�}|��*|dz
}td|�D]u}	|j|	�dk(s�|j|	d�}
|
s�-|j|	d�}d}||vr|||vr|||}|s�Wt||�}
|j!|	|
���w��y)	zeApply the virtual, configurable keybindings.

        Also update hotkeys to current keyset.
        rraNrf�acceleratorr{rB)rN)rrBr/rCr�rFrG�menudefsr�r�r�r�rPrK�	entrycget�get_acceleratorr�)
rrHrJrK�
menuEventDictrDr��menubarItemrqr��accel�itemNamer]s
             r$�ApplyKeybindingszEditorWindow.ApplyKeybindings�s���3;�2K�2K�2M�M��
�
�%������!�>�>�@�M��4�4�]�C�H���#�#�H�-�A��
��M�M�*�*�D�%'�M�$�q�'�"��Q����BF�q�'�M�$�q�'�*�7�4��7�+;�A�+>�?� �+�
 �=�=�K��=�=��-�D��*�*�S�/�C��{���1�H�C��q�#����9�9�U�#�y�0� �N�N�5�-�@�E��#'�>�>�%��#A�� "��&�-�7�'�=��+E�E�(5�k�(B�8�(L�� �$3�G�U�$C�E� �,�,�U��,�F�'�)r&c�Z�|jstjdddd��|_yy)zCUpdate the indentwidth if changed and not using tabs in this windowrGrlz
num-spacesrIrJN)r�rr�r�r�s r$r�z#EditorWindow.set_notabs_indentwidth�s,���|�|�'�1�1�&�(�<�7<� >�D��r&c�t�tj�}|jd}|jt�}||j
kDr|j
|j
dz|�|rA|j�|D],}|j|d�}|j|d|���.||jd<y)z4Update the additional help entries on the Help menu.rrarr�N)
r�GetAllExtraHelpSourcesListr�r�r�r�r�r��_extra_help_callbackr�)r�	help_list�helpmenu�helpmenu_length�entryrs      r$r�z$EditorWindow.reset_help_menu_entries�s����7�7�9�	��=�=��(��"�.�.��-���T�6�6�6��O�O�T�6�6��:�_�M���"�"�$�"���/�/��a��9���$�$�5��8�S�$�A�#�!)��
�
�f�r&c���|f�fd�	}|S)z9Return a callback that loads resource (file or web page).c�l��|jd�stjj|�}tj
dddk(r	tj|�ytj|�y#t$r5}tjdt|��j��Yd}~yd}~wwxYw)N)�www�httpr@rAr�r�)rrxryr�rr|r�r�rr�rRrLr�r�)�helpfiler�rs  �r$�display_extra_helpz=EditorWindow._extra_help_callback.<locals>.display_extra_help�s�����&�&��7��7�7�+�+�H�5���|�|�B�Q��5�(�<��L�L��*�
����)��	�<��(�(�/G� #�C�����<�<��<�s�	A5�5	B3�>+B.�.B3r\)r�resourcerds`  r$rZz!EditorWindow._extra_help_callback�s���(0�
	*�"�!r&c��g}|j}|rFtjj|�r't	|dd��5}|j�}ddd�|rItjj
|�dz}||vr|j|�|jd|�g}|D]:}d|vs#tjj|dd�r�*|j|��<|D�cgc]	}||vs�|��}}d	}|dt|�}|r*	t	|d
dd��5}|j|�ddd�|j&j(D]u}
|
j*}|j-dt.�t1|�D]C\}}
|
j3�}
|
j5|
�}|j7||dz|
z|d���E�wy#1swY��uxYwcc}w#1swY��xYw#t$rY}	t|jdd�s7d
|j_t!j"dd|	�d�|j$��Yd}	~	��
d}	~	wwxYw)z/Load and update the recent files list and menus�utf_8r)r.�errorsNr6r�rr�1234567890ABCDEFGHIJK�w�recentfiles_messageFTzIDLE Warningz)Cannot save Recent Files list to disk.
  z
Select OK to continue.r�rA)r{rfr|)r�rxryr�r��	readlines�abspath�removerC�appendrQ�
writelinesr�r�r�rlr�showwarningrLr�r�r�r�r��	enumerate�rstrip�#_EditorWindow__recent_file_callbackr�)r�new_file�rf_listr�rf_list_file�	bad_pathsry�ulchars�rf_file�err�instancerD�i�	file_name�callbacks               r$r�z%EditorWindow.update_recent_files_list�s#�����*�*�	�������	�2��i�&�y�:�=I�&�0�0�2��:���w�w���x�0�4�7�H��7�"����x�(��N�N�1�h�'��	��D��t�|�2�7�7�>�>�$�q��*�#=�� � ��&��%,�E�G�D�t�9�/D�4�G��E�)���!�C��L�)���
*��)�S�#*�9�>�AH��&�&�w�/�>����.�.�H��-�-�D��K�K��3�� )�'� 2���9�%�,�,�.�	�#�:�:�9�E��� � �w�q�z�C�'7�)�'C�)1�+,�!�.�!3�/�=:�:��F�
>�>���
*��t�y�y�*?��G�48�D�I�I�1��*�*��!%�%(�E�*9�!9� $�y�y�	*���
*�sH�G�'	G�1G�
G �G�+G �G�G�G � 	I�)AH=�=Ic���|f�fd�	}|S)Nc�>���jj|��y)N)�editFile)r�r�)�
fn_closurers �r$�open_recent_filez=EditorWindow.__recent_file_callback.<locals>.open_recent_files����G�G�L�L�*�L�-r&r\)rrr�s`  r$�__recent_file_callbackz#EditorWindow.__recent_file_callbacks���(1�	.��r&c��|j�}|j�}|r&|r$tj�s|dz|ztz}n|r|}n|r|}nd}|xs|xs|}|j�s
d|z}d|z}|jj|�|jj|�tj�rH|jjd|�|jjd|j��yy)Nz - �untitledz*%s*z*%sz
-titlepathz	-modified)
�short_title�
long_titler
�	isCocoaTk�_py_version�	get_savedr��wm_title�wm_iconname�
wm_attributes)r�short�longr��icons     r$r�zEditorWindow.saved_change_hooks���� � �"����� ���T�&�"2�"2�"4��E�M�D�(�;�6�E�
��E�
��E��E��%��%����~�~���U�N�E��4�<�D������%� ������T�"������H�H�"�"�<��6�
�H�H�"�"�;�D�N�N�4D�0D�E�r&c�6�|jj�Sr&)r�r�r�s r$r�zEditorWindow.get_saved/s���y�y�"�"�$�$r&c�:�|jj|�yr&)r��	set_saved)r�flags  r$r�zEditorWindow.set_saved2s���	�	���D�!r&c�8�|jj�yr&)r��
reset_undor�s r$r�zEditorWindow.reset_undo5s���	�	���r&c�t�|jj}|rtjj	|�SdS)Nr�)r�rrxryr9)rrs  r$r�zEditorWindow.short_title8s-���7�7�#�#��-5�r�w�w����)�E�:�Er&c�6�|jjxsdS)NrB)r�rr�s r$r�zEditorWindow.long_title<s���w�w���%�2�%r&c�$�|j�yrZ)rr's  r$r�z EditorWindow.center_insert_event?s�����
�r&c���|j}|j�\}}|j|�}||z
}td||dzz
�}|j	t|��y)NrarC)rL�getwindowlinesr��maxr�r�)r�markrLr��botr�rP�newtops        r$rzEditorWindow.centerCsY���y�y���&�&�(���S�����%���s����Q�����*�+���
�
�5��=�!r&c���|j}|jd�}|jd�}||k(r)|j�dk(rt|d�}||zdz
}||fS)Nr�z@0,65535rarP)rLr��winfo_heightrI)rrLr�r�rPs     r$r�zEditorWindow.getwindowlinesKsc���y�y���n�n�V�$���n�n�Z�(���#�:�$�+�+�-��2���h��(�F���,��"�C��C�x�r&c�`�|j}tt|j|���Sr&)rLrIr�r�)rr�rLs   r$r�zEditorWindow.getlinenoUs$���y�y���5����D�)�*�+�+r&c��|jj�}tjd|�}t	tt|j���S)zReturn (width, height, x, y)z(\d+)x(\d+)\+(-?\d+)\+(-?\d+))r��wm_geometry�re�match�listr,rI�groups)r�geom�ms   r$�get_geometryzEditorWindow.get_geometryYs=���x�x�#�#�%���H�H�5�t�<���C��Q�X�X�Z�(�)�)r&c�$�|j�yrZ)r�r's  r$r�zEditorWindow.close_event_s���
�
��r&c�F�|jr�|j�sk|jj�dk7r|jj	�|jj�|jj
�|jj�Sy)Nr�)r�r�r�rL�	deiconify�lower�lift�	maybesaver�s r$r�zEditorWindow.maybesavecsi���7�7��>�>�#��8�8�>�>�#�X�-��H�H�&�&�(������ ����
�
���7�7�$�$�&�&�
r&c��	|j�}t|�dk7r|j�|S#t$rYywxYw)N�cancel)r�rR�_close�AttributeError)r�replys  r$r�zEditorWindow.closels?��	��N�N�$�E��5�z�X�%����
��L���	��	�s�/2�	>�>c�P�|jjr&|j|jj��tj|j
�|j
�|jj�d|_d|_|jr!|jj�d|_	d|_
d|_|jj�d|_|jj�|jr|j�yy)N)rv)r�rr�r�unregister_callbackr��unload_extensionsr�r�r�rLr�r�r��destroyr!r�s r$r�zEditorWindow._closeus����7�7����)�)�4�7�7�3C�3C�)�D��"�"�4�#7�#7�8���� ����
�
�������	��:�:��J�J�����D�J���	� �������������������?�?��O�O��r&c�2�i|_|j�yr&)�
extensions�load_standard_extensionsr�s r$r�zEditorWindow.load_extensions�s������%�%�'r&c��t|jj��D]}t|d�s�|j	��!i|_y)Nr�)r�r��valuesr�r�)r�inss  r$r�zEditorWindow.unload_extensions�s:������.�.�0�1�C��s�G�$��	�	��2���r&c��|j�D]}	|j|��y#tdt|��t	j
�Y�ExYw)NzFailed to load extension)rF�load_extension�print�repr�	traceback�	print_exc)rrFs  r$r�z%EditorWindow.load_standard_extensions�sJ���5�5�7�D�
&��#�#�D�)�8��
&��0�$�t�*�=��#�#�%�s	�)�+Ac�.�tjd��S)NT)�editor_only)r�
GetExtensionsr�s r$rFz)EditorWindow.get_standard_extension_names�s���%�%�$�7�7r&�ZzDummy�zzdummyc���|jj||�}		tjd|zt��}t||�}tj|�}t|d�r|j|j|�||�}||j|<|r�|j|�|D]x}|j!dd�}|dddk(r|dd}|dddk(r�|d	dd
k(r|dd	}|d	dd
k(r�|dz}t||�s�S|j"j%|t||���zyy#t
tf$rtj|�}Y��wxYw#t
$rtd|��wxYw)Nr@)�packagez
Failed to import extension: rO�-r3rarIrrrK�_event)�extfilesr��	importlib�
import_module�__package__�ImportError�	TypeErrorr�r�rrGr�r�rOr�r�rrLr�)	rrF�fname�mod�clsrHr��vevent�
methodnames	         r$r�zEditorWindow.load_extension�sz���
�
�!�!�$��-��	�
5��-�-�c�E�k�;�O���c�4� ���/�/��5���3�
�#��O�O�C�L�L�'�2��$�i�� #�����������(�!��#�^�^�C��5�
� ��!�n��+�!+�A�B��J�!��!�n��+� ���o��,�!+�C�R��J�!���o��,�'�(�2�
��3�
�+��I�I�N�N�6�7�3�
�+C�D�"��� ��+�
5��-�-�e�4��
5���	��2�D�9��	�s#�D/�/$E�E�E�E�E1c��|�|jj}|j}||_|j	�D]\}}|s�	|j
|g|����y)z"Add events with keys to self.text.N)r/rCrLrHrDr�)rrHrLr]rIs     r$r�zEditorWindow.apply_bindings�sP���?��m�m�3�3�G��y�y�����%�m�m�o�N�E�7������u�/�w�/�.r&c	���|�|jj}|�|jj}|j}|j}|D]�\}}|j|�}|s�|D]�}|�|j
��|\}	}
|	dddk(}|r|	dd}	t|	�\}}	t||
�}
||
fd�}|r-|j|
t�}|j|	|||
|���y|j|	|||
������y)z�Fill in dropdown menus used by this window.

        Items whose name begins with '!' become checkbuttons.
        Other names indicate commands.  None becomes a separator.
        Nra�!c�&�|j|�yr&r�r�s  r$rfz(EditorWindow.fill_menus.<locals>.command�s���+�+�I�6r&)r{r|rfrN�variable)r{r|rfrN)
r/rOrCr�rLr�r�r�rQ�get_var_obj�
BooleanVar�add_checkbuttonr�)rrOrHr�rL�mname�	entrylistrDr^r{r��checkbuttonr|rNrf�vars                r$r�zEditorWindow.fill_menus�s�����}�}�-�-�H��?��m�m�3�3�G��=�=���y�y�� (��E�9��<�<��&�D���"���=��&�&�(�',�$�E�9�#(��!�9��#3�K�"� %�a�b�	��'.�u�~�$�I�u�"1�'�9�"E�K�%)�Y�7�"�"�.�.�y�*�E���,�,�5�I�$+��%(�-�*��(�(�u�	�18�5@�)�B�%#�	!)r&c�b�|j|�}|r|j�}|St|��r&)r�r��	NameError)rrFr��values    r$�getvarzEditorWindow.getvar�s/�����t�$����G�G�I�E��L��D�/�!r&c�d�|j||�}|r|j|�yt|��r&)r�r�r�)rrFr��vartyper�s     r$�setvarzEditorWindow.setvar�s,�����t�W�-����G�G�E�N��D�/�!r&c��|jj|�}|s#|r!||j�x|j|<}|S)z:Return a tkinter variable instance for the event.
        )r�r�rL)rr�r�r�s    r$r�zEditorWindow.get_var_obj�sB�����#�#�I�.���w�18����1C�C�D���i�(�3��
r&c��|jr;|jjd|�xsd|jj|�vSy)N�TODO�STRINGra)r�rL�
tag_prevrange�	tag_names)r�
text_indexs  r$�is_char_in_stringzEditorWindow.is_char_in_stringsE���:�:��9�9�*�*�6�:�>�?��t�y�y�2�2�:�>�>�
?�r&c��	|jjd�}|jjd�}||fS#t$rYywxYw)NrGrJ�NNr�)rr[r\s   r$�get_selection_indicesz"EditorWindow.get_selection_indicessG��	��I�I�O�O�K�0�E��9�9�?�?�:�.�D��$�;����	��	�s�9<�	A�Ac�F�|jdxst}t|�S)N�tabs)rL�TK_TABWIDTH_DEFAULTrI)r�currents  r$�get_tk_tabwidthzEditorWindow.get_tk_tabwidth&s ���)�)�F�#�:�':���7�|�r&c	���|j}|j�|k7rC|jjdd|dd|jd|z�}|j|��yy)Nrkr1z
-displayof�n)r�)rLrr-r��master�	configure)r�newtabwidthrL�pixelss    r$�set_tk_tabwidthzEditorWindow.set_tk_tabwidth,s^���y�y�����!�[�0��W�W�\�\�&�)�T�&�\�".����"%��"3�5�F�
�N�N��N�'�1r&c���|rG|rE|j�}d|cxkrdkr
nn||_|j|jk7rd|_|j	|j�y)NrCrF)�guess_indentr�r�r�r)rr �guessr~s    r$r�z#EditorWindow.set_indentation_params7sS�����!�!�#�A��A�{��{�#$�� ����4�=�=�0�$������T�]�]�+r&c��|j}|j�\}}|r'|r%|j||�|jd|�y|j	dd�}|dk(r6|jddd�r|jd�y|j
�y|dd	vr|jd�y|j}t|j|��}|d
z
|jz|jz}d}		|dd}|	d
z}	t|j|��}||ks|dd	vrn�2|j�|jd|	zd�||kr#|jdd
||z
z|j�|j�y)NrCr[r?rBrKrFz	insert-1crr� 	rarz
insert-%dcrA)rLr�r�rTr�rN�bellr�rQ�
expandtabsr�r�rCr�r�)
rr]rLr[r\�charsr��have�want�
ncharsdeleteds
          r$r�z"EditorWindow.smart_backspace_event@s����y�y���0�0�2���t��T��K�K��t�$��M�M�(�E�*�����+�X�6���B�;��|�|�H�c�5�1����K�(���	�	����"�I�U�"��K�K��$���=�=���5�#�#�H�-�.�����d�.�.�.�$�2B�2B�B���
���#�2�J�E�)�A�-�M��u�'�'��1�2�D��t�|�u�R�y��5���	
�������L�=�0�(�;��$�;��K�K��#����"5��3�3�
5�����r&c�$�|j}|j�\}}|j�	|rh|rft|�t|�k7r+|jj|�|j
�S|j||�|jd|�|jdd�}t||j�\}}|t|�k(r|j||jz�ng|jrd}n;t|j!|j��}|j}	d|	||	zz
z}|j#d||j$�|j'd�	|j
�y#|j
�wxYw)NrCr?rBrAr[)rLr�r��
index2liner�r�r�r�rTr��get_line_indentr�rQ�reindent_tor�r�rrCr�rV)
rr]rLr[r\�prefix�raw�	effective�padrs
          r$r�zEditorWindow.smart_indent_eventksR���y�y���0�0�2���t�����	#����e�$�
�4�(8�8��<�<�;�;�E�B�(
� � �"�'���E�4�(��
�
�h��.��X�X�0�(�;�F�,�V�T�]�]�C�N�C���c�&�k�!�� � ��T�-=�-=�!=�>��<�<��C� #�F�$5�$5�d�m�m�$D� E�I��(�(�A���Y��]�!2�3�C����H�c�4�+F�+F�G��H�H�X���� � �"��D� � �"�s�5E=�7C4E=�=Fc���|j}|j�\}}|j�	|r&|r$|j||�|j	d|�|jdd�}dt
|�}}||kr||dvr|dz
}||kr||dvr�||k(r@|jdd|j�	|jd�|j�y|d|}d}|r|d	dvr|dd	}|dz
}|r|d	dvr�|r|jd
|zd�|jd�dvr%|jd�|jd�dvr�%|jdd|j�t|jd��}	tj|j|j �}
|j"s�|j$D]k}t'|	|z
d�}t)|�dz}
|j|
d�}|
j+|�|
j-|j/|
��}|�|dk(s�kn|
j1xsd�nP|j3dd�}|r|d}
nd
}
|j|
d�}|
j+|�|
j1d�|
j5�}|tj6k7r�|tj8k(rn�|tj:k(r|jd||j�n�|tj<k(r |j?|
jA��nd|tjBk(rQ|
jE�dkDr|jd||j�n |j?|
jG��		|jd�|j�y|
jI�}|jd||j�|
jK�r|jM|�n#|r!|
jO�r|jQ|�	|jd�|j�y#|jd�|j�wxYw)a�Insert a newline and indentation after Enter keypress event.

        Properly position the cursor on the new line based on information
        from the current line.  This takes into account if the current line
        is a shell prompt, is empty, has selected text, contains a block
        opener, contains a block closer, is a continuation line, or
        is inside a string.
        rCr?rrrar6r[Nrrzinsert - %d charsr��consolerF))rLr�r�r�rTr�rQrCr�rVr�rr�r�Parserr�r�r�r�r�r��set_code�find_good_parse_start�_build_char_in_string_func�set_lor��get_continuation_type�C_NONE�C_STRING_FIRST_LINE�C_STRING_NEXT_LINES�	C_BRACKETr�compute_bracket_indent�C_BACKSLASH�get_num_lines_in_stmt�compute_backslash_indent�get_base_indent_string�is_block_openerr��is_block_closerr�)rr]rLr[r\rXr~r�indent�lnor��context�startat�startatindex�rawtext�bod�rrDs                  r$r�z%EditorWindow.newline_and_indent_event�s���y�y���0�0�2���t�����e	#������E�4�(��
�
�h��.��8�8�.��9�D��c�$�i�q�A��a�%�D��G�u�,��Q����a�%�D��G�u�,��A�v����.�� �7�7�9��j
�H�H�X��� � �"�k�"�1�X�F��A��4��8�u�,��C�R�y���Q����4��8�u�,�����/�!�3�X�>��(�(�8�$��-����H�%��(�(�8�$��-�
�K�K��$��(C�(C�D��T�Z�Z��1�2�C����t�/�/����?�A��(�(�#�5�5�G�!�#��-��3�G�#'��=�4�#7�L�"�h�h�|�X�>�G��J�J�w�'��1�1� �;�;�L�I�K�C���'�Q�,�� 6�������"��&�&�y�(�;���#$�Q�4�L�#(�L��(�(�<��:���
�
�7�#�������'�'�)�A��G�N�N�"���3�3�3���'�5�5�5��K�K��&�$�2M�2M�N��'�+�+�+�
�$�$�Q�%=�%=�%?�@��'�-�-�-��.�.�0�1�4����H�f�$(�$?�$?�A��(�(��)C�)C�)E�F��
�H�H�X��� � �"��-�-�/�F��K�K��&�$�*E�*E�F�� � �"��'�'��.��A�-�-�/��*�*�5�1���H�H�X��� � �"��
�H�H�X��� � �"�s4�A$Q�"Q�#Q�?AQ�C#Q�2E(Q�=A2Q�#Q5c�&�||jfd�}|S)Nc��||d|zz�S)Nz+%dcr\)�offset�_startindex�_iciss   r$�innerz6EditorWindow._build_char_in_string_func.<locals>.inners����v���6�7�7r&)r�)r�
startindexr;s   r$r z'EditorWindow._build_char_in_string_funcs��&0��.�.�	8��r&c�l�|jr$t||j�\}}d|zd|zzSd|zS)NrBrA)r��divmodr�)rr�ntabs�nspacess    r$�_make_blankszEditorWindow._make_blankss9���<�<�#�A�t�}�}�5�N�E�7��%�<�#��-�/�/���7�Nr&c��|j}|j�|jddd�r|jdd�|r,|j	d|j|�|j�|j�y)Nr?z!=rC)rLr�rNr�rCrAr�r�)rrhrLs   r$rzEditorWindow.reindent_to sj���y�y�������<�<�*�D�(�;��K�K�*�H�5���K�K��$�"3�"3�F�";��3�3�
5����r&c���t|j�j�\}}|r9|r7t||j�\}}t||j�\}}||z
Sdx}}||z
S�Nr)�IndentSearcherrLrrrr�)r�opener�indentedr�indentsmall�indentlarges      r$r	zEditorWindow.guess_indent/sq��)�$�)�)�4�8�8�:�����h�.�v�t�}�}�E��C��.�x����G��C���[�(�(�)*�)�K�+��[�(�(r&c���|j�y|jjr|jj�d}n|jj�d}|j	dd|�d���y)N�Show�Hidersruz
 Line Numbers)rDr�r{)r��is_shown�hide_sidebar�show_sidebarr�)rr]�
menu_labels   r$rz&EditorWindow.toggle_line_numbers_event8sp�����$�����%�%����*�*�,��J����*�*�,��J����I�]�(2�|�=�%A�	�	Cr&)NNNNr&)rCr�)T)�r	�
__module__�__qualname__�idlelib.percolatorr)�idlelib.colorizerr*r+�idlelib.undor,�idlelib.iomenur-r.r
r/�idlelib.statusbarr0�idlelib.autocompleter1�idlelib.autoexpandr2�idlelib.calltipr3�idlelib.codecontextr4�idlelib.sidebarr5�idlelib.formatr6r7r8r9�idlelib.parenmatchr:�idlelib.zoomheightr;r�getfilesystemencoding�filesystemencodingrwrrr�r$r�r�r�r�r�rgr�r�r�r�rr�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�rr�r�r�r�rr�r!r#r�r+r/r��string�
ascii_letters�digitsr7r:r�r@rLrVr�r�rZr�rur�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�rFr�r�r�r�r�r�r�r�r�rrr�r�r�r�r rArr	rr\r&r$r(r(3s���-�>�*�2� �0�1�-�'�/�+�M�M�-�-�2��2�2�4���H�����!��aI�F	�4��
)�V7� ;��&�J�#'�J)�1�
1�
	�
�E�!�J	,��K�

�'�4�����	����
��
�(���������0�	��
��:��
%��K��.��%�%��
�
�5��;�J�	�A��"
<�&G�P>�)�"
"�,.�\ �
F�6%�"��F�&��"��,�*��'���((��&�8�	�9�
�H�E�80�$B�L"�"��$���(�,�)�V!#�Fq#�p� ��)�Cr&r(c�*�tt|��Sr&)rIr�)r�s r$rrFs���u�U�|��r&z[ \t]*c��tj|�}|j�t|j	�j|��fS)z�Return a line's indentation as (# chars, effective # of spaces).

    The effective # of spaces is the length after properly "expanding"
    the tabs into spaces, as done by str.expandtabs(tabwidth).
    )�_line_indent_rer�rqrQ�groupr)rXr�r�s   r$rrKs;��	���d�#�A��5�5�7�C����	�,�,�X�6�7�7�7r&c�X�eZdZdZd�Zd�Zejejdfd�Z	d�Z
y)rEz4Manage initial indent guess, returned by run method.c�J�||_dx|_|_dx|_|_yrD)rLr~�finished�blkopenline�indentedline)rrLs  r$r$zIndentSearcher.__init__Xs'����	�!"�"�����/3�3���4�,r&c���|jry|jdzx}|_t|�dz}|jj	|dd�ry|jj||dz�S)NrBrar�z>=rqz lineend+1c)rkr~r�rLrNr�)rr~r�s   r$�readlinezIndentSearcher.readline]s`���=�=���V�V�a�Z���D�F��A�w��~���9�9���T�4��/���y�y�}�}�T�4�-�#7�8�8r&)�class�def�for�ifr��try�while�withc	��|jry||k(r||vr||_y||k(r|jr||_d|_yyy)Nra)rkrlrm)	rrK�token�startrqrX�INDENT�NAME�OPENERSs	         r$�
tokeneaterzIndentSearcher.tokeneaterfsI��
�=�=��
�T�\�e�w�.�#�D��
�V�^�� 0� 0� $�D���D�M�!1�^r&c���	tj|j�}|D]}|j|��	|j|jfS#tjt
f$rY�3wxYw)ztReturn 2 lines containing block opener and and indent.

        Either the indent line or both may be None.
        )�tokenize�generate_tokensror}�
TokenError�SyntaxErrorrlrm)r�tokensrxs   r$rrzIndentSearcher.runssk��
	��-�-�d�m�m�<�F��������'� �
����!2�!2�2�2���#�#�[�1�	��	�s�5A�A,�+A,N)r	rQrR�__doc__r$rorrzr{r}rrr\r&r$rErEUs.��:�4�
9�#�/�/� �
�
�-��3r&rEc�R�|jd�}|dk\r|d|||dzdz}||fS)z�Extract the underscore from a string.

    For example, prepstr("Co_py") returns (2, "Copy").

    Args:
        s: String with underscore.

    Returns:
        Tuple of (position of underscore, string without underscore).
    r3rNra)r�)�sr~s  r$r�r��s:��	
���s��A��A�v�
�b�q�E�A�a��c�d�G�O���a�4�Kr&�[�]�/)�bracketleft�bracketright�slashc�
�|j|�}|rtj�r|dvry|d}tjdd�|�}tjdd�|�}tjdd|�}tjd	d
|�}tjdd|�}tjd
d|�}tjdd|�}tjdd|�}tjdd|�}|S)akReturn a formatted string for the keybinding of an event.

    Convert the first keybinding for a given event to a form that
    can be displayed as an accelerator on the menu.

    Args:
        keydefs: Dictionary of valid events to keybindings.
        eventname: Event to retrieve keybinding for.

    Returns:
        Formatted string of the keybinding.
    >r_rXr`rBrz-[a-z]\bc�>�|j�j�Sr&)rh�upper�r�s r$r^z!get_accelerator.<locals>.<lambda>�s��a�g�g�i�o�o�&7r&z\b\w+\bc�f�tj|j�|j��Sr&)�keynamesr�rhr�s r$r^z!get_accelerator.<locals>.<lambda>�s��X�\�\�!�'�'�)�Q�W�W�Y�%Gr&zKey-�Cancelz
Ctrl-BreakzControl-zCtrl-r��+z><rArIrK)r�r
r�r��sub)rHr�rIr�s    r$rQrQ�s����k�k�)�$�G�
��)�)�+�	�>6�16����
�A�
���{�7��;�A�
���z�G��K�A�
���v�r�1��A�
���x��q�)�A�
���z�7�A�&�A�
���s�C���A�
���t�S�!��A�
���s�B���A�
���s�B���A��Hr&c��|j}|jddd�|jddd�|jddd�y)	N�tcl_wordBreakAfterza brr��
tcl_wordcharsz\w�tcl_nonwordcharsz\W)r-r�)r�r-s  r$�
fixwordbreaksr��s?��
���B��G�G� �%��+��G�G�E�?�E�*��G�G�E�%�u�-r&c�@�|}t|�tjddrtjd}nd}tj|d�t||��}|j}d|d<td�D]&}|jdd|zt|�zdz��(y)	Nra)r�r�
rP�rCz  r6)
r�r�argvr
�setupAppr(rLrPrCrR)r�r�rrnrLr~s      r$�_editor_windowr��s����D��$��
�x�x���|��8�8�A�;����
�O�O�D�$���T�H�5�D��9�9�D��D��N�
�2�Y�����H�d�1�f�s�1�v�o��4�5�r&�__main__)rGzidlelib.idle_test.test_editorrCF)�	verbosity�exit)rr):�
importlib.abcr��importlib.utilrxr|r�rbrrr�r��tkinter�tkinter.fontr�tkinter.ttkrrr�idlelib.configrr
r	r
rrr
�idlelib.multicallrrrrr�idlelib.treer�idlelib.utilrrr��python_versionr�rr%r(r�compilergrrEr�r�rQr�r�r	�unittestrG�idlelib.idle_test.htestrrr\r&r$�<module>r�s����	��	�
�
������!� ��#� �����.�����$�&�����/��/�/�1�1��	����	!��
�PC�PC�f0��"�*�*�Y�'��8�*3�*3�^�$��

���(
�V.�
6�&�z����	(�A�E�B�+����r&

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists