HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/idlelib/__pycache__/editor.cpython-310.opt-1.pyc
o

�iQ�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlTddlm
Z
ddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddlm$Z$dZ%de�&�Z'ejdkZ(dd�Z)Gdd�d�Z*dd�Z+e�,d�Z-dd �Z.Gd!d"�d"�Z/d#d$�Z0d%d&d'd(�Z1d)d*�Z2d+d,�Z3d-d.�Z4e5d/kr�dd0l6m7Z7e7d1d2d3d4�dd5l8m9Z9e9e4�dSdS)6�N)�*)�Font)�	Scrollbar)�simpledialog)�
messagebox)�idleConf)�configdialog)�grep)�help)�
help_about)�macosx)�MultiCallCreator)�pyparse)�query)�replace)�search)�wheel_event)�
py_extensions)�window�z (%s)�darwincCsdtj\}}}}}d||f}|d|f7}|dkr"|d|f7}|S|dkr0|d|d|f7}|S)zYFormat sys.version_info to produce the Sphinx version string used to install the chm docsz%s%sz%s�	candidatezrc%s�finalr)�sys�version_info)�major�minor�micro�level�serial�release�r!�+/usr/local/lib/python3.10/idlelib/editor.py�_sphinx_version&s�r#c@s4eZdZddlmZddlmZmZddlm	Z	ddl
mZmZddl
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZmZmZddl m!Z!ddl"m#Z#e$�%�Z&dZ'dZ(dZ)dZ*d�dd�Z+d�dd�Z,dd�Z-dd�Z.dd�Z/dd�Z0d�dd�Z1gd �Z2d!d"�Z3d#d$�Z4d%d&�Z5d'd(�Z6d)d*�Z7dZ8d+d,�Z9d-gZ:d.d/�Z;d0d1�Z<d2d3�Z=d4d5�Z>d�d6d7�Z?d�d8d9�Z@d�d:d;�ZAd�d<d=�ZBd>d?�ZCd@dA�ZDdBdC�ZEd�dDdE�ZFd�dFdG�ZGdHdI�ZHdJdK�ZIdLdM�ZJdNdO�ZKdPdQ�ZLdRdS�ZMdTdU�ZNdVdW�ZOdXdY�ZPdZd[�ZQd\d]�ZRd�d^d_�ZSd�d`da�ZTd�dbdc�ZUddde�ZVdfdg�ZWdhdi�ZXdjdk�ZYdldm�ZZdndo�Z[dpdq�Z\drds�Z]e^j_e^j`dtZadudv�Zbdwdx�Zcdydz�Zdd{d|�Zed}d~�Zfdd��Zgd�d��Zhd�d��Zid�d�d��Zjd�d��Zkd�d��Zld�d��Zmd�d��Znd�d��Zod�d��Zpd�d��Zqd�d��Zrd�d�d��Zsd�d��Ztd�d�d��Zud�d��Zvd�d��Zwd�d��Zxd�d��Zyd�d��Zzd�d��Z{d�d��Z|d�d��Z}d�d��Z~d�d�iZd�d��Z�d�d�d��Z�d�d�d��Z�d�d��Z�d�d�d��Z�d�d�d��Z�d�d��Z�d�d��Z�d�dÄZ�d�dńZ�d�d�dDŽZ�d�dɄZ�d�d˄Z�d�d̈́Z�d�dτZ�d�dфZ�d�dӄZ�d�dՄZ�d�d�dׄZ�dS)��EditorWindowr)�
Percolator)�ColorDelegator�color_config)�
UndoDelegator)�	IOBinding�encoding)�mainmenu)�MultiStatusBar)�AutoComplete)�
AutoExpand)�Calltip)�CodeContext)�LineNumbers)�FormatParagraph�FormatRegion�Indents�Rstrip)�
ParenMatch)�
ZoomHeightNTcCs�	ddlm}tjdur�tj�tjdd�}tj	�
d�r:ddtjdd�}tj�d	�r.d
}n^d}tj�||dd�}nRtj	dd�dkrddl
}	d
}
dtj�d�}z	|	�|	j|�}
Wntyuz	|	�|	j|�}
Wn	tyrYnwYnwtj�|
�r~|
}n
tj	dkr�tj�tjd�}tj�|�}tj�|�r�|t_tj	dkr�dtjt_n
dtjdd�t_||_|p�|j}||_t|�|_tj||jd�|_}|r�|j|_|j|j_ni|_i|j_t j!o�tj�t j!d�|_"d
|_#t$|�|_%}
t&|
dd�|_'}t j(ddddd�}ddd d|d!t j(ddd"dd�d#�}t)t*�|
fi|��|_+}|j+|j_,|�-�|�.�|j�/d$|j0�|j�1d%|j2�t3�4��r]|�1d%|j2�|�1d&|j5�|�1d'|j5�n|�1d(|j5�|�1d)t6�|�1d*t6�|�1d+t6�|�1d,|j7�|�1d-|j8�|�1d.|j9�|�1d/|j:�|�1d0|j;�|�1d1|j<�|�1d2|j=�|�1d3|j>�|�1d4|j?�|�1d5|j@�|�1d6d7d8��|�1d9|jA�|�1d:|jB�|�1d;|jC�|�1d<|jD�|�1d=|jE�|�1d>|jF�|�1d?|jG�|�1d@|jH�|�1dA|jI�|�1dB|jJ�|�1dC|jK�|�L|�|_M}|�1dD|jN�|�1dE|jO�|�1dF|jP�|�1dG|jQ�|�1dH|jR�|�1dI|jS�|�T|�}|�1dJ|jU�|�1dK|jV�|�1dL|�Wd��|�1dM|�WdN��|�1dO|jX�|�1dP|jY�|�1dQ|jZ�|�r�||j|<|�r�||j[|<|�1dR|j\�|�1dS|jj]�|�1dT|j^�|�1dU|j_�|�1dV|j`�|�a�|
jbtctddNdW�|
jedNdNdX�|
jfdNdNdX�|jg|dY<|jhdNdtidZ�|jj|d[<t �k|jdd�|d\<|jhdNdNtidZ�|�l�|�m�t j(dd]d^d_d�}||_nd`|_o|jo|_p|�q�trt da��s|j+dbt _s|�t�dc|_u|�v|�|_w}|�x�|_y}|�z|�|j{|_{|j||_||�}|j~�|�|�|_�}|��|j��dd|_�|��dd�d|_�d|_�d|_�|�r�tj��|��r�tj�|��s�|��|��r�de|_�|��|�}|��|�n|��|�de|_�|���|�~�|���|���|j���df�}|�r�|��dg�}|du�r�dh}|dk�r�|���|dN}||_�t��|j��t�j�|_�t�j�|_�t�j�|_�|��didj�|��dkdldmdn�|��dodp�|��dqdr�|��dsdrdtdu�|��||j��}|�1di|j��|�1dk|j��|�1dv|j��|�1dw|��|�j��|�1dx|��|�j��|��|�}|�1dy|j��|�1ds|j��||�}|�1dz|j��|�1d{|j��|�1d||j��|�1d}|��|�j��|��|�|_�}|�1do|j��|�1dq|j��|�1d~|j��|�1d|��|�j��|j��r�|��|�|_�|�1d�|j�j��n|��d�d�d��|j��r�|��|�|_�t j(ddd�d_d��r�|���|�1d�|j��dS|��d�d�d��dS)�Nr)�
ScriptBindingZDocz
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�ZnoneZ
wordprocessor�height)r@�padx�wrapZhighlightthicknessrBZtabstylerHZWM_DELETE_WINDOW�<<close-window>>z<Control-Button-1>z<2>z<3>z<MouseWheel>z
<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>>cSsdS�N�breakr!��eventr!r!r"�<lambda>�sz'EditorWindow.__init__.<locals>.<lambda>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)Zweight�command)�row�columnZstickyZyscrollcommand�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)�Zidlelib.runscriptr8r$�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�menubarrZListedToplevel�top�vars�tkinter_varsZinversedict�
instance_dictrZuserdir�recent_files_path�prompt_last_line�Frame�
text_framerr?�	GetOptionr
ZTextrFZfocused_widget�
createmenubar�apply_bindings�protocol�close�bind�close_eventrZisAquaTk�right_menu_eventr�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_eventr3�fregion�indent_region_eventZdedent_region_eventZcomment_region_eventZuncomment_region_eventZtabify_region_eventZuntabify_region_eventr4Ztoggle_tabs_eventZchange_indentwidth_event�move_at_edge_if_selection�
del_word_left�del_word_right�
home_callback�dict�new_callbackZclose_all_callback�open_module_browser�open_path_browser�open_turtle_demo�set_status_bar�packZLEFTZBOTHZrowconfigureZcolumnconfigure�handle_yviewZgridZNSEW�set�GetFontZ	focus_set�	set_width�usetabs�tabwidth�indentwidth�set_notabs_indentwidth�hasattrr^�update_cursor_blink�num_context_linesr%�perr(�undoZinsertfilter�undo_block_start�undo_block_stopZset_saved_change_hook�saved_change_hookr)�ioZset_filename_change_hook�filename_change_hookZ	good_load�set_indentation_params�color�code_context�line_numbers�exists�loadfile�ispythonsourceZset_filename�ResetColorizer�update_recent_files_list�load_extensions�menudict�get�index�
add_separator�	wmenu_endZregister_callback�postwindowsmenurZ
askintegerrZaskyesno�	showerror�	event_addr-�user_input_insert_tagsZautocomplete_eventZtry_open_completions_eventZforce_open_completions_eventr.Zexpand_word_eventr2Zformat_paragraph_eventr6Zflash_paren_eventZparen_closed_eventZcheck_module_eventZrun_module_eventZrun_custom_eventr5Z	do_rstripr/�ctipZtry_open_calltip_eventZrefresh_calltip_eventZforce_open_calltip_eventr7Zzoom_height_event�allow_code_contextr0Ztoggle_code_context_event�update_menu_state�allow_line_numbersr1�toggle_line_numbers_event)�selfrv�filename�keyrwr8ZdochomeZpyverZbasepathrnZdocfileZKEYrzr�r?rBZtext_optionsrFr��indentsZ	usespacesr�r�r��	is_py_srcr>raZautocompleteZ
parenmatchZ
scriptbindingr�r!r!r"�__init__Is�

������

�
��

���







�



�



����
�
��zEditorWindow.__init__cCs|��dS�N)r��r�rPr!r!r"r�k�zEditorWindow.handle_winconfigcCs^|j}tt|jj|�d�|�d�g��}|��d|}t||�d�d��d�}|||_	dS)NZborderrIr=r[)r[�0)
rF�sum�map�tkZgetintZcgetZwinfo_widthr�measurerB)r�rFZ
inner_paddingZpixel_widthZzero_char_widthr!r!r"r�ns��zEditorWindow.set_widthcCs|j��\}}|j�|�dSrM)r�Zdefaultfilenamerv�new)r�rP�dirname�basenamer!r!r"r�{szEditorWindow.new_callbackcCs�|jd@dkr|jdkrdS|j�d�r2|j�ddd�r2|j�ddd�r2t|j�d��d�d	�}n|j�dd�}tt	|��D]
}||d
vrInq?t	|�}t|j�d��d�d	�}||krad}dt
|�d
}|jd	@dkry|j�ddd�nV|j�d�s�|j�dd�n|j�|j�d�d|j�d��r�|j�dd�n|j�dd�|j�|�}|j�d�}|j�|d|�r�||}}|j�ddd�|j�
d||�|j�d|�|j�d�dS)N�rZHomeZiomark�<=zinsert lineend�insert linestart�.rT)� �	�insertzinsert linestart+�c�sel�1.0ra�	sel.firstZ	my_anchor�<�sel.last�>rN)�stateZkeysymrFr��comparerC�splitr��range�len�str�
tag_remove�mark_set�tag_add�see)r�rPZinsertpt�lineZlineat�dest�first�lastr!r!r"r��sH���
�
zEditorWindow.home_callbackcCs�|�|j�|_t|jdddd�}tjdkr|jjddtd�|jjdd	td�|jjd
dtd�|jjt	t
d�|jt	t
d�|j�d
|j
�|j�d
dd�|j�|j
�dS)NrTZgrey75)rHZborderwidthZ
backgroundrZ	_padding1z    )rUrZzCol: ?r�zLn: ?)rUrVz<<set-line-and-column>>z<KeyRelease>z<ButtonRelease>)r,rz�
status_barr�rrk�	set_labelZRIGHTr�ZBOTTOM�XrFr��set_line_and_columnr�Z
after_idle)r��sepr!r!r"r��s
�zEditorWindow.set_status_barcCs>|j�t��d�\}}|j�dd|�|j�dd|�dS)Nr�rZzCol: %sr�zLn: %s)rFr�ZINSERTr�rr)r�rPr�rZr!r!r"r�sz EditorWindow.set_line_and_column))�fileZ_File)�editZ_Edit)�formatZF_ormat)�runZ_Run)rcZ_Options)rZ_Window)r
Z_HelpcCs�|j}i|_}|jD]'\}}t|�\}}t||�d�d�}t||d|d�||<}|j|||d�qt��rIt|ddd�|d<}|jd|d	�|�	�t|jdd
�|_
|jdjdd
d|j
d�|jd�t
�|_|��dS)NZ_menu_postcommandr)r@�tearoff�postcommand)�labelr>�	underlineZapple)r@rZapplicationZIDLE)rr>�rrr:zRecent Files)rrr>r
)ryr��
menu_specs�prepstr�getattrrxZadd_cascaderZ
isCarbonTk�
fill_menus�recent_files_menuZinsert_cascader��END�base_helpmenu_length�reset_help_menu_entries)r�Zmbarr�r@rrr
r>r!r!r"r��s,
���zEditorWindow.createmenubarcCsJ|jd}|�d�}|durd}||jkr|�|jd|�t�|�dS)NrrarbrT)r�r�r��deleterZadd_windows_to_menu)r�r>rar!r!r"r��s


zEditorWindow.postwindowsmenucC�|j|}|j||d�dS)z$Update label for menu item at index.)rN�r��entryconfig)r�r>r�r�menuitemr!r!r"�update_menu_label��
zEditorWindow.update_menu_labelcCr)z$Update state for menu item at index.�r�Nr)r�r>r�r�rr!r!r"r��rzEditorWindow.update_menu_statecGsT|dkrt|d�}t|�d�|�|�d�}d}|df}|jj|g|�R�dS)zHandle scrollbar.Zmovetorra�@0,0ZscrollZunitsrN)�float�round�	getlinenorF�yview)r�rP�argsZfraction�linesr!r!r"r��s�zEditorWindow.handle_yviewc	Cs*|j}|�d|j�d|j���}z|�dd|�o|�|dd�}Wnty+d}Ynw|s;|�ddd	�|�d
|�|jsB|�	�|j}||_
tjdd�dk}|rY|j
d
d�|jD]%}z|\}}	}
Wn	tynYq\w|
durtq\t||
��}|j||d�q\|�|j|j�|r�|jj
dd�dS)N�@�,r�r�r�Fr�r�rar�r:r;Zarrow)Zcursorr ZibeamrN)rFr��x�yr��TclErrorr�r��rmenu�
make_rmenurPrrkZconfig�rmenu_specs�
ValueErrorrZentryconfigureZtk_popupZx_rootZy_root)r�rPrFZnewdexZin_selectionr-Ziswin�itemr�	eventnameZverify_stater�r!r!r"r�sB��
�zEditorWindow.right_menu_event)�CloserKNcCsft|jdd�}|jD]#}|d|d}}|dur)|j|fdd�}|j||d�q
|��q
||_dS)NrrrTcS�|�|�dSr���event_generate�rFr2r!r!r"rX/�z(EditorWindow.make_rmenu.<locals>.command�rrX)rxrFr/�add_commandr�r-)r�r-r1rr2rXr!r!r"r.*s


zEditorWindow.make_rmenucCs|��Sr�)�rmenu_check_copy�r�r!r!r"�rmenu_check_cut6szEditorWindow.rmenu_check_cutcCs2z|j�d�}Wn
tyYdSw|rdSdS)Nr�rd�normal�rFr�r,)r�Zindxr!r!r"r;9s�zEditorWindow.rmenu_check_copycCs0z
|jj�d|jd�WdStyYdSw)Nztk::GetSelectionZ	CLIPBOARDrdr>)rFr��callr,r<r!r!r"�rmenu_check_pasteAs��zEditorWindow.rmenu_check_pastecC�t�|j�dS)zHandle Help 'About IDLE' event.rN)rZAboutDialogrzr�r!r!r"r�IszEditorWindow.about_dialogcCst�|jd�dS)z&Handle Options 'Configure IDLE' event.ZSettingsrN)rZConfigDialogrzr�r!r!r"r�OszEditorWindow.config_dialogcCs"|jr|j}n|j}t�|�dS)zHandle Help 'IDLE Help' event.rN)rwrzr
Z
show_idlehelp)r�rP�parentr!r!r"r�Us

zEditorWindow.help_dialogc
Csrtjdd�dkr1z	t�|j�WdSty0}ztjdt|�|j	d�WYd}~dSd}~wwt
�|j�dS)Nr:r;�Document Start Failure��title�messagerCrN)rrkrg�	startfilerf�OSErrorrr�r�rF�
webbrowser�open)r�rP�whyr!r!r"r�_s�
���zEditorWindow.python_docscC�|j�d�dS)Nz<<Cut>>rN�rFr6r�r!r!r"r�j�zEditorWindow.cutcCs |j�d�sdS|j�d�dS)Nr�z<<Copy>>rN)rFZ
tag_rangesr6r�r!r!r"r�nszEditorWindow.copycCs|j�d�|j�d�dS)Nz	<<Paste>>r�rN)rFr6r�r�r!r!r"r�u�zEditorWindow.pastecCs.|j�ddd�|j�dd�|j�d�dS)Nr�r�zend-1cr�rN)rFr�r�r�r�r!r!r"r�zszEditorWindow.select_allcCs |j�ddd�|j�d�dS)Nr�r�rar�rN)rFr�r�r�r!r!r"r��szEditorWindow.remove_selectioncs*|jj�|jj�d�����fdd�}|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-1ccsD|jd@dkr z�d��d���WdStyYdSwdS)NrGrr�r�)r�r,rO��
edge_indexZedges_tableZself_text_indexZself_text_mark_setr!r"�move_at_edge�s��z<EditorWindow.move_at_edge_if_selection.<locals>.move_at_edge)rFr�r�)r�rRrSr!rQr"r��s
z&EditorWindow.move_at_edge_if_selectioncCrM)Nz
<Meta-Delete>rNrNr�r!r!r"r��rOzEditorWindow.del_word_leftcCrM)Nz<Meta-d>rNrNr�r!r!r"r��rOzEditorWindow.del_word_rightcCrBrM)r�findrFr�r!r!r"r��rOzEditorWindow.find_eventcCrBrM)rZ
find_againrFr�r!r!r"r��rOzEditorWindow.find_again_eventcCrBrM)rZfind_selectionrFr�r!r!r"r��rOz!EditorWindow.find_selection_eventcCst�|j|j|j�dSrM)r	rFr�rvr�r!r!r"r��sz EditorWindow.find_in_files_eventcCst�|j�dSrM)rrFr�r!r!r"r��rOzEditorWindow.replace_eventcCsT|j}t�|dd�j}|dur(|�ddd�|�d|�d��|�d�|��dS)	Nz
Go To Linez/Enter a positive integer
('big' = end of file):r�r�rar��.0rN)rFrZGoto�resultr�r�r�r)r�rPrF�linenor!r!r"r��s��
zEditorWindow.goto_line_eventcCspz|j�dd���}Wntyd}Ynwt�|jdd|�j}|dur6|jr0|j�|�|S|j	�
|�|S)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.
        r�r�r<zOpen ModulezAEnter the name of a Python module
to search on sys.path and open:N)rFr��stripr,rZ
ModuleNamerVrvrKr�r�)r�r@�	file_pathr!r!r"�open_module�s$����zEditorWindow.open_modulecC�|��dSrM)rZr�r!r!r"r���zEditorWindow.open_module_eventcCsJ|jj}|jjdkr|s|��}|durdSddlm}|�|j|�dS)NZPyShellEditorWindowrNr)�browser)	r�r��	__class__�__name__rZ�idlelibr]Z
ModuleBrowserrw)r�rPr�r]r!r!r"r��s�z EditorWindow.open_module_browsercCsddlm}|�|j�dS)Nr)�pathbrowserrN)r`raZPathBrowserrw)r�rPrar!r!r"r��rPzEditorWindow.open_path_browsercCs&ddl}tjddg}|j|dd�dS)Nrz-cz,from turtledemo.__main__ import main; main()F)�shellrN)�
subprocessr�
executable�Popen)r�rPrc�cmdr!r!r"r��s�zEditorWindow.open_turtle_democCsV|dur'|dkr)|j�dd|�|j�ddd�|j�ddd�|��dSdSdS)Nrr�z%d.0r�r�raz
insert +1l)rFr�r�r��center)r�rWr!r!r"�gotoline�s�zEditorWindow.gotolinecCs`|rtj�|�r
dStj�tj�|��\}}tj�|�tvr dS|j�dd�}|�	d�o/d|vS)NTr�z1.0 lineendz#!Zpython)
rgrhrm�splitextr��normcaserrFr��
startswith)r�r��base�extr�r!r!r"r��szEditorWindow.ispythonsourcecCs |jr|j�|�d|_dSdSr�)rvZunregister_maybe_terminater<r!r!r"�
close_hooks
�zEditorWindow.close_hookcCs
||_dSr�)rn)r�rnr!r!r"�set_close_hook
�
zEditorWindow.set_close_hookcCs2|jr	|j�|�|��|j�|�|��dSr�)rvZfilename_changed_editr�rzZupdate_windowlist_registryr�r<r!r!r"r�s
z!EditorWindow.filename_change_hookcCsD|jrdS|�|jj�r|��|_|jr |jj|j|jd�dSdS)N)�filterZafter)r�r�r�r�r&r�Zinsertfilterafterr�r<r!r!r"�
_addcolorizers
�zEditorWindow._addcolorizercCs,|jsdS|j��|j�|j�d|_dSr�)r�Zremovecolorsr�Zremovefilterr<r!r!r"�_rmcolorizer s


