Your IP : 52.15.190.187


Current Path : /opt/alt/python34/lib64/python3.4/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/idlelib/__pycache__/EditorWindow.cpython-34.pyc

�
e f�@s^ddlZddlZddlZddlZddlZddlZddlZddlZddlTddl	j
Zddlj
ZddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZmZmZddlmZddlmZd
Z dej!�Z"dd�Z#Gdd�de$�Z%e%�Z&Gdd�de$�Z'dd�Z(dd�Z)ddl*Z*e*Z+[*Gdd�de$�Z,dd�Z-idd6dd 6d!d"6Z.d#d$�Z/d%d&�Z0d'd(�Z1e2d)krZdd*l3m4Z4e4e1�ndS)+�N)�*)�MultiCallCreator)�
WindowList)�SearchDialog)�
GrepDialog)�
ReplaceDialog)�PyParse)�idleConf)�aboutDialog�textView�configDialog)�
macosxSupport)�help�z (%s)cCs�tj\}}}}}d||f}|d|f7}|dkrY|d|f7}n'|dkr�|d|d|f7}n|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�9/opt/alt/python34/lib64/python3.4/idlelib/EditorWindow.py�_sphinx_versionsrc@sReZdZdd�Zddd�Zdd�Zdd	�Zdd
d�ZdS)�
HelpDialogcCsd|_d|_dS)N)�parent�dlg)�selfrrr�__init__-s	zHelpDialog.__init__NcCs[ddl}|jdtdd�|jdkrA|j|�n|rW|j|�ndS)z� Display the help dialog.

            parent - parent widget for the help window

            near - a Toplevel widget (e.g. EditorWindow or PyShell)
                   to use as a reference for placing the help window
        rNz�EditorWindow.HelpDialog is no longer used by Idle.
