B � fN�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Tddl m Z ddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lm Z dd lm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%ddlm&Z&dZ'de�(�Z)ejdkZ*dd�Z+Gdd�de,�Z-dd�Z.e�/d�Z0dd�Z1Gdd�de,�Z2d d!�Z3d"d#d$d%�Z4d&d'�Z5d(d)�Z6d*d+�Z7e8d,k�r�dd-l9m:Z:e:d.d/d0d1�dd2l;md;d<�Z?d�d=d>�Z@d�d?d@�ZAd�dAdB�ZBd�dCdD�ZCdEdF�ZDdGdH�ZEdIdJ�ZFd�dKdL�ZGd�dMdN�ZHdOdP�ZIdQdR�ZJdSdT�ZKdUdV�ZLdWdX�ZMdYdZ�ZNd[d\�ZOd]d^�ZPd_d`�ZQdadb�ZRdcdd�ZSd�dedf�ZTd�dgdh�ZUd�didj�ZVdkdl�ZWdmdn�ZXdodp�ZYdqdr�ZZdsdt�Z[dudv�Z\dwdx�Z]dydz�Z^e_j`e_jad{Zbd|d}�Zcd~d�Zdd�d��Zed�d��Zfd�d��Zgd�d��Zhd�d��Zid�d��Zjd�d�d��Zkd�d��Zld�d��Zmd�d��Znd�d��Zod�d��Zpd�d��Zqd�d��Zrd�d��Zsd�d�d��Ztd�d��Zud�d�d��Zvd�d��Zwd�d��Zxd�d��Zyd�d��Zzd�d��Z{d�d��Z|d�d��Z}d�d��Z~d�d��Zd�d�iZ�d�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�d΄Z�d�dЄZ�d�dÒ„Z�d�dÔ„Z�d�dÖ„Z�d�dØ„Z�d�dÚ„Z�d�dÜ„Z�d�d�dÞ„Z�dS)�� EditorWindowr)� Percolator)�ColorDelegator� color_config)� UndoDelegator)� IOBinding�encoding)�mainmenu)�MultiStatusBar)� AutoComplete)� AutoExpand)�Calltip)� CodeContext)� LineNumbers)�FormatParagraph� FormatRegion�Indents�Rstrip)� ParenMatch)�Squeezer)� ZoomHeightNTc CsH ddlm}tjdk�rtj�tjdd�}tj � d�rvddtj dd�}tj� d �r^d }q�d }tj�||dd�}nVtj dd�d kr�tj�tjdd t ��} tj�| �r�| }ntj dkr�tj�tjd�}tj�|�}tj�|��r|t_tj dk�rdtjt_ndtj dd�t_||_|�p*|j}||_t|�|_tj||jd�|_} |�rl|j|_|j|j_ni|_i|j_tj�o�tj�tjd�|_d|_t| �|_ } t!| dd�|_"} tj#ddddd�} dddd| d tj#ddd!dd�d"�}t$t%�| f|�|_&}|j&|j_'|�(�|�)�|j�*d#|j+�|j�,d$|j-�t.�/��rt|�,d$|j-�|�,d%|j0�|�,d&|j0�n|�,d'|j0�|�,d(t1�|�,d)t1�|�,d*t1�|�,d+|j2�|�,d,|j3�|�,d-|j4�|�,d.|j5�|�,d/|j6�|�,d0|j7�|�,d1|j8�|�,d2|j9�|�,d3|j:�|�,d4|j;�|�,d5d6d7��|�,d8|j<�|�,d9|j=�|�,d:|j>�|�,d;|j?�|�,d<|j@�|�,d=|jA�|�,d>|jB�|�,d?|jC�|�,d@|jD�|�,dA|jE�|�,dB|jF�|�G|�|_H}|�,dC|jI�|�,dD|jJ�|�,dE|jK�|�,dF|jL�|�,dG|jM�|�,dH|jN�|�O|�}|�,dI|jP�|�,dJ|jQ�|�,dK|�Rd��|�,dL|�RdM��|�,dN|jS�|�,dO|jT�|�,dP|jU�|�r||j|<|�r�||jV|<|�,dQ|jW�|�,dR|jjX�|�,dS|jY�|�,dT|jZ�|�,dU|j[�|�\�| j]t^t_dMdV�| j`dMdMdW�| jadMdMdW�|jb| dX<| jcdMdtddY�| je|dZ<t�f|jdd�|d[<|jcdMdMtddY�|�g�|�h�tj#dd\d]d^d�}| |_id_|_j|jj|_k|�l�tmtd`��s�|j&dat_n|�o�db|_p|�q|�|_r}|�s�|_t}|�u|�|jv|_v|jw|_w|�x|jy�|�z|�|_{}|�||j}�dc|_~|�dc�d|_�d|_�d|_�|�r�tj��|��r�tj� |��s�|��|��r�dd|_~|��|�}|�|�n|��|�dd|_~|���|�y�|���|���|j���de�}|�rP|��df�}|dk�r$dg}|dk�r>|���|dM}||_�t��|j��t�j�|_�t�j�|_�t�j�|_�|��dhdi�|��djdkdldm�|��dndo�|��dpdq�|��drdqdsdt�|��|�}|�,dh|j��|�,dj|j��|�,du|j��|�,dv|��|�j��|�,dw|��|�j��|��|�}|�,dx|j��|�,dr|j��||�}|�,dy|j��|�,dz|j��|�,d{|j��|�,d||��|�j��|��|�|_�}|�,dn|j��|�,dp|j��|�,d}|j��|�,d~|��|�j��|j��r�|��|�|_�|�,d|j�j��n|��d�d�d��|j�� r6|��|�|_�tj#ddd�d^d�� r&|���|�,d�|j��n|��d�d�d��dS)�Nr)� ScriptBindingZDocz index.htmlZlinuxz python-docs-z%s.%s.%s�z/var/www/html/python/z/var/www/html/python/index.htmlz/usr/share/doc/�winz Python%s.chmrz0Resources/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=�padxZwrapZhighlightthicknessr?ZtabstylerDZWM_DELETE_WINDOWz<>zz<2>z<3>z z z z z<>z<>z <>z<>z<>z<>z<>z<>z<>z<>cSsdS)N�breakr)�eventrrr���z'EditorWindow.__init__..z<>z<>z<>z<>z<>z<>z <>z <>z<>z<>z<>z<>z<>z<>z<>z<>z<>z<>z<>zz�z<>z<>z<>z<>z<>z<>z<>z<>)�side�fill�expand)Zweight�command)�row�columnZstickyZyscrollcommand�font�Indentz use-spaces�boolr�blink_off_time� insertofftime)�2i�i@KLFTr�end�����z<>z z<>zzzz<>zz<>zz<>zzz<>z<>z<>z<>z<>z<>z<>z <>z<>z<>z<>�optionsz *Code Context�disabledzline-numbers-defaultz<>z *Line Numbers)�Zidlelib.runscriptr6r!�help_url�os�path�joinr� base_prefix�platform�countr�isdirr �isfile�normpath�flist�root�Menu�menubarrZListedToplevel�top�vars� tkinter_varsZ inversedict� instance_dictrZuserdir�recent_files_path�prompt_last_line�Frame� text_framerr<� GetOptionr ZTextrBZfocused_widget� createmenubar�apply_bindingsZprotocol�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_eventr0�fregion�indent_region_eventZdedent_region_eventZcomment_region_eventZuncomment_region_eventZtabify_region_eventZuntabify_region_eventr1Ztoggle_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�hasattrrT�update_cursor_blink�num_context_linesr"�perr%�undo� 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�postwindowsmenu� tkMessageBoxZaskyesno�tkSimpleDialogZ askinteger� showerror� event_addr*Zautocomplete_eventZtry_open_completions_eventZforce_open_completions_eventr+Zexpand_word_eventr/Zformat_paragraph_eventr3Zflash_paren_eventZparen_closed_eventZcheck_module_eventZrun_module_eventZrun_custom_eventr2Z do_rstripr,�ctipZtry_open_calltip_eventZrefresh_calltip_eventZforce_open_calltip_eventr5Zzoom_height_event�allow_code_contextr-Ztoggle_code_context_event�update_menu_state�allow_line_numbersr.�toggle_line_numbers_event)�selfre�filename�keyrfr6ZdochomeZpyverZbasepathZchmfilerirpr<r?Z text_optionsrBr��indentsZ usespacesr�r�r�� is_py_srcr:rWZ autocompleteZ parenmatchZ scriptbindingr�rrr�__init__Hs�                                                     zEditorWindow.__init__cCs |��dS)N)r�)r�rGrrrrx`szEditorWindow.handle_winconfigcCs^|j}tt|jj|�d�|�d�g��}|��d|}t||�d�d��d�}|||_ dS)NZborderrEr9rQ)rQ�0) rB�sum�map�tkZgetintZcgetZ winfo_widthr�measurer?)r�rBZ inner_paddingZ pixel_widthZzero_char_widthrrrr�cs zEditorWindow.set_widthcCs|j��\}}|j�|�dS)NrF)r�Zdefaultfilenamere�new)r�rG�dirname�basenamerrrr�ps zEditorWindow.new_callbackcCs�|jd@dkr|jdkrdS|j�d�rd|j�ddd�rd|j�ddd�rdt|j�d��d�d �}n:|j�dd�}x*tt |��D]}||d kr�Pq�Wt |�}t|j�d ��d�d �}||kr�d}d t |�d }|jd @dkr�|j� ddd�n�|j�d��s|j� dd �n@|j�|j�d�d|j�d ���rD|j� dd�n|j� dd�|j�|�}|j�d�}|j�|d|��r�||}}|j� ddd�|j� d||�|j� d |�|j�d �dS)N�rZHomeZiomarkz<=zinsert lineendzinsert linestart�.rJ)� � �insertzinsert linestart+�c�selz1.0rWz sel.firstZ my_anchor�rF)�stateZkeysymrBr��comparer@�splitr��range�len�str� tag_remove�mark_set�tag_add�see)r�rGZinsertpt�lineZlineat�dest�first�lastrrrr�us@      zEditorWindow.home_callbackcCs�|�|j�|_t|jdddd�}tjdkr<|jjddtd�|jjdd td�|jjd d td�|jjt t d �|jt t d �|j � d |j �|j �d dd�|j �|j �dS)NrJZgrey75)rDZ borderwidthZ backgroundrZ _padding1z )rKrPzCol: ?r�zLn: ?)rKrLz<>z z)r)ri� status_barrorr`� set_labelZRIGHTr�ZBOTTOM�XrBru�set_line_and_columnr�Z after_idle)r��seprrrr��s zEditorWindow.set_status_barcCs>|j�t��d�\}}|j�dd|�|j�dd|�dS)Nr�rPzCol: %sr�zLn: %s)rBr�ZINSERTr�r�r�)r�rGr�rPrrrr��sz EditorWindow.set_line_and_column)�fileZ_File)�editZ_Edit)�formatZF_ormat)�runZ_Run)rYZ_Options)rZ_Window)rZ_HelpcCs�|j}i|_}xD|jD]:\}}t|�\}}t||dd�||<}|j|||d�qWt��r�t|ddd�|d<}|jd|d�|��t|jdd�|_ |jd j d d d|j d �|jd � t �|_ |��dS)Nr)r=�tearoff)�labelr:� underlineZappleZ applicationZIDLE)r�r:)r�r�r7z Recent Files)r�r�r:r)rhr�� menu_specs�prepstrrgZ add_cascader Z isCarbonTk� fill_menus�recent_files_menuZinsert_cascader��END�base_helpmenu_length�reset_help_menu_entries)r�Zmbarr�r=r�r�r:rrrrr�s"   zEditorWindow.createmenubarcCsJ|jd}|�d�}|dkr d}||jkr<|�|jd|�t�|�dS)NrrWrXrJ)r�r�r��deleterZadd_windows_to_menu)r�r:rWrrrr��s   zEditorWindow.postwindowsmenucCs|j|}|j||d�dS)z$Update label for menu item at index.)r�N)r�� entryconfig)r�r:r�r��menuitemrrr�update_menu_label�s zEditorWindow.update_menu_labelcCs|j|}|j||d�dS)z$Update state for menu item at index.)r�N)r�r�)r�r:r�r�rrrrr��s zEditorWindow.update_menu_statecGsR|dkr>NcCsjt|jdd�}xP|jD]F}|d|d}}|dk rT|j|fdd�}|j||d�q|��qW||_dS)Nr)r�rJcSs|�|�dS)N)�event_generate)rBrrrrrN"sz(EditorWindow.make_rmenu..command)r�rN)rgrBr� add_commandr�r )r�r rr�rrNrrrrs  zEditorWindow.make_rmenucCs|��S)N)�rmenu_check_copy)r�rrr�rmenu_check_cut)szEditorWindow.rmenu_check_cutcCs6y|j�d�}Wntk r$dSX|r.dSdSdS)Nz sel.firstrZ�normal)rBr�r )r�Zindxrrrr,s zEditorWindow.rmenu_check_copycCs6y|jj�d|jd�Wntk r,dSXdSdS)Nztk::GetSelectionZ CLIPBOARDrZr)rBr��callr )r�rrr�rmenu_check_paste4s zEditorWindow.rmenu_check_pastecCst�|j�dS)zHandle Help 'About IDLE' event.rF)r Z AboutDialogri)r�rGrrrr<s zEditorWindow.about_dialogcCst�|jd�dS)z&Handle Options 'Configure IDLE' event.ZSettingsrF)rZ ConfigDialogri)r�rGrrrr�BszEditorWindow.config_dialogcCs"|jr|j}n|j}t�|�dS)zHandle Help 'IDLE Help' event.rF)rfrirZ show_idlehelp)r�rG�parentrrrr}Hs  zEditorWindow.help_dialogc Csntjdd�dkr^yt�|j�Wqjtk rZ}ztjdt|�|j d�Wdd}~XYqjXn t � |j�dS)Nr7r8zDocument Start Failure)�title�messagerrF) rr`r\� startfiler[�OSErrorr�r�r�rB� webbrowser�open)r�rG�whyrrrr~Rs$ zEditorWindow.python_docscCs|j�d�dS)Nz<>rF)rBr)r�rGrrrry]s zEditorWindow.cutcCs |j�d�sdS|j�d�dS)Nr�z<>rF)rBZ tag_rangesr)r�rGrrrrzas  zEditorWindow.copycCs|j�d�|j�d�dS)Nz <>r�rF)rBrr�)r�rGrrrr{hs  zEditorWindow.pastecCs.|j�ddd�|j�dd�|j�d�dS)Nr�z1.0zend-1cr�rF)rBr�r�r�)r�rGrrrr�ms zEditorWindow.select_allcCs |j�ddd�|j�d�dS)Nr�z1.0rWr�rF)rBr�r�)r�rGrrrr�ss 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+1cz sel.last-1ccsB|jd@dkr>y�d��d���Wntk r<YnXdS)NrCrz sel.firstr�)r�r )rG)� edge_index� edges_table�self_text_index�self_text_mark_setrr� move_at_edge�s z.move_at_edge)rBr�r�)r�r#r'r)r#r$r%r&rr�xs z&EditorWindow.move_at_edge_if_selectioncCs|j�d�dS)Nz rF)rBr)r�rGrrrr��s zEditorWindow.del_word_leftcCs|j�d�dS)NzrF)rBr)r�rGrrrr��s zEditorWindow.del_word_rightcCst�|j�dS)NrF)r�findrB)r�rGrrrr��s zEditorWindow.find_eventcCst�|j�dS)NrF)rZ find_againrB)r�rGrrrr��s zEditorWindow.find_again_eventcCst�|j�dS)NrF)rZfind_selectionrB)r�rGrrrr��s z!EditorWindow.find_selection_eventcCst�|j|j|j�dS)NrF)rrBr�re)r�rGrrrr��sz EditorWindow.find_in_files_eventcCst�|j�dS)NrF)rrB)r�rGrrrr��s zEditorWindow.replace_eventcCsT|j}t�|dd�j}|dk rP|�ddd�|�d|�d��|�d�|��dS) Nz Go To Linez/Enter a positive integer ('big' = end of file):r�z1.0rWr�z.0rF)rBr ZGoto�resultr�r�r�r�)r�rGrB�linenorrrr��s zEditorWindow.goto_line_eventcCspy|j�dd���}Wntk r.d}YnXt�|jdd|�j}|dk rl|jr`|j�|�n |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. z sel.firstzsel.lastr;z Open ModulezAEnter the name of a Python module to search on sys.path and open:N) rBr��stripr r Z ModuleNamer)rer!r�r�)r�r=� file_pathrrr� open_module�s  zEditorWindow.open_modulecCs |��dS)NrF)r-)r�rGrrrr��szEditorWindow.open_module_eventcCsJ|jj}|jjdkr|s,|��}|dkr,dSddlm}|�|j|�dS)NZPyShellEditorWindowrFr)�browser) r�r�� __class__�__name__r-�idlelibr.Z ModuleBrowserrf)r�rGr�r.rrrr��s  z EditorWindow.open_module_browsercCsddlm}|�|j�dS)Nr)� pathbrowserrF)r1r2Z PathBrowserrf)r�rGr2rrrr��s  zEditorWindow.open_path_browsercCs&ddl}tjddg}|j|dd�dS)Nrz-cz,from turtledemo.__main__ import main; main()F)�shellrF)� subprocessr� executable�Popen)r�rGr4�cmdrrrr��s zEditorWindow.open_turtle_democCsN|dk rJ|dkrJ|j�dd|�|j�ddd�|j�ddd�|��dS)Nrr�z%d.0r�z1.0rWz insert +1l)rBr�r�r��center)r�r*rrr�gotoline�s zEditorWindow.gotolinecCs`|rtj�|�rdStj�tj�|��\}}tj�|�dkr@dS|j�dd�}|�d�o^d|kS)NT)z.pyz.pywz1.0z 1.0 lineendz#!�python) r\r]rb�splitextr��normcaserBr�� startswith)r�r��baseZextr�rrrr��szEditorWindow.ispythonsourcecCs|jr|j�|�d|_dS)N)reZunregister_maybe_terminate)r�rrr� close_hook�s zEditorWindow.close_hookcCs ||_dS)N)r?)r�r?rrr�set_close_hookszEditorWindow.set_close_hookcCs2|jr|j�|�|��|j�|�|��dS)N)reZfilename_changed_editr�riZupdate_windowlist_registryr�)r�rrrr�s   z!EditorWindow.filename_change_hookcCsV|jr dS|�|jj�r"|��|_|jrR|j�|j�|j�|j�|j�|j�dS)N) r�r�r�r�r#r�� removefilterr�r�)r�rrr� _addcolorizer s zEditorWindow._addcolorizercCs,|js dS|j��|j�|j�d|_dS)N)r�Z removecolorsr�rA)r�rrr� _rmcolorizers  zEditorWindow._rmcolorizercCsH|��|��t�|j�|jdk r0|j��|jdk rD|j��dS)zUpdate the color themeN) rCrBr!r$rBr�Zupdate_highlight_colorsr�Z update_colors)r�rrrr�s    zEditorWindow.ResetColorizer�_cCsp|�d|�|�|�}|r6||jkr6|�d|d|�d|�|�krR|�d|�n|�d|d�|�|�dS)NZERRORz wordstart� r�z+1c)r�r�� IDENTCHARSr�r�)r�rB�pos�charrrr�colorize_syntax_error+s  z"EditorWindow.colorize_syntax_errorcCs2tjddddd�}|s"d|jd<n tj|jd<dS) z&Update the cursor blink configuration.r>r!z cursor-blinkrS)rArrUN)rrqrBrT)r�Z cursorblinkrrrr�6s  z EditorWindow.update_cursor_blinkcCsN|jdk r|j��|jdk r(|j��t�|jdd�}||jd<|��dS)z.Update the text widgets' font if it is changedNr>r!rQ)r�Z update_fontr�rr�rfrBr�)r�Znew_fontrrr� ResetFont@s     zEditorWindow.ResetFontcCs�t��|j_}x&|��D]\}}|jj|f|��qWxF|��D]:}t�|�}|rBx&|��D]\}}|jj|f|��q^WqBWdS)z/Remove the keybindings before they are changed.N) r�GetCurrentKeySetr(�default_keydefs�itemsrBZ event_delete�get_standard_extension_names�GetExtensionBindings)r��keydefsrG�keylist� extensionName�xkeydefsrrr�RemoveKeybindingsQs zEditorWindow.RemoveKeybindingsc CsVt��|j_}|��x(|��D]}t�|�}|r"|�|�q"Wi}xR|jjD]F}i||d<x4|dD](}|rj|d||dt|d�d<qjWqPWx�|j D]�}|j |}|� t �}|dkr�q�|d7}x�t d|�D]r} |� | �dkr�|�| d�} | r�|�| d�} d} ||k�r.| ||k�r.||| } | r�t|| �} |j| | d�q�Wq�WdS) z-Update the keybindings after they are changedrrJNrN� acceleratorr�r;)rU)rrKr(rLrsrNrO�menudefsr�r�r�r�r�rAZ entrycget�get_acceleratorr�) r�rPrRrSZ menuEventDictr:rZ menubarItemrWr�ZaccelZitemNamerGrrr�ApplyKeybindings]s<  (        zEditorWindow.ApplyKeybindingscCs|jstjddddd�|_dS)zCUpdate the indentwidth if changed and not using tabs in this windowr>rRz num-spacesr@)rAN)r�rrqr�)r�rrrr��s z#EditorWindow.set_notabs_indentwidthcCs�t��}|jd}|�t�}||jkr8|�|jd|�|rr|��x,|D]$}|�|d�}|j |d|d�qJW||jd<dS)z3Update the additional help entries on the Help menurrJr)r�rNN) rZGetAllExtraHelpSourcesListr�r�r�r�r�r��"_EditorWindow__extra_help_callbackr)r�Z help_listZhelpmenuZhelpmenu_length�entryr7rrrr��s    z$EditorWindow.reset_help_menu_entriescs|f�fdd� }|S)zCCreate a callback with the helpfile value frozen at definition timec s�|�d�stj�|�}tjdd�dkrryt�|�Wq|tk rn}ztj dt |��j d�Wdd}~XYq|Xn t � |�dS)N)ZwwwZhttpr7r8zDocument Start Failure)rrr)r=r\r]rdrr`rrr�r�r�rBr r!)�helpfiler")r�rr�display_extra_help�s  $z>EditorWindow.__extra_help_callback..display_extra_helpr)r�r[r\r)r�rZ__extra_help_callback�s z"EditorWindow.__extra_help_callbackc s�g}|j}|r>tj�|�r>t|dddd��}|��}WdQRX|rptj�|�d}||krd|�|�|�d|�g�x2|D]*}d|ks�tj�|dd ��sz�� |�qzW�fd d �|D�}d }|dt |��}|�rVy*t|d ddd��}|� |�WdQRXWnVt k �rT}z6t |jdd��sDd|j_tjdd|�d�|jd�Wdd}~XYnXxj|jjD]^} | j} | �dt�xDt|�D]8\} } | ��} | �| �} | j|| d| | dd��q�W�q`WdS)z/Load and update the recent files list and menus�r�utf_8r)r'�errorsNrEr�rXcsg|]}|�kr|�qSrr)�.0r])� bad_pathsrr� �sz9EditorWindow.update_recent_files_list..Z1234567890ABCDEFGHIJK�w�recentfiles_messageFTz IDLE Warningz)Cannot save Recent Files list to disk. z Select OK to continue.)rrrr�)r�rNr�)rmr\r]r�r!� readlines�abspath�remover��appendr�� writelinesrrrfrer�� showwarningrBrirlr�r�r�� enumerate�rstrip�#_EditorWindow__recent_file_callbackr)r��new_fileZrf_listr,Z rf_list_filer]ZulcharsZrf_file�err�instancer:�i� file_name�callbackr)rbrr��sL        z%EditorWindow.update_recent_files_listcs|f�fdd� }|S)Ncs�jj|d�dS)N)ZeditFile)r�r!)Z fn_closure)r�rr�open_recent_file�sz=EditorWindow.__recent_file_callback..open_recent_filer)r�rsrur)r�rZ__recent_file_callback�sz#EditorWindow.__recent_file_callbackcCs�|��}|��}|r*|r*|d|t}n|r4|}n|r>|}nd}|pL|pL|}|��sfd|}d|}|j�|�|j�|�dS)Nz - �untitledz*%s*z*%s)� short_title� long_title� _py_version� get_savedriZwm_titleZ wm_iconname)r�ZshortZlongrZiconrrrr��s  zEditorWindow.saved_change_hookcCs |j��S)N)r�rz)r�rrrrz�szEditorWindow.get_savedcCs|j�|�dS)N)r�� set_saved)r��flagrrrr{�szEditorWindow.set_savedcCs|j��dS)N)r�� reset_undo)r�rrrr}�szEditorWindow.reset_undocCs|jj}|rtj�|�SdS)Nrv)r�r�r\r]r�)r�r�rrrrw�szEditorWindow.short_titlecCs |jjp dS)Nr;)r�r�)r�rrrrx�szEditorWindow.long_titlecCs |��dS)NrF)r8)r�rGrrrr|�sz EditorWindow.center_insert_eventr�cCsH|j}|��\}}|�|�}||}td||d�}|�t|��dS)NrJr9)rB�getwindowlinesr�maxrr)r��markrBri�botr*rDZnewtoprrrr8s   zEditorWindow.centercCsN|j}|�d�}|�d�}||krF|��dkrFt|d�}||d}||fS)Nz@0,0z@0,65535rJrD)rBrZ winfo_heightr@)r�rBrir�rDrrrr~ s    zEditorWindow.getwindowlinescCs|j}tt|�|���S)N)rBr@rr�)r�r�rBrrrrszEditorWindow.getlinenocCs(|j��}t�d|�}ttt|����S)zReturn (width, height, x, y)z(\d+)x(\d+)\+(-?\d+)\+(-?\d+))riZ wm_geometry�re�match�listr�r@�groups)r�Zgeom�mrrr� get_geometrys  zEditorWindow.get_geometrycCs |��dS)NrF)rt)r�rGrrrrvszEditorWindow.close_eventcCsH|jrD|��s:|j��dkr&|j��|j��|j��|j��SdS)Nr)r�rzrir�Z deiconify�lowerZlift� maybesave)r�rrrr�!s   zEditorWindow.maybesavecCs:y |��}t|�dkr|��|Stk r4YnXdS)NZcancel)r�r��_close�AttributeError)r�Zreplyrrrrt*s zEditorWindow.closecCs�|jjr|j|jjd�t�|j�|��|j��d|_d|_|j rX|j ��d|_ d|_ d|_ |j ��d|_ |j ��|jr�|��dS)N)ro)r�r�r�rZunregister_callbackr��unload_extensionsrtr�r�rBrkr�riZdestroyr?)r�rrrr�3s"     zEditorWindow._closecCsi|_|��dS)N)� extensions�load_standard_extensions)r�rrrr�GszEditorWindow.load_extensionscCs4x(t|j���D]}t|d�r|��qWi|_dS)Nrt)r�r��valuesr�rt)r��insrrrr�Ks  zEditorWindow.unload_extensionscCsHxB|��D]6}y|�|�Wq tdt|��t��Yq Xq WdS)NzFailed to load extension)rN�load_extension�print�repr� traceback� print_exc)r�r=rrrr�Qs z%EditorWindow.load_standard_extensionscCs tjdd�S)NT)Z editor_only)rZ GetExtensions)r�rrrrNYsz)EditorWindow.get_standard_extension_namesZZzDummyZzzdummyc CsF|j�||�}y>ytjd|td�}Wn"ttfk rHt�|�}YnXWn tk rltd|��YnXt||�}t � |�}t |d�r�|� |j |�||�}||j|<|�rB|�|�x�|D]|}|�dd�}x |dd�dkr�|dd�}q�Wx"|d d�d k�r|dd �}q�W|d }t ||�r�|j�|t||��q�WdS) Nr�)�packagez Failed to import extension: rV�-rDrJr�rXr�Z_event)�extfilesr�� importlib� import_module� __package__� ImportError� TypeErrorr�rrrOr�r�rVr�rsrrBru) r�r=Zfname�mod�clsrPr�ZveventZ methodnamerrrr�`s4         zEditorWindow.load_extensioncCsJ|dkr|jj}|j}||_x(|��D]\}}|r&|j|f|��q&WdS)N)r(rLrBrPrMr�)r�rPrBrGrQrrrrs|szEditorWindow.apply_bindingsc Cs�|dkr|jj}|dkr |jj}|j}|j}x�|D]�\}}|�|�}|sJq2x�|D]�}|sb|��qP|\} } | dd�dk} | r�| dd�} t| �\} } t|| �} || fdd�}| r�|� | t �}|j | | || |d�qP|j | | || d�qPWq2WdS)zAdd appropriate entries to the menus and submenus Menus that are absent or None in self.menudict are ignored. NrJ�!cSs|�|�dS)N)r)rBrrrrrN�sz(EditorWindow.fill_menus..command)r�r�rNrUZvariable)r�r�rNrU) r(rVrLr�rBr�r�r�rW� get_var_objZ BooleanVarZadd_checkbuttonr)r�rVrPr�rBZmnameZ entrylistr:rZr�rZ checkbuttonr�rUrN�varrrrr��s8        zEditorWindow.fill_menuscCs&|�|�}|r|��}|St|��dS)N)r�r�� NameError)r�r=r��valuerrr�getvar�s  zEditorWindow.getvarcCs(|�||�}|r|�|�nt|��dS)N)r�r�r�)r�r=r��vartyper�rrr�setvar�s  zEditorWindow.setvarcCs,|j�|�}|s(|r(||j�|j|<}|S)N)rkr�rB)r�r=r�r�rrrr��s zEditorWindow.get_var_objcCs,|jr$|j�d|�p"d|j�|�kSdSdS)NZTODO�STRINGrJ)r�rB� tag_prevrangeZ tag_names)r�Z text_indexrrr�is_char_in_string�szEditorWindow.is_char_in_stringcCs:y |j�d�}|j�d�}||fStk r4dSXdS)Nz sel.firstzsel.last)NN)rBr�r )r�r�r�rrr�get_selection_indices�s   z"EditorWindow.get_selection_indicescCs|jdp t}t|�S)N�tabs)rB�TK_TABWIDTH_DEFAULTr@)r�Zcurrentrrr�get_tk_tabwidth�szEditorWindow.get_tk_tabwidthc CsB|j}|��|kr>|j�dd|dd|jd|�}|j|d�dS)NrQr�z -displayof�n)r�)rBr�r�rZmasterZ configure)r�Z newtabwidthrBZpixelsrrr�set_tk_tabwidth�s   zEditorWindow.set_tk_tabwidthcCsP|r@|r@|��}d|kr$dkr.nn||_|j|jkr@d|_|�|j�dS)Nr9rF)� guess_indentr�r�r�r�)r�r�Zguessrrrrrr��s z#EditorWindow.set_indentation_paramsc CsP|j}|��\}}|r6|r6|�||�|�d|�dS|�dd�}|dkrp|�ddd�rd|�d�n|��dS|dd kr�|�d�dS|j}t|� |��}|d ks�t �|d |j |j }d } xJ||j kr�P|dd�}| d } t|� |��}||k�s|dd kr�Pq�W|� �|�d | d�||k�rD|�dd ||�|��dS)Nr�rFzinsert linestartr;r�z1.0z insert-1crXz rrJz insert-%dcr�)rBr�r�r�r�r�Zbellr�r�� expandtabs�AssertionErrorr�rnr�r�r�) r�rGrBr�r��charsr�ZhaveZwantZ ncharsdeletedrrrr��sD           z"EditorWindow.smart_backspace_eventc Cs�|j}|��\}}|��z�|rX|rXt|�t|�kr@|j�|�S|�||�|�d|�|�dd�}t ||j �\}}|t |�kr�|� ||j �n>|jr�d}n&t |�|j ��}|j } d| || }|�d|�|�d�dS|��XdS)Nr�zinsert linestartr�r�rF)rBr�r�� index2liner�r�r�r�r��get_line_indentr�r�� reindent_tor�r�r�r�r�r�) r�rGrBr�r��prefix�rawZ effectiveZpadr�rrrr�&s,        zEditorWindow.smart_indent_eventc Cs�|j}|��\}}|���z�|r>|r>|�||�|�d|�|�dd�}dt|�}}x ||krx||dkrx|d7}qZW||kr�|�dd�dS|d|�}d}x2|r�|d dkr�||jkr�|dd �}|d7}q�W|r�|�d |d�x|�d�dk�r|�d�q�W|�dd�t |� d��} t � |j |j�} |j�s�xf|jD]\} t| | d�} t| �d } |�| d�}| �|�| �|�| ��}|dk �s�| dk�rDP�qDW| �|�p�d�n@|�d d�}|�r�|d} nd } |�| d�}| �|�| �d�| ��}|t jk�r�|t jk�rn�|t jk�r2|�d|�nh|t jk�rN|�| ���nL|t jk�r�| ��dk�rv|�d|�n|�| � ��nd�s�t!d|f��dS| �"�}|�d|�| �#��r�|�$|�n|�r�| �%��r�|�&|�dS|�'d�|�(�XdS)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�zinsert linestartrz rJrErFNrXzinsert - %d charsz.0Zconsolez1.0zbogus continuation type %r))rBr�r�r�r�r�r�r�rnr�r�r ZParserr�r�r�rr�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_indentZ C_BACKSLASHZget_num_lines_in_stmtZcompute_backslash_indentr�Zget_base_indent_stringZis_block_openerr�Zis_block_closerr�r�r�)r�rGrBr�r�r�rrr��indentZlnor �contextZstartatZ startatindexZrawtextZbodr]r�rrrr�Is�                               z%EditorWindow.newline_and_indent_eventcCs||jfdd�}|S)NcSs||d|�S)Nz+%dcr)�offsetZ _startindexZ_icisrrr�inner�sz6EditorWindow._build_char_in_string_func..inner)r�)r�Z startindexr�rrrr��sz'EditorWindow._build_char_in_string_funccCs2|jr&t||j�\}}d|d|Sd|SdS)Nr�r�)r��divmodr�)r�r�ZntabsZnspacesrrr� _make_blanks�szEditorWindow._make_blankscCsJ|j}|��|�ddd�r(|�dd�|r>|�d|�|��|��dS)Nzinsert linestartz!=r�)rBr�r�r�r�r�r�)r�rPrBrrrr��s zEditorWindow.reindent_tocCsPt|j|j���\}}|r@|r@t||j�\}}t||j�\}}nd}}||S)Nr)�IndentSearcherrBr�r�r�)r��openerZindentedr�Z indentsmallZ indentlargerrrr��s zEditorWindow.guess_indentcCsN|jdkrdS|jjr&|j��d}n|j��d}|jdd|�d�d�dS)NZShowZHiderYz *Line Numbersz Line Numbers)r:r�r�)r�Zis_shownZ hide_sidebarZ show_sidebarr)r�rGZ menu_labelrrrr��s   z&EditorWindow.toggle_line_numbers_event)NNNN)N)N)N)N)N)N)N)N)N)N)N)N)r�)r�)N)NN)N)N)T)N)�r0� __module__� __qualname__Zidlelib.percolatorr"Zidlelib.colorizerr#r$Z idlelib.undor%Zidlelib.iomenur&r'r1r(Zidlelib.statusbarr)Zidlelib.autocompleter*Zidlelib.autoexpandr+Zidlelib.calltipr,Zidlelib.codecontextr-Zidlelib.sidebarr.Zidlelib.formatr/r0r1r2Zidlelib.parenmatchr3Zidlelib.squeezerr4Zidlelib.zoomheightr5r�getfilesystemencodingZfilesystemencodingr[r�r�r�rxr�r�r�r�r�r�rrr�rr�r�r rwrrrrrrr�r}r~ryrzr{r�r�r�r�r�r�r�r�r�r�r�r-r�r�r�r�r9r�r?r@r�rBrCr��stringZ ascii_lettersZdigitsrFrIr�rJrTrXr�r�rYr�rnr�rzr{r}rwrxr|r8r~rr�rvr�rtr�r�r�r�rNr�r�rsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr!1s               +   %              $ .     %     ,#v  r!cCs tt|��S)N)r@r)r�rrrr��sr�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�rWr��groupr�)r�r�r�rrrr�s r�c@s8eZdZdd�Zdd�Zejejdfdd�Zdd �Z d S) r�cCs(||_||_d|_|_d|_|_dS)Nr)rBr�rr�finished� blkopenline� indentedline)r�rBr�rrrr�s zIndentSearcher.__init__cCsL|jr dS|jd}|_t|�d}|j�|dd�r:dS|j�||d�S)Nr;rJz.0z>=rWz lineend+1c)r�rrr�rBr�r�)r�rrr�rrr�readlines zIndentSearcher.readline)�class�def�for�if�try�whilec Cs>|jrn2||kr ||kr ||_n||kr:|jr:||_d|_dS)NrJ)r�r�r�) r�rA�token�startrWr��INDENT�NAMEZOPENERSrrr� tokeneater#szIndentSearcher.tokeneaterc Csltj}|jt_zHy(t�|j�}x|D]}|j|�q$WWntjtfk rRYnXWd|t_X|j|j fS)N) �tokenize�tabsizer��generate_tokensr�r�� TokenError� SyntaxErrorr�r�)r�Z save_tabsize�tokensr�rrrr�/s   zIndentSearcher.runN) r0r�r�r�r�r�r�r�r�r�rrrrr� s   r�cCs6|�d�}|dkr.|d|�||dd�}||fS)NrDrrJ)r()�srrrrrr�As r��[�]�/)Z bracketleftZ bracketrightZslashcCs�|�|�}|rt��r"|dkr"dS|d}t�ddd�|�}t�ddd�|�}t�d d|�}t�d d |�}t�d d |�}t�dd|�}t�dd|�}t�dd|�}t�dd|�}|S)N>�<>�<>� <>r;rz-[a-z]\bcSs |����S)N)r��upper)r�rrrrHZrIz!get_accelerator..z\b\w+\bcSst�|��|���S)N)�keynamesr�r�)r�rrrrH[rIzKey-ZCancelz Ctrl-BreakzControl-zCtrl-r��+z>zidlelib.idle_test.test_editorr9F)� verbosity�exit)r�)=Z importlib.abcr��importlib.utilr\r`r�r�rr�r�r ZtkinterZ tkinter.fontrZ tkinter.ttkrZtkinter.simpledialogZ simpledialogr�Ztkinter.messageboxZ messageboxr�Zidlelib.configrr1rrrr r Zidlelib.multicallr r r rrZ idlelib.treerrr�Zpython_versionryrr �objectr!r��compiler�r�r�r�r�rWr�r�r0Zunittestr>Zidlelib.idle_test.htestr�rrrr�sv                    X  4