zEditorWindow._rmcolorizercCsL|��|��t�|j�|jdur|j��|jdur$|j��dSdS)zUpdate the color themeN)	rsrrr$r'rFr�Zupdate_highlight_colorsr�Z
update_colorsr<r!r!r"r�'s


�zEditorWindow.ResetColorizer�_cCsp|�d|�|�|�}|r||jvr|�d|d|�d|�|�kr)|�d|�n|�d|d�|�|�dS)N�ERRORz
 wordstart�
r�z+1c)r�r��
IDENTCHARSr�r�)r�rF�pos�charr!r!r"�colorize_syntax_error6s
z"EditorWindow.colorize_syntax_errorcCs4tjddddd�}|sd|jd<dStj|jd<dS)	z&Update the cursor blink configuration.rAr$zcursor-blinkr]rDrr_N)rr�rFr^)r�Zcursorblinkr!r!r"r�As�z EditorWindow.update_cursor_blinkcCsN|jdur
|j��|jdur|j��t�|jdd�}||jd<|��dS)z.Update the text widgets' font if it is changedNrAr$r[)r�Zupdate_fontr�rr�rwrFr�)r�Znew_fontr!r!r"�	ResetFontKs




zEditorWindow.ResetFontcCs|t��|j_}|��D]\}}|jj|g|�R�q|��D]}t�|�}|r;|��D]\}}|jj|g|�R�q,qdS)z/Remove the keybindings before they are changed.N)	r�GetCurrentKeySetr+�default_keydefs�itemsrFZevent_delete�get_standard_extension_names�GetExtensionBindings)r��keydefsrP�keylist�
extensionName�xkeydefsr!r!r"�RemoveKeybindings\s
��zEditorWindow.RemoveKeybindingsc
Cs>t��|j_}|��|��D]}t�|�}|r|�|�qi}|jjD]!}i||d<|dD]}|rE|d||dt|d�d<q1q%|j	D]R}|j	|}|�
t�}|dur[qJ|d7}td|�D]7}	|�
|	�dkr�|�|	d�}
|
r�|�|	d�}d}||vr�|||vr�|||}|r�t||�}
|j|	|
d�qdqJdS)	z-Update the keybindings after they are changedrrTNrX�acceleratorrr<)r�)rr|r+r}r�rr��menudefsrr�r�rr�rEZ	entrycget�get_acceleratorr)
r�r�r�r�Z
menuEventDictr>r1ZmenubarItemrar�ZaccelZitemNamerPr!r!r"�ApplyKeybindingshsH