It will be removed in 3.6 or later.
It has been replaced by private help.HelpWindow
�
stacklevel�)�warnings�warn�DeprecationWarningr�show_dialog�
nearwindow)r r�near�wrrr�display1s	
zHelpDialog.displaycCsr||_tjjtjjtjjt��d�}tj|d|dd�|_	}|j
d|jd�dS)Nzhelp.txtZHelpZmodalFz	<Destroy>�+)r�os�path�join�abspath�dirname�__file__rZ	view_filer�bind�destroy)r r�fnrrrrr'Cs	-"zHelpDialog.show_dialogcCs\|j}|j�d|j�df}|j�|jd|�|j�|j�dS)N�
z=+%d+%d)rZwinfo_rootxZwinfo_rootyZwithdrawZgeometry�	deiconify�lift)r r)r�geomrrrr(Is	 

zHelpDialog.nearwindowcCsd|_d|_dS)N)rr)r Zevrrrr4Ts	zHelpDialog.destroy)�__name__�
__module__�__qualname__r!r+r'r(r4rrrrr+s
rc@s�eZdZddlmZddlmZddlmZddl	m
Z
mZmZddl
mZddlmZddlmZd	Zd	d	d	d	d
d�Zdd
�Zdd�Zdd�Zdd�Zd	dd�Zd�d�d�d�d�d�d�gZd$d%�Zd&d'�Zd	Zd(d)�Zd�gZd,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#d	d4d5�Z$d	d6d7�Z%d	d8d9�Z&d	d:d;�Z'd<d=�Z(d>d?�Z)d@dA�Z*d	dBdC�Z+d	dDdE�Z,dFdG�Z-dHdI�Z.dJdK�Z/dLdM�Z0dNdO�Z1dPdQ�Z2dRdS�Z3dTdU�Z4dVdW�Z5d	dXdY�Z6d	dZd[�Z7d	d\d]�Z8d	d^d_�Z9d`da�Z:dbdc�Z;ddde�Z<dfdg�Z=dhdi�Z>djdk�Z?dldm�Z@dndo�ZAeBjCeBjDdpZEdqdr�ZFdsdt�ZGdudv�ZHdwdx�ZIdydz�ZJd{d|�ZKd}d~�ZLd	dd��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d�d��ZVd�d��ZWd�d�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd	d�d��Zcd	d	d�d��Zdd�d��Zed	d�d��Zfd	d�d��Zgd�d��Zhd�d��Zid�d��Zjd�d��Zkd�d�d��Zld�d��Zmd�d��Znd�d��Zod�d��Zpd�d��Zqd�d��Zrd�d��Zsd�d��Ztd�d��Zud�d��Zvd�d��Zwd�d��Zxd�d��Zyd�d��Zzd�d��Z{d�d��Z|d�d��Z}d�d��Z~d	S)��EditorWindowr)�
Percolator)�ColorDelegator)�
UndoDelegator)�	IOBinding�filesystemencoding�encoding)�Bindings)�Toplevel)�MultiStatusBarNcCs�	tjdkr�tjjtjdd�}tjjd�r�ddtj	dd�}tjj
d�rrd}qd	}tjj||dd�}n�tjdd�d
kr�tjjtjddt��}tjj|�r|}qn*tjdkrtjjtjd
�}ntjj
|�}tjj|�rk|t_tjdkr�dtjt_q�q�dtj	dd�t_n||_|p�|j}||_ytjWntk
r�dt_YnXt|�|_tj|d|j�|_}	|r$|j|_|j|j_ni|_i|j_tjjtj�d�|_t|	�|_}
t |
dd�|_!}tj"ddddd�|_#idd6dd6dd6d d!6|j#d6tj"ddd"dd�d"6}t$d#krd$|d%<nt%t&�|
|�|_'}
|j'|j_(|j)�|j*�|jj+d&|j,�|jj-d'|j.�t/j0�r�|
j-d'|j.�|
j-d(|j1�|
j-d)|j1�n|
j-d*|j1�|
j-d+|j2�|
j-d,|j3�|
j-d-|j4�|
j-d.|j5�|
j-d/|j6�|
j-d0|j7�|
j-d1|j8�|
j-d2|j9�|
j-d3|j:�|
j-d4d5d6��|
j-d7|j;�|
j-d8|j<�|
j-d9|j=�|
j-d:|j>�|
j-d;|j?�|
j-d<|j@�|
j-d=|jA�|
j-d>|jB�|
j-d?|jC�|
j-d@|jD�|
j-dA|jE�|
j-dB|jF�|
j-dC|jG�|
j-dD|jH�|
j-dE|jI�|
j-dF|jJ�|
j-dG|jK�|
j-dH|jL�|
j-dI|jM�|
j-dJ|jNd ��|
j-dK|jNdL��|
j-dM|jO�|
j-dN|jP�|
j-dO|jQ�|r�||j|<|r�||jR|<n|
j-dP|jS�|
j-dQ|jjT�|
j-dR|jU�|
j-dS|jV�|
j-dT|jW�n|jX�|
jY|dU<|jZdVt[dWt\�|j]|
dX<tj^|jdd�|
dY<|
jZdVt_dWt`dZdL�|
jZdVtadWt`dZdL�|
jb�tj"dd[d\dd]�}||_cd^|_d|jd|_e|jf�d_|_gdf|_h|ji|
�|_j}|jk�|_l}|jm|�|jn|
_n|jo|
_o|jp|jq�|jr|�|_s}|jt|ju�d_|_v|jwd_�d|_x|r�tjjy|�r�tjj
|�r�|jz|�r�dc|_v|j{|�}|jw|�q�q�|j||�dc|_vn|j}�|jq�|j~�|j�|j�j�dd�}|r�	|j�de�}|dkr^	dg}n|d kr�	|j��|dL}n||_�tj�|j��nt�j�|_�t�j�|_�t�j�|_�dS)hNZDocz
index.html�linuxzpython-docs-z%s.%s.%s�z/var/www/html/python/z/var/www/html/python/index.htmlz/usr/share/doc/�winzPython%s.chm�darwinz0Resources/English.lproj/Documentation/index.htmlzfile://zhttps://docs.python.org/%d.%d/r#z>>> �menuzrecent-files.lst�name�vbar�mainr=�width�type�int�text�ZpadxZnoneZwraprZhighlightthickness�heightg!@Z
wordprocessorZtabstyleZWM_DELETE_WINDOWz<<close-window>>z<Control-Button-1>z<2>z<3>z<<cut>>z<<copy>>z	<<paste>>z<<center-insert>>z<<help>>z<<python-docs>>z<<about-idle>>z<<open-config-dialog>>z<<open-module>>z<<do-nothing>>cSsdS)N�breakr)�eventrrr�<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>>z
<<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>>z<<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>>�command�side�fillZyscrollcommand�font�expand�Indentz
use-spaces�boolrF�2���@KLT�windows�end)r`rarb���)�r=�help_urlr-r.r/r�base_prefix�platform�countr�isdirr�isfile�normpath�flist�root�ps1�AttributeError�Menu�menubarrZListedToplevel�top�vars�tkinter_varsZinversedict�
instance_dictr	Z
GetUserCfgDir�recent_files_path�Frame�
text_frameZ	ScrollbarrM�	GetOptionrO�	TkVersionrZTextrRZfocused_widget�
createmenubar�apply_bindingsZprotocol�closer3�close_eventr
ZisAquaTk�right_menu_event�cut�copy�paste�center_insert_event�help_dialog�python_docs�about_dialog�
config_dialog�open_module�
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_event�indent_region_event�dedent_region_event�comment_region_event�uncomment_region_event�tabify_region_event�untabify_region_event�toggle_tabs_event�change_indentwidth_event�move_at_edge_if_selection�
del_word_left�del_word_right�
home_callback�dict�new_callbackZclose_all_callback�open_class_browser�open_path_browser�open_turtle_demo�set_status_bar�yview�pack�RIGHT�Y�set�GetFontZLEFTZBOTHZTOPZ	focus_set�usetabs�tabwidth�indentwidth�set_notabs_indentwidth�context_use_ps1�num_context_linesr>�perr@�undo�insertfilter�undo_block_start�undo_block_stopZset_saved_change_hook�saved_change_hookrA�ioZset_filename_change_hook�filename_change_hookZ	good_load�set_indentation_params�color�exists�loadfile�ispythonsourceZset_filename�ResetColorizer�update_recent_files_list�load_extensions�menudict�get�index�
add_separator�	wmenu_endZregister_callback�postwindowsmenu�tkMessageBox�askyesno�tkSimpleDialog�
askinteger�	showerror)r rm�filename�keyrnZdochomeZpyverZbasepathZchmfilersryrMZtext_optionsrRZ	usespacesr�r�r��	is_py_srcrKrdrrrr!fs>				
	









	
		
	
	%	




	

	zEditorWindow.__init__cCs�t|t�rwy|j|j�}Wqwtk
rsy|j|j�}Wn!tk
rn|jd�}YnXYqwXntjdd|�S)z3Return filename as BMP unicode so diplayable in Tk.z	iso8859-1u[𐀀-􏿿]u�)�
isinstance�bytes�decoderB�UnicodeDecodeErrorrC�re�sub)r r�rrr�_filename_to_unicode?s

z!EditorWindow._filename_to_unicodecCs)|jj�\}}|jj|�dS)NrU)r�Zdefaultfilenamerm�new)r rVr1�basenamerrrr�NszEditorWindow.new_callbackcCs||jd@dkr&|jdkr&dS|jjd�r�|jjddd�r�|jjddd�r�t|jjd�jd�d	�}nR|jjdd�}x:tt	|��D]}||dkr�Pq�q�Wt	|�}t|jjd�jd�d	�}||krd}nd
t
|�d}|jd	@dkr\|jjddd�n�|jjd�s�|jjdd�nY|jj|jjd�d|jjd��r�|jjdd�n|jjdd�|jj|�}|jjd�}|jj|d|�r)||}}n|jjddd�|jj
d||�|jjd|�|jjd�dS)N�rZHomeZiomarkz<=zinsert lineendzinsert linestart�.rX� �	�insertzinsert linestart+�c�selz1.0rdz	sel.firstZ	my_anchor�<zsel.last�>rU)r�r�)�stateZkeysymrRr��comparerQ�splitr��range�len�str�
tag_remove�mark_set�tag_add�see)r rVZinsertpt�lineZlineat�dest�first�lastrrrr�Ss@"(%	zEditorWindow.home_callbackcCs|j|j�|_t|jdddddd�}tjdkra|jjddd	t�n|jjd
dd	t�|jjdd
d	t�|jjd	t	dt
�|jd	t	dt
�|jjd|j
�|jjddd�|jj|j
�dS)NrTrXZborderwidth�
backgroundZgrey75rJZ	_padding1z    rZ�columnzCol: ?r�zLn: ?r[z<<set-line-and-column>>z<KeyRelease>z<ButtonRelease>)rFrs�
status_barrxrrh�	set_labelr�r�ZBOTTOM�XrRr3�set_line_and_column�	event_addZ
after_idle)r �seprrrr�~s!
zEditorWindow.set_status_barcCsS|jjt�jd�\}}|jjdd|�|jjdd|�dS)Nr�r�zCol: %sr�zLn: %s)rRr�ZINSERTr�r�r�)r rVr�r�rrrr��s!z EditorWindow.set_line_and_column�file�_File�edit�_Edit�format�F_ormat�run�_Run�options�_Optionsrc�_Windowr�_HelpcCs5|j}i|_}xe|jD]Z\}}t|�\}}t|d|dd�||<}|jd|d|d|�q Wtj�r�t|dddd�|d<}|jdd	d|�n|j�t|jdd�|_	|jd
j
dddddd|j	�|jd
jt�|_
|j�dS)NrL�tearoffr�labelrK�	underlineZappleZapplicationZIDLEr�rHzRecent Filesr)rrr��
menu_specs�prepstrrqZadd_cascader
Z
isCarbonTk�
fill_menus�recent_files_menuZinsert_cascader��END�base_helpmenu_length�reset_help_menu_entries)r Zmbarr�rLrrrKrrrr|�s"	
  

zEditorWindow.createmenubarcCsk|jd}|jd�}|dkr1d}n||jkrZ|j|jd|�ntj|�dS)NrcrdrXre)r�r�r��deleterZadd_windows_to_menu)r rKrdrrrr��s
	zEditorWindow.postwindowsmenuc	
Cs,|jjdd|j|jf�|js9|j�n|j}||_tjdd�dk}|r�|jj	dd�nxs|j
D]h}y|\}}}Wntk
r�w�YnX|dkr�q�nt||��}|j
|d|�q�W|j|j|j�|r(|jj	dd�ndS)	Nr�z@%d,%drHrI�cursorZarrowr�Zibeam)rRr��x�y�rmenu�
make_rmenurVrrh�config�rmenu_specs�
ValueError�getattrZentryconfigureZtk_popupZx_rootZy_root)	r rVrZiswin�itemr�	eventnameZverify_stater�rrrr��s(#	
		
zEditorWindow.right_menu_event�Close�<<close-window>>cCs�t|jdd�}xj|jD]_}|d|d}}|dk	rt|j|dd�}|jd|d|�q|j�qW||_dS)NrrrXcSs|j|�dS)N)�event_generate)rRrrrrrY�sz(EditorWindow.make_rmenu.<locals>.commandrrY)rqrRr�add_commandr�r)r rrrrrYrrrr�szEditorWindow.make_rmenucCs
|j�S)N)�rmenu_check_copy)r rrr�rmenu_check_cut�szEditorWindow.rmenu_check_cutcCsAy|jjd�}Wntk
r.dSYnX|r9dSdSdS)Nz	sel.first�disabled�normal)rRr��TclError)r Zindxrrrr�s

	zEditorWindow.rmenu_check_copycCsAy |jjjd|jd�Wntk
r8dSYnXdSdS)Nztk::GetSelectionZ	CLIPBOARDr!r")rR�tk�callr#)r rrr�rmenu_check_paste�s
 
	zEditorWindow.rmenu_check_pastecCstj|jd�dS)zHandle Help 'About IDLE' event.z
About IDLEN)r
ZAboutDialogrs)r rVrrrr��szEditorWindow.about_dialogcCstj|jd�dS)z&Handle Options 'Configure IDLE' event.ZSettingsN)rZConfigDialogrs)r rVrrrr�szEditorWindow.config_dialogcCs/|jr|j}n	|j}tj|�dS)zHandle Help 'IDLE Help' event.N)rnrsrZ
show_idlehelp)r rVrrrrr�s		zEditorWindow.help_dialogcCs�tjdd�dkr}ytj|j�Wq�tk
ry}z*tjdddt|�d|j	�WYdd}~Xq�Xnt
j|j�dS)NrHrI�titlezDocument Start Failure�messagerrU)rrhr-�	startfilerf�OSErrorr�r�r�rR�
webbrowser�open)r rV�whyrrrr�s,zEditorWindow.python_docscCs|jjd�dS)Nz<<Cut>>rU)rRr)r rVrrrr�szEditorWindow.cutcCs*|jjd�sdS|jjd�dS)Nr�z<<Copy>>rU)rRZ
tag_rangesr)r rVrrrr�szEditorWindow.copycCs$|jjd�|jjd�dS)Nz	<<Paste>>r�rU)rRrr�)r rVrrrr�%szEditorWindow.pastecCs=|jjddd�|jjdd�|jjd�dS)Nr�z1.0zend-1cr�rU)rRr�r�r�)r rVrrrr�*szEditorWindow.select_allcCs*|jjddd�|jjd�dS)Nr�z1.0rdr�)rRr�r�)r rVrrrr�0szEditorWindow.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.

        �sel.first+1c�sel.last-1ccsN|jd@dkrJy�d��d���WqJtk