� ��



���zEditorWindow.ApplyKeybindingscCs"|jstjddddd�|_dSdS)zCUpdate the indentwidth if changed and not using tabs in this windowrAr\z
num-spacesrCrDN)r�rr�r�r<r!r!r"r��s

��z#EditorWindow.set_notabs_indentwidthcCs|t��}|jd}|�t�}||jkr|�|jd|�|r7|��|D]}|�|d�}|j	|d|d�q$||jd<dS)z3Update the additional help entries on the Help menur
rTrr9N)
rZGetAllExtraHelpSourcesListr�r�rrrr��"_EditorWindow__extra_help_callbackr:)r�Z	help_listZhelpmenuZhelpmenu_length�entryrfr!r!r"r�s


z$EditorWindow.reset_help_menu_entriesc�|f�fdd�	}|S)zCCreate a callback with the helpfile value frozen at definition timec
s�|�d�stj�|�}tjdd�dkr;zt�|�WdSty:}ztj	dt
|��jd�WYd}~dSd}~wwt�
|�dS)N)Zwww�httpr:r;rDrE)rkrgrhrurrkrHrIrr�r�rFrJrK)�helpfilerLr<r!r"�display_extra_help�s

���z>EditorWindow.__extra_help_callback.<locals>.display_extra_helpr!)r�r�r�r!r<r"Z__extra_help_callback�sz"EditorWindow.__extra_help_callbackc
s�g}|j}|r)tj�|�r)t|dddd��}|��}Wd�n1s$wY|rBtj�|�d}||vr<|�|�|�d|�g�|D]}d|vsVtj�|dd	��s[��	|�qF�fd
d�|D�}d}|dt
|��}|r�zt|d
ddd��
}|�|�Wd�n1s�wYWn*ty�}zt
|jdd�s�d|j_tjdd|�d�|jd�WYd}~nd}~ww|jjD]+}	|	j}
|
�dt�t|�D]\}}|��}|	�|�}
|
j||d||
dd�q�q�dS)z/Load and update the recent files list and menus�r�utf_8r)r*�errorsNrvr�rbcsg|]}|�vr|�qSr!r!)�.0rh�Z	bad_pathsr!r"�
<listcomp>�sz9EditorWindow.update_recent_files_list.<locals>.<listcomp>Z1234567890ABCDEFGHIJK�w�recentfiles_messageFTzIDLE Warningz)Cannot save Recent Files list to disk.
  z