rFYqJXndS)NrSrz	sel.firstr�)r�r#)rV)�
edge_index�edges_table�self_text_index�self_text_mark_setrr�move_at_edge?s

z<EditorWindow.move_at_edge_if_selection.<locals>.move_at_edge)r.r/)rRr�r�)r r0r4r)r0r1r2r3rr�4s
z&EditorWindow.move_at_edge_if_selectioncCs|jjd�dS)Nz
<Meta-Delete>rU)rRr)r rVrrrr�HszEditorWindow.del_word_leftcCs|jjd�dS)Nz<Meta-d>rU)rRr)r rVrrrr�LszEditorWindow.del_word_rightcCstj|j�dS)NrU)r�findrR)r rVrrrr�PszEditorWindow.find_eventcCstj|j�dS)NrU)rZ
find_againrR)r rVrrrr�TszEditorWindow.find_again_eventcCstj|j�dS)NrU)rZfind_selectionrR)r rVrrrr�Xsz!EditorWindow.find_selection_eventcCs tj|j|j|j�dS)NrU)rZgreprRr�rm)r rVrrrr�\sz EditorWindow.find_in_files_eventcCstj|j�dS)NrU)r�replacerR)r rVrrrr�`szEditorWindow.replace_eventcCsp|j}tjddd|�}|dkr1dS|dkrK|j�dS|jdd|�|jd�dS)NZGotozGo to line number:rrUrr�z%d.0)rRr�r��bellr�r�)r rVrR�linenorrrr�ds		
zEditorWindow.goto_line_eventc!Cs�y|jjdd�}Wntk
r3d}Yn
X|j�}tjddd|jd|�}|rv|j�}n|s�dSytjj|�}WnNt	t
fk
r�}z(tjdt
|�d|j�dSWYdd}~XnX|dkrtjdd	d|j�dSt|jtjj�sEtjdd
d|j�dSy|jj|�}Wn/tk
r�tjddd|j�dSYnX|jr�|jj|�n|jj|�|S)Nz	sel.firstzsel.last�ZModulezAEnter the name of a Python module
to search on sys.path and open:r�initialvaluezImport errorzmodule not foundznot a source-based modulez$loader does not support get_filename)rRr�r#�stripr�Z	askstring�	importlib�util�	find_specr�ImportErrorr�r�r�r��loader�abc�SourceLoader�get_filenamerprmr,r�r�)r rVrL�spec�msgZ	file_pathrrrr�psH
	


	
		zEditorWindow.open_modulecCs�|jj}|jjdko!|sC|j�}|dkrCdSntjj|�\}}tjj|�\}}ddl	m
}|j
|j||g�dS)NZPyShellEditorWindowr)�ClassBrowser)r�r��	__class__r:r�r-r.r��splitext�idlelibrFrm)r rVr��head�tail�base�extrFrrrr��szEditorWindow.open_class_browsercCs$ddlm}|j|j�dS)Nr)�PathBrowser)rIrNrm)r rVrNrrrr��szEditorWindow.open_path_browsercCs5ddl}tjddg}|j|dd�dS)Nrz-cz,from turtledemo.__main__ import main; main()�shellF)�
subprocessr�
executable�Popen)r rVrP�cmdrrrr��s
	zEditorWindow.open_turtle_democCsl|dk	rh|dkrh|jjdd|�|jjddd�|jjddd�|j�ndS)Nrr�z%d.0r�z1.0rdz
insert +1l)rRr�r�r��center)r r8rrr�gotoline�s
zEditorWindow.gotolinecCs�|stjj|�rdStjjtjj|��\}}tjj|�dkr]dS|jjdd�}|jd�o�d|kS)	NT�.py�.pywz1.0z1.0 lineendz#!�python)rVrW)	r-r.rjrHr��normcaserRr��
startswith)r r�rLrMr�rrrr��s$zEditorWindow.ispythonsourcecCs)|jr%|jj|�d|_ndS)N)rmZunregister_maybe_terminate)r rrr�
close_hook�s	zEditorWindow.close_hookcCs
||_dS)N)r[)r r[rrr�set_close_hook�szEditorWindow.set_close_hookcCsD|jr|jj|�n|j�|jj|�|j�dS)N)rmZfilename_changed_editr�rsZupdate_windowlist_registryr�)r rrrr��s
	
z!EditorWindow.filename_change_hookcCs}|jr
dS|j|jj�r4|j�|_n|jry|jj|j�|jj|j�|jj|j�ndS)N)	r�r�r�r�r?r��removefilterr�r�)r rrr�
_addcolorizer�s		zEditorWindow._addcolorizercCs:|js
dS|jj�|jj|j�d|_dS)N)r�Zremovecolorsr�r])r rrr�_rmcolorizer�s
	
zEditorWindow._rmcolorizercCs�|j�|j�tj�}tj|d�}tj|ddd�}tj|d�}|jjd|dd|dd|d	|dd
|d�tdkr�|jjd|d�nd
S)zUpdate the color themer"rZfgBgZfgZhiliteZ
foregroundr�ZinsertbackgroundZselectforegroundZselectbackgroundg!@ZinactiveselectbackgroundN)r_r^r	ZCurrentThemeZGetHighlightrRrr{)r ZthemeZ
normal_colorsZcursor_colorZ
select_colorsrrrr��s




zEditorWindow.ResetColorizer�_cCs�|jd|�|j|�}|rN||jkrN|jd|d|�nd|j|�krv|jd|�n|jd|d�|j|�dS)NZERRORz
 wordstart�
r�z+1c)r�r��
IDENTCHARSr�r�)r rR�pos�charrrr�colorize_syntax_error�sz"EditorWindow.colorize_syntax_errorcCs#tj|jdd�|jd<dS)z.Update the text widgets' font if it is changedrNr=r\N)r	r�rnrR)r rrr�	ResetFontszEditorWindow.ResetFontcCs�tj�|j_}x-|j�D]\}}|jj||�q#Wx\|j�D]N}tj|�}|rSx0|j�D]\}}|jj||�q{WqSqSWdS)z/Remove the keybindings before they are changed.N)	r	�GetCurrentKeySetrD�default_keydefs�itemsrRZevent_delete�get_standard_extension_names�GetExtensionBindings)r �keydefsrV�keylist�
extensionName�xkeydefsrrr�RemoveKeybindingsszEditorWindow.RemoveKeybindingsc
Cs�tj�|j_}|j�x9|j�D]+}tj|�}|r-|j|�q-q-Wi}xd|jjD]V}i||d<x?|dD]3}|r�|d||dt|d�d<q�q�WqoWx	|j	D]�}|j	|}|j
t�}|dkrq�n|d7}x�td|�D]�}	|j
|	�dkr!|j|	d�}
|
r�|j|	d�}d}||kr�|||kr�|||}q�n|r�t||�}
|j|	d|
�q�q�q!q!Wq�WdS)z-Update the keybindings after they are changedrrXNrY�acceleratorrr9)r	rgrDrhr}rjrk�menudefsr	r�r�rr�rPZ	entrycget�get_acceleratorZentryconfig)
r rlrnroZ
menuEventDictrKrZmenubarItemrdr�ZaccelZitemNamerVrrr�ApplyKeybindingss<
/

zEditorWindow.ApplyKeybindingscCs.|js*tjddddd�|_ndS)zCUpdate the indentwidth if changed and not using tabs in this windowrNr^z
num-spacesrPrQN)r�r	rzr�)r rrrr�;s	z#EditorWindow.set_notabs_indentwidthcCs�tj�}|jd}|jt�}||jkrQ|j|jd|�n|r�|j�x>|D]3}|j|d�}|j	d|dd|�qhWn||jd<dS)z3Update the additional help entries on the Help menurrXrrrYN)
r	ZGetAllExtraHelpSourcesListr�r�rr
rr��"_EditorWindow__extra_help_callbackr)r Z	help_listZhelpmenuZhelpmenu_length�entryrSrrrrBs


!z$EditorWindow.reset_help_menu_entriescs|�fdd�}|S)zCCreate a callback with the helpfile value frozen at definition timecs�|jd	�s$tjj|�}ntjdd�dkr�ytj|�Wq�tk
r�}z*tj	dddt
|�d�j�WYdd}~Xq�Xn
tj
|�dS)
N�www�httprHrIr'zDocument Start Failurer(r)rwrx)rZr-r.rlrrhr)r*r�r�r�rRr+r,)�helpfiler-)r rr�display_extra_helpUs,z>EditorWindow.__extra_help_callback.<locals>.display_extra_helpr)r ryrzr)r rZ__extra_help_callbackSsz"EditorWindow.__extra_help_callbackcszg}tjj|j�rQt|jddddd��}|j�}WdQXn|r�tjj|�d}||kr�|j|�n|jd|�ng�xG|D]?}d	|ks�tjj|dd��r��j	|�q�q�W�fdd�|D�}d
}|dt
|��}y8t|jddddd��}|j|�WdQXWn{tk
r�}z[t
|jdd�s�d|j_tjdddd|jt|��d|j�nWYdd}~XnXx�|jjD]�}|j}	|	jdt�xlt|�D]^\}
}|j�}|j|�}|j|�}
|	jd||
d|d|
dd�qWq�WdS)z/Load and update the recent files list and menus�rrC�utf_8�errorsr6Nrar�rXcs"g|]}|�kr|�qSrr)�.0r.)�	bad_pathsrr�
<listcomp>ss	z9EditorWindow.update_recent_files_list.<locals>.<listcomp>Z1234567890ABCDEFGHIJKr*�recentfilelist_error_displayedFTr'zIDLE Warningr(z|Cannot update File menu Recent Files list. Your operating system says:
%s
Select OK and IDLE will continue without updating.rrr�rYrre)r-r.r�rwr,�	readlinesr0�remover��appendr��
writelinesr*rrnr�r��showwarningr�r�rRrsrvrrr�	enumerate�rstrip�#_EditorWindow__recent_file_callbackr)r �new_fileZrf_listZrf_list_filer.ZulcharsZrf_file�err�instancerK�i�	file_nameZ
ufile_name�callbackr)r�rr�bsL
) 	z%EditorWindow.update_recent_files_listcs|�fdd�}|S)Ncs�jjd|�dS)NZeditFile)r�r,)Z
fn_closure)r rr�open_recent_file�sz=EditorWindow.__recent_file_callback.<locals>.open_recent_filer)r r�r�r)r rZ__recent_file_callback�sz#EditorWindow.__recent_file_callbackcCs�|j�}|j�}|r9|r9|d|t}n$|rH|}n|rW|}nd}|pl|pl|}|j�s�d|}d|}n|jj|�|jj|�dS)Nz - �Untitledz*%s*z*%s)�short_title�
long_title�_py_version�	get_savedrsZwm_titleZwm_iconname)r ZshortZlongr'Ziconrrrr��s		

zEditorWindow.saved_change_hookcCs
|jj�S)N)r�r�)r rrrr��szEditorWindow.get_savedcCs|jj|�dS)N)r��	set_saved)r Zflagrrrr��szEditorWindow.set_savedcCs|jj�dS)N)r��
reset_undo)r rrrr��szEditorWindow.reset_undocCs:|jj}|r'tjj|�}nd}|j|�S)Nr�)r�r�r-r.r�r�)r r�rrrr��s
zEditorWindow.short_titlecCs|j|jjpd�S)Nr9)r�r�r�)r rrrr��szEditorWindow.long_titlecCs|j�dS)N)rT)r rVrrrr��sz EditorWindow.center_insert_eventr�cCsb|j}|j�\}}|j|�}||}td||d�}|jt|��dS)NrXr#)rR�getwindowlines�	getlineno�maxr��float)r �markrRrs�botr8rTZnewtoprrrrT�s	
zEditorWindow.centercCsp|j}|jd�}|jd�}||krf|j�dkrft|d�}||d}n||fS)Nz@0,0z@0,65535rXrT)rRr�Zwinfo_heightrQ)r rRrsr�rTrrrr��s	zEditorWindow.getwindowlinescCs"|j}tt|j|���S)N)rRrQr�r�)r r�rRrrrr��s	zEditorWindow.getlinenocCs:|jj�}tjd|�}ttt|j���S)zReturn (width, height, x, y)z(\d+)x(\d+)\+(-?\d+)\+(-?\d+))rsZwm_geometryr��match�list�maprQ�groups)r r9�mrrr�get_geometry�szEditorWindow.get_geometrycCs|j�dS)N)r~)r rVrrrr�szEditorWindow.close_eventcCsh|jrd|j�sW|jj�dkr:|jj�n|jj�|jj�n|jj�SdS)Nr")r�r�rsr�r7�lowerr8�	maybesave)r rrrr��s	
zEditorWindow.maybesavecCs/|j�}t|�dkr+|j�n|S)NZcancel)r�r��_close)r Zreplyrrrr~�s
zEditorWindow.closecCs�|jjr%|jd|jj�ntj|j�|j�|jj�d|_d|_|j	r�|j	jd�d|_	nd|_
d|_|jj�d|_|j
j�|jr�|j�ndS)Nr�F)r�r�r�rZunregister_callbackr��unload_extensionsr~r�r�rRrur�rsr4r[)r rrrr��s"

					
	
	zEditorWindow._closecCsi|_|j�dS)N)�
extensions�load_standard_extensions)r rrrr�s	zEditorWindow.load_extensionscCsIx9t|jj��D]"}t|d�r|j�qqWi|_dS)Nr~)r�r��values�hasattrr~)r �insrrrr�szEditorWindow.unload_extensionscCsTxM|j�D]?}y|j|�Wq
tdt|��tj�Yq
Xq
WdS)NzFailed to load extension)rj�load_extension�print�repr�	traceback�	print_exc)r rLrrrr�sz%EditorWindow.load_standard_extensionscCstjdd�S)NZeditor_onlyT)r	Z
GetExtensions)r rrrrjsz)EditorWindow.get_standard_extension_namescCs�yKytjd|dt�}Wn'ttfk
rItj|�}YnXWn"tk
rotd|��YnXt||�}tj|�}t	|d�r�|j
|j|�n||�}||j|<|r�|j
|�x�|D]�}|jdd�}x*|dd�dkr*|dd�}qWx*|dd�d	krW|dd�}q.W|d
}t	||�r�|jj|t||��q�q�WndS)
Nr��packagez
Failed to import extension: rr�-r`rXr�r�Z_eventrere)r<�
import_module�__package__r?�	TypeErrorr�rr	rkr�r
rrr�r}r6rRr3)r rL�mod�clsrlr�ZveventZ
methodnamerrrr�s2





zEditorWindow.load_extensioncCsg|dkr|jj}n|j}||_x3|j�D]%\}}|r:|j||�q:q:WdS)N)rDrhrRrlrir�)r rlrRrVrmrrrr}2s		zEditorWindow.apply_bindingsc
Csu|dkr|jj}n|dkr6|jj}n|j}|j}x&|D]\}}|j|�}|svqOnx�|D]�}|s�|j�q}|\}	}
|	dd�dk}|r�|	dd�}	nt|	�\}}	t||
�}
||
dd�}|rG|j	|
t
�}|jd|	d|d|d	|
d
|�q}|jd|	d|d|d	|
�q}WqOWdS)zAdd appropriate entries to the menus and submenus

        Menus that are absent or None in self.menudict are ignored.
        NrX�!cSs|j|�dS)N)r)rRrrrrrYTsz(EditorWindow.fill_menus.<locals>.commandrrrYrqZvariable)
rDrrrhr�rRr�r�r	rs�get_var_objZ
BooleanVarZadd_checkbuttonr)r rrrlr�rRZmnameZ	entrylistrKrvrrZcheckbuttonrrqrY�varrrrr
;s8		


zEditorWindow.fill_menuscCs5|j|�}|r%|j�}|St|��dS)N)r�r��	NameError)r rLr��valuerrr�getvar`s
zEditorWindow.getvarcCs8|j||�}|r(|j|�nt|��dS)N)r�r�r�)r rLr��vartyper�rrr�setvarhszEditorWindow.setvarcCs@|jj|�}|r<|r<||j�|j|<}n|S)N)rur�rR)r rLr�r�rrrr�os
zEditorWindow.get_var_objcCs<|jr4|jjd|�p3d|jj|�kSdSdS)NZTODO�STRINGrX)r�rR�
tag_prevrangeZ	tag_names)r Z
text_indexrrr�is_char_in_strings	zEditorWindow.is_char_in_stringcCsOy2|jjd�}|jjd�}||fSWntk
rJdSYnXdS)Nz	sel.firstzsel.last)NN)rRr�r#)r r�r�rrr�get_selection_indices�s
z"EditorWindow.get_selection_indicescCs|jdpt}t|�S)N�tabs)rR�TK_TABWIDTH_DEFAULTrQ)r Zcurrentrrr�get_tk_tabwidth�szEditorWindow.get_tk_tabwidthcCs^|j}|j�|krZ|jjdd|dd|jd|�}|jd|�ndS)Nr\Zmeasurez
-displayof�nr�)rRr�r$r%ZmasterZ	configure)r ZnewtabwidthrRZpixelsrrr�set_tk_tabwidth�s		
zEditorWindow.set_tk_tabwidthTcCsu|ra|ra|j�}d|ko/dknr@||_n|j|jkrad|_qan|j|j�dS)Nr#rF)�guess_indentr�r�r�r�)r r�Zguessr�rrrr��sz#EditorWindow.set_indentation_paramscCs�|j}|j�\}}|rK|rK|j||�|jd|�dS|jdd�}|dkr�|jddd�r�|jd�n
|j�dS|dd	kr�|jd�dS|j}t|j	|��}|d
ks�t
�|d|j|j}|jr't
jjd�d}	nd}	d
}
xc||	krFPn|dd�}|
d}
t|j	|��}||ks�|dd	kr6Pq6q6W|j�|jd|
d�||kr�|jdd
||�n|j�dS)Nr�rUzinsert linestartr9r�z1.0z	insert-1crXz 	rraz
insert-%dcr�rererere)rRr�rr�r�r�r7r�r��
expandtabs�AssertionErrorr�r�rror�r�r�r�)r rVrRr�r��charsr�ZhaveZwant�last_line_of_promptZ
ncharsdeletedrrrr��sJ	

		


z"EditorWindow.smart_backspace_eventc

CsH|j}|j�\}}|j�z|r||r|t|�t|�krY|j|�S|j||�|jd|�n|jdd�}t||j	�\}}|t
|�kr�|j||j�nU|j
r�d}n3t
|j|j	��}|j}	d|	||	}|jd|�|jd�dSWd|j�XdS)Nr�zinsert linestartr�r�rU)rRr�r��
index2liner�rr�r��
classifywsr�r��reindent_tor�r�r�r�r�r�)
r rVrRr�r��prefix�raw�	effectiveZpadr�rrrr��s,	

			
zEditorWindow.smart_indent_eventcCs|j}|j�\}}|j�z�|rW|rW|j||�|jd|�n|jdd�}dt|�}}x*||kr�||dkr�|d}qW||kr�|jdd�dS|d|�}d}tj	j
d�d
}	x@|r7|ddkr7||	kr7|dd�}|d}q�W|rU|jd|d�nx&|jd�dkr}|jd�qXW|jdd�t|jd��}
t
j|j|j�}|jsjx�|jD]�}t|
|d�}
t|
�d	}|j|d�}|j|�|j|j|j|��}|dk	sL|
dkr�Pq�q�W|j|pcd�nW|jd
d�}|r�|d}nd}|j|d�}|j|�|jd�|j�}|t
jkr�|t
jkr�n�|t
jkr|jd|�n�|t
jkr5|j|j ��nc|t
j!kr|j"�dkri|jd|�q�|j|j#��nds�t$d|f��dS|j%�}|jd|�|j&�r�|j'|�n"|r�|j(�r�|j)|�ndSWd|j*d�|j+�XdS)Nr�zinsert linestartrz 	rXrarUzinsert - %d charsz.0Zconsolez1.0zbogus continuation type %rrerere),rRr�r�rr�r�r�r�rror�r�r�rZParserr�r�r�r�r�r�Zset_strZfind_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_indentr�Zget_base_indent_stringZis_block_openerr�Zis_block_closerr�r�r�)r rVrRr�r�r�r�r��indentr�Zlnor�contextZstartatZstartatindexZrawtextZbodr{r�rrrr�s�	
%	




z%EditorWindow.newline_and_indent_eventcCs||jdd�}|S)NcSs||d|�S)Nz+%dcr)�offsetZ_startindexZ_icisrrr�innerosz6EditorWindow._build_char_in_string_func.<locals>.inner)r�)r Z
startindexr�rrrr�nsz'EditorWindow._build_char_in_string_funcc
Cs�|j�\}}}}xstt|��D]_}||}|r+t||j�\}}	|	|j}	|j|	�||d�||<q+q+W|j||||�dS)NrU)�
get_regionr�r�r�r�r��_make_blanks�
set_region)
r rVrJrKr��linesrcr�r�r�rrrr�ts

(z EditorWindow.indent_region_eventc
Cs�|j�\}}}}x|tt|��D]h}||}|r+t||j�\}}	t|	|jd�}	|j|	�||d�||<q+q+W|j||||�dS)NrrU)	r�r�r�r�r�r�r�r�r�)
r rVrJrKr�r�rcr�r�r�rrrr�s
(z EditorWindow.dedent_region_eventcCsk|j�\}}}}x6tt|�d�D]}||}d|||<q/W|j||||�dS)NrXz##)r�r�r�r�)r rVrJrKr�r�rcr�rrrr��s

z!EditorWindow.comment_region_eventcCs�|j�\}}}}x�tt|��D]x}||}|sGq+n|dd�dkrp|dd�}n)|dd�dkr�|dd�}n|||<q+W|j||||�dS)Nr#z##rX�#)r�r�r�r�)r rVrJrKr�r�rcr�rrrr��s
z#EditorWindow.uncomment_region_eventc
Cs�|j�\}}}}|j�}|dkr4dSx{tt|��D]g}||}|rGt||�\}	}
t|
|�\}}d|d|||	d�||<qGqGW|j||||�dS)Nr�r�)r��_asktabwidthr�r�r��divmodr�)
r rVrJrKr�r�r�rcr�r�r��ntabs�nspacesrrrr��s
+z EditorWindow.tabify_region_eventcCs�|j�\}}}}|j�}|dkr4dSx1tt|��D]}||j|�||<qGW|j||||�dS)N)r�r�r�r�r�r�)r rVrJrKr�r�r�rcrrrr��sz"EditorWindow.untabify_region_eventcCsZ|jddd
|jdd|jdd	d
|j�rV|j|_d|_ndS)NzToggle tabsz
Turn tabs �on�offz?
Indent width �will be�
remains atz 8.z!
 Note: a tab is always 8 columnsrrrU)r�r�)r�r�)r�r�rRr�)r rVrrrr��s!
zEditorWindow.toggle_tabs_eventcCs_|jddd|jd|jdddd�}|r[||jkr[|jr[||_nd	S)
NzIndent widthz6New indent width (2-16)
(Always use 8 when using tabs)rr:�minvaluer#�maxvalue�rU)r�rRr�r�)r rVr�rrrr��s			z%EditorWindow.change_indentwidth_eventcCs�|j}|j�\}}|rP|rP|j|d�}|j|d�}n|jd�}|jd�}|j||�}|jd�}||||fS)Nz
 linestartz-1c lineend +1czinsert linestartzinsert lineend +1cra)rRr�r�r�r�)r rRr�r�rJrKr�r�rrrr��s	zEditorWindow.get_regioncCs�|j}dj|�}||kr2|j�dS|jddd�|jd|�|j�|j||�|j||�|j�|j	d|d�dS)Nrar�z1.0rdr�)
rRr/r7r�r�r�rr�r�r�)r rJrKr�r�rR�newcharsrrrr��s	


zEditorWindow.set_regioncCs=|jr1t||j�\}}d|d|Sd|SdS)Nr�r�)r�r�r�)r r�r�r�rrrr��s	zEditorWindow._make_blankscCsk|j}|j�|jddd�r;|jdd�n|r]|jd|j|��n|j�dS)Nzinsert linestartz!=r�)rRr�r�rr�r�r�)r r�rRrrrr��s	
zEditorWindow.reindent_tocCs.|jddd|jd|jdddd�S)	Nz	Tab widthzColumns per tab? (2-16)rr:r�r#r�r�)r�rRr�)r rrrr�s		zEditorWindow._asktabwidthcCsrt|j|j�j�\}}|r`|r`t||j�\}}t||j�\}}n
d}}||S)Nr)�IndentSearcherrRr�r�r�)r ZopenerZindentedr�ZindentsmallZindentlargerrrr�s!
zEditorWindow.guess_indent)zfiler�)zeditr�)zformatr�)zrunr)rr)zwindowsr)zhelpr)rrN)r:r;r<Zidlelib.Percolatorr>Zidlelib.ColorDelegatorr?Zidlelib.UndoDelegatorr@Zidlelib.IOBindingrArBrCrIrD�tkinterrEZidlelib.MultiStatusBarrFrfr!r�r�r�r�r�rr|r�rr�rrr rr&r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rUr�r[r\r�r^r_r��stringZ
ascii_lettersZdigitsrbrerfrprtr�rrur�r�r�r�r�r�r�r�r�rTr�r�r�rr�r~r�r�r�r�rjr�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�rrrrr=[s��+	
		+	$.	
		%	0#k


	r=cCstt|��S)N)rQr�)r�rrrr�sr�cCstd}}x]|D]U}|dkr:|d}|d}q|dkre|d}||d|}qPqW||fS)Nrr�rXr�r)�sr�r�r�Zchrrrr�$s




r�c@sOeZdZdd�Zdd�Zejejddd�Zd
d�Z	dS)r�cCs6||_||_d|_|_d|_|_dS)Nr)rRr�r��finished�blkopenline�indentedline)r rRr�rrrr!<s		zIndentSearcher.__init__cCsd|jr
dS|jd}|_t|�d}|jj|dd�rMdS|jj||d�S)Nr9rXz.0z>=rdz lineend+1c)r�r�r�rRr�r�)r r�r�rrr�readlineBs	zIndentSearcher.readline�class�def�for�if�try�whilec		Cs^|jrnN||kr0||kr0||_n*||krZ|jrZ||_d|_ndS)NrX)r�r�r�)	r rP�token�startrdr��INDENT�NAMEZOPENERSrrr�
tokeneaterKs		zIndentSearcher.tokeneatercCs�tj}|jt_zVy4tj|j�}x|D]}|j|�q4WWntjtfk
riYnXWd|t_X|j|j	fS)N)
�	_tokenize�tabsizer��generate_tokensr�r��
TokenError�SyntaxErrorr�r�)r Zsave_tabsize�tokensr�rrrr�Ws	
	
zIndentSearcher.runN)zclasszdefzforzifztryzwhile)
r:r;r<r!r�r�r�r�r�r�rrrrr�5s
	r�cCsJ|jd�}|dkr@|d|�||dd�}n||fS)Nr`rrX)r5)r�r�rrrr	is%r	�[Zbracketleft�]Zbracketright�/ZslashcCs	|j|�}|s.tj�r2|dkr2dS|d}tjddd�|�}tjd	d