Select OK to continue.rEr�)rrXr)r~rgrhr�rK�	readlines�abspath�remover��appendr��
writelinesrIrrwr�r�showwarningrFrzr}rrr�	enumerate�rstrip�#_EditorWindow__recent_file_callbackr:)r��new_fileZrf_listrYZrf_list_filerhZulcharsZrf_file�err�instancer>�i�	file_name�callbackr!r�r"r��sl�
�

��������	
���z%EditorWindow.update_recent_files_listcr�)Ncs�jj|d�dS)N)ZeditFile)r�rK)Z
fn_closurer<r!r"�open_recent_file�sz=EditorWindow.__recent_file_callback.<locals>.open_recent_filer!)r�r�r�r!r<r"Z__recent_file_callback�sz#EditorWindow.__recent_file_callbackcCs�|��}|��}|r|r|d|t}n|r|}n|r|}nd}|p&|p&|}|��s3d|}d|}|j�|�|j�|�dS)Nz - �untitledz*%s*z*%s)�short_title�
long_title�_py_version�	get_savedrzZwm_titleZwm_iconname)r�Zshort�longrFZiconr!r!r"r��szEditorWindow.saved_change_hookcCs
|j��Sr�)r�r�r<r!r!r"r��rpzEditorWindow.get_savedcCs|j�|�dSr�)r��	set_saved)r��flagr!r!r"r��szEditorWindow.set_savedcCs|j��dSr�)r��
reset_undor<r!r!r"r��r8zEditorWindow.reset_undocCs|jj}|rtj�|�SdS)Nr�)r�r�rgrhr�)r�r�r!r!r"r�szEditorWindow.short_titlecCs|jjpdS)Nr<)r�r�r<r!r!r"r�r�zEditorWindow.long_titlecCr[rM)rgr�r!r!r"r�r\z EditorWindow.center_insert_eventr�cCsH|j}|��\}}|�|�}||}td||d�}|�t|��dS)NrTr=)rF�getwindowlinesr$�maxr%r")r��markrFrz�botrWrHZnewtopr!r!r"rgs
zEditorWindow.centercCsN|j}|�d�}|�d�}||kr#|��dkr#t|d�}||d}||fS)Nr!z@0,65535rTrH)rFr$Zwinfo_heightrC)r�rFrzr�rHr!r!r"r�s

zEditorWindow.getwindowlinescCs|j}tt|�|���Sr�)rFrCr"r�)r�r�rFr!r!r"r$szEditorWindow.getlinenocCs(|j��}t�d|�}ttt|����S)zReturn (width, height, x, y)z(\d+)x(\d+)\+(-?\d+)\+(-?\d+))rzZwm_geometry�re�match�listr�rC�groups)r�Zgeom�mr!r!r"�get_geometry"s
zEditorWindow.get_geometrycCr[rM)r�r�r!r!r"r�(r\zEditorWindow.close_eventcCsH|jr"|��s|j��dkr|j��|j��|j��|j��SdS)Nr>)r�r�rzr�Z	deiconify�lowerZlift�	maybesaver<r!r!r"r�,s



�zEditorWindow.maybesavecCs8z|��}t|�dkr|��|WStyYdSw)N�cancel)r�r��_close�AttributeError)r�Zreplyr!r!r"r�5s�zEditorWindow.closecCs�|jjr|j|jjd�t�|j�|��|j��d|_d|_|j	r,|j	��d|_	d|_
d|_|j��d|_|j
��|jrH|��dSdS)N)r�)r�r�r�rZunregister_callbackr��unload_extensionsr�r�r�rFr|r�rzZdestroyrnr<r!r!r"r�>s$