d�|�}tjdd|�}tjdd
|�}tjdd|�}tjdd|�}tjdd|�}tjdd|�}tjdd|�}|S)N�<<open-module>>�
<<goto-line>>�<<change-indentwidth>>r9rz-[a-z]\bcSs|j�j�S)N)�group�upper)r�rrrrW�sz!get_accelerator.<locals>.<lambda>z\b\w+\bcSstj|j�|j��S)N)�keynamesr�r)r�rrrrW�szKey-ZCancelz
Ctrl-BreakzControl-zCtrl-r�r,z><r�r�r�>r	rr
)r�r
Z	isCocoaTkr�r�)rlrrmr�rrrrsxs"	
rscCsF|j}|jddd�|jddd�|jddd�dS)	NZtcl_wordBreakAfterza brr�Z
tcl_wordcharsz[a-zA-Z0-9_]Ztcl_nonwordcharsz
[^a-zA-Z0-9_])r$r%)rnr$rrr�
fixwordbreaks�s	rcCsx|}t|�tjdd�r3tjd}nd}tj|d�td|d|�}|jjd|j�dS)NrXrnr�z<<close-all-windows>>)	rr�argvr
ZsetupAppr=rRr3r)rrnr�r�rrr�_editor_window�s
r�__main__)r�)5r<Z
importlib.abc�importlib.utilr-rhr�r�rr�Ztkinter.simpledialogZsimpledialogr�Ztkinter.messageboxZ
messageboxr�r�r+Zidlelib.MultiCallrrIrrrrrZidlelib.configHandlerr	r
rrr
rr�Zpython_versionr�r�objectrZ
helpDialogr=r�r��tokenizer�r�r	r
rsrrr:Zidlelib.idle_test.htestr�rrrr�<module>sd
-	������
4	
	

?>