�zEditorWindow._closecCsi|_|��dSr�)�
extensions�load_standard_extensionsr<r!r!r"r�RszEditorWindow.load_extensionscCs0t|j���D]}t|d�r|��qi|_dS)Nr�)r�r��valuesr�r�)r��insr!r!r"r�Vs

�
zEditorWindow.unload_extensionscCs@|��D]}z|�|�Wqtdt|��t��YqdS)NzFailed to load extension)r�load_extension�print�repr�	traceback�	print_exc)r�r@r!r!r"r�\s�z%EditorWindow.load_standard_extensionscCstjdd�S)NT)Zeditor_only)rZ
GetExtensionsr<r!r!r"rdr�z)EditorWindow.get_standard_extension_namesZZzDummyZzzdummyc		CsN|j�||�}zztjd|td�}Wnttfy#t�|�}YnwWn
ty2td|��wt||�}t	�
|�}t|d�rI|�|j
|�||�}||j|<|r�|�|�|D]I}|�dd�}|dd�dkry|dd�}|dd�dksk|d	d�d
kr�|dd	�}|d	d�d
ks�|d}t||�r�|j�|t||��q[dSdS)Nr�)�packagez
Failed to import extension: r��-rtrTr�rbr�Z_event)�extfilesr��	importlib�
import_module�__package__�ImportError�	TypeErrorr�rrr�r�rr�r�r�rrFr�)	r�r@Zfname�mod�clsr�r�ZveventZ
methodnamer!r!r"r�ksD��
�




��
��zEditorWindow.load_extensioncCsH|dur|jj}|j}||_|��D]\}}|r!|j|g|�R�qdSr�)r+r}rFr�r~r�)r�r�rFrPr�r!r!r"r��s��zEditorWindow.apply_bindingsc	Cs�|dur|jj}|dur|jj}|j}|j}|D]Z\}}|�|�}|s$q|D]K}|s/|��q&|\}	}
|	dd�dk}|rC|	dd�}	t|	�\}}	t||
�}
||
fdd�}|rh|�	|
t
�}|j|	|||
|d�q&|j|	|||
d�q&qdS)zAdd appropriate entries to the menus and submenus

        Menus that are absent or None in self.menudict are ignored.
        NrT�!cSr4r�r5r7r!r!r"rX�r8z(EditorWindow.fill_menus.<locals>.command)rrrXr��variable)rrrXr�)
r+r�r}r�rFr�r�rr��get_var_objZ
BooleanVarZadd_checkbuttonr:)r�r�r�r�rFZmnameZ	entrylistr>r�rr2Zcheckbuttonrr�rX�varr!r!r"r�s@


����zEditorWindow.fill_menuscCs"|�|�}|r
|��}|St|��r�)r�r��	NameError)r�r@r��valuer!r!r"�getvar�s

zEditorWindow.getvarcCs&|�||�}|r|�|�dSt|��r�)r�r�r�)r�r@r��vartyper�r!r!r"�setvar�szEditorWindow.setvarcCs,|j�|�}|s|r||j�|j|<}|Sr�)r|r�rF)r�r@r�r�r!r!r"r��szEditorWindow.get_var_objcCs(|jr|j�d|�pd|j�|�vSdS)NZTODO�STRINGrT)r�rF�
tag_prevrangeZ	tag_names)r�Z
text_indexr!r!r"�is_char_in_string�s
�zEditorWindow.is_char_in_stringcCs8z|j�d�}|j�d�}||fWStyYdSw)Nr�r��NNr?)r�rrr!r!r"�get_selection_indices�s
�z"EditorWindow.get_selection_indicescCs|jdpt}t|�S)N�tabs)rF�TK_TABWIDTH_DEFAULTrC)r��currentr!r!r"�get_tk_tabwidth�szEditorWindow.get_tk_tabwidthc	CsF|j}|��|kr!|j�dd|dd|jd|�}|j|d�dSdS)Nr[r�z
-displayof�n)r�)rFr�r�r@ZmasterZ	configure)r�ZnewtabwidthrFZpixelsr!r!r"�set_tk_tabwidth�s��zEditorWindow.set_tk_tabwidthcCsP|r |r |��}d|krdkrnn||_|j|jkr d|_|�|j�dS)Nr=rF)�guess_indentr�r�r�r�)r�r�Zguessr�r!r!r"r��sz#EditorWindow.set_indentation_paramsc
Cs8|j}|��\}}|r|r|�||�|�d|�dS|�dd�}|dkr9|�ddd�r3|�d�dS|��dS|dd	vrF|�d�dS|j}t|�	|��}|d
|j
|j
}d}		|dd�}|	d
}	t|�	|��}||ksx|dd	vrynq]|��|�d
|	d�||kr�|�dd|||j
�|��dS)Nr�rNr�r<r�r�z	insert-1crb� 	rTrTz
insert-%dcr�)rFr�rr�r�r�Zbellr�r��
expandtabsr�r�r�r�r�)
r�rPrFrr�charsr�ZhaveZwantZ
ncharsdeletedr!r!r"r�sF
�
��z"EditorWindow.smart_backspace_eventc
Cs|j}|��\}}|��zm|r1|r1t|�t|�kr%|j�|�W|��S|�||�|�d|�|�	dd�}t
||j�\}}|t|�krN|�
||j�n!|jrTd}nt|�|j��}|j}	d|	||	}|�d||j�|�d�W|��dS|��w)Nr�r�r�r�rN)rFr�r��
index2liner�r�r�rr�r��get_line_indentr�r��reindent_tor�r�r�r�r�r�)
r�rPrFrr�prefix�rawZ	effectiveZpadr�r!r!r"r�0s.
�
zEditorWindow.smart_indent_eventc	Cs:|j}|��\}}|���z�|r|r|�||�|�d|�|�dd�}dt|�}}||krD||dvrD|d7}||krD||dvs6||kr\|�dd|j�W|�	d�|�
�dS|d|�}d}|r~|d	dvr~|dd	�}|d7}|r~|d	dvsl|r�|�d
|d�|�d�dvr�|�d�|�d�dvs�|�dd|j�t|�d��}	t
�|j|j�}
|js�|jD],}t|	|d�}t|�d}
|�|
d�}|
�|�|
�|�|
��}|dus�|dkr�nq�|
�|p�d�n|�dd�}|r�|d}
nd
}
|�|
d�}|
�|�|
�d�|
��}|t
jk�rc|t
jk�rn:|t
jk�r,|�d||j�n+|t
jk�r:|�|
� ��n|t
j!k�rW|
�"�dk�rP|�d||j�n|�|
�#��W|�	d�|�
�dS|
�$�}|�d||j�|
�%��rz|�&|�n
|�r�|
�'��r�|�(|�W|�	d�|�
�dS|�	d�|�
�w)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.
        r�r�rr�rTrvrNNrbzinsert - %d charsrUZconsoler�))rFr�r�rr�r�r�r�r�r�r�r�r�rZParserr�r�rr�r�r�Zset_codeZfind_good_parse_start�_build_char_in_string_funcZset_lor�Zget_continuation_typeZC_NONEZC_STRING_FIRST_LINEZC_STRING_NEXT_LINESZ	C_BRACKETr�Zcompute_bracket_indentZC_BACKSLASHZget_num_lines_in_stmtZcompute_backslash_indentZget_base_indent_stringZis_block_openerr�Zis_block_closerr�)r�rPrFrrr�r�r��indent�lnor+�contextZstartatZstartatindexZrawtextZbodr�r�r!r!r"r�Ss�	��
U��
�

��


�

�



�
z%EditorWindow.newline_and_indent_eventcCs||jfdd�}|S)NcSs||d|�S)Nz+%dcr!)�offsetZ_startindexZ_icisr!r!r"�inner�sz6EditorWindow._build_char_in_string_func.<locals>.inner)r�)r�Z
startindexr�r!r!r"r��s
�z'EditorWindow._build_char_in_string_funccCs.|jrt||j�\}}d|d|Sd|S)Nr�r�)r��divmodr�)r�r�ZntabsZnspacesr!r!r"�_make_blanks�szEditorWindow._make_blankscCsN|j}|��|�ddd�r|�dd�|r!|�d|�|�|j�|��dS)Nr�z!=r�)rFr�r�rr�r�r�r�)r�rZrFr!r!r"r��s�zEditorWindow.reindent_tocCsVt|j|j���\}}|r#|r#t||j�\}}t||j�\}}||Sd}}||S�Nr)�IndentSearcherrFr�rr�)r��openerZindentedr�ZindentsmallZindentlarger!r!r"r��s�zEditorWindow.guess_indentcCsN|jdurdS|jjr|j��d}n|j��d}|jdd|�d�d�dS)NZShowZHidercrez
 Line Numbers)r>r�r)r�Zis_shownZhide_sidebarZshow_sidebarr)r�rPZ
menu_labelr!r!r"r��s



�z&EditorWindow.toggle_line_numbers_event)NNNNr�)r�r�)T)�r_�
__module__�__qualname__Zidlelib.percolatorr%Zidlelib.colorizerr&r'Zidlelib.undor(Zidlelib.iomenur)r*r`r+Zidlelib.statusbarr,Zidlelib.autocompleter-Zidlelib.autoexpandr.Zidlelib.calltipr/Zidlelib.codecontextr0Zidlelib.sidebarr1Zidlelib.formatr2r3r4r5Zidlelib.parenmatchr6Zidlelib.zoomheightr7r�getfilesystemencodingZfilesystemencodingrfr�r�r�r�r�r�r�r�r�rrr�r�rr�r�r-r�r/r.r=r;rAr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZr�r�r�r�rhr�rnror�rrrsr��string�
ascii_letters�digitsrwrzr�r{r�r�r�rr�r�r�r�r�r�r�r�r�r�rgr�r$r�r�r�r�r�r�r�r�rr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r!r!r!r"r$2s�

$
+

%�









			

$
.


		�

	%


	+#x
	r$cCstt|��Sr�)rCr")r�r!r!r"r�r�r�z[ \t]*cCs$t�|�}|��t|���|��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�rar��groupr�)r�r�r�r!r!r"r�s
r�c@s8eZdZdd�Zdd�Zejejdfdd�Zdd	�Z	d
S)r�cCs(||_||_d|_|_d|_|_dSr�)rFr�r��finished�blkopenline�indentedline)r�rFr�r!r!r"r�!szIndentSearcher.__init__cCsL|jrdS|jd}|_t|�d}|j�|dd�rdS|j�||d�S)Nr<rTrUz>=raz lineend+1c)rr�r�rFr�r�)r�r�r�r!r!r"�readline'szIndentSearcher.readline)�class�def�for�if�try�whilec		CsJ|jrdS||kr||vr||_dS||kr!|jr#||_d|_dSdSdS)NrT)rrr)	r�rE�token�startrar��INDENT�NAMEZOPENERSr!r!r"�
tokeneater0s

�zIndentSearcher.tokeneaterc	Csltj}|jt_z$zt�|j�}|D]}|j|�qWntjtfy&YnwW|t_n|t_w|j|j	fSr�)
�tokenize�tabsizer��generate_tokensrr�
TokenError�SyntaxErrorrr)r�Zsave_tabsize�tokensrr!r!r"r<s���zIndentSearcher.runN)
r_r�r�r�rrrrrrr!r!r!r"r�s

�r�cCs6|�d�}|dkr|d|�||dd�}||fS)NrtrrT)rT)�sr�r!r!r"rNs
r�[�]�/)ZbracketleftZbracketrightZslashcCs�|�|�}|rt��r|dvrdS|d}t�ddd�|�}t�ddd�|�}t�d	d|�}t�d
d|�}t�dd
|�}t�dd|�}t�dd|�}t�dd|�}t�dd|�}|S)N>rSrRrLr<rz-[a-z]\bcSs|����Sr�)r�upper�r�r!r!r"rQgsz!get_accelerator.<locals>.<lambda>z\b\w+\bcSst�|��|���Sr�)�keynamesr�rrr!r!r"rQhszKey-ZCancelz
Ctrl-BreakzControl-zCtrl-r��+z><r�r�r�)r�rZ	isCocoaTkr��sub)r�r2r�rr!r!r"r�]s
r�cCs4|j}|�ddd�|�ddd�|�ddd�dS)	NZtcl_wordBreakAfterza brr�Z
tcl_wordcharsz\wZtcl_nonwordcharsz\W)r�r@)rwr�r!r!r"�
fixwordbreaksssr#cCs~|}t|�tjdd�rtjd}nd}t�|d�t||d�}|j}d|d<td�D]}|�dd|t	|�d�q,dS)	NrT)rwr��
rH�r�z  rv)
r#r�argvrZsetupAppr$rFr�r�r�)rCrwr�r	rFr�r!r!r"�_editor_window|s�r'�__main__)rAzidlelib.idle_test.test_editorr=F)�	verbosity�exit)r):Z
importlib.abcr��importlib.utilrgrkr�rrrr�rJ�tkinterZtkinter.fontrZtkinter.ttkrrrZidlelib.configrr`rr	r
rrZidlelib.multicallr
rrrrZidlelib.treerZidlelib.utilrrr�Zpython_versionr�rr#r$r��compilerr�r�rr r�r#r'r_ZunittestrAZidlelib.idle_test.htestrr!r!r!r"�<module>s~
d

4
�	