a
    åzeÅ  ã                   @   sð  d dl Zd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlT d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d dlm$Z$ dZ%de &¡  Z'ejdkZ(dd„ Z)G dd„ dƒZ*dd„ Z+e ,d¡Z-dd „ Z.G d!d"„ d"ƒZ/d#d$„ Z0d%d&d'd(œZ1d)d*„ Z2d+d,„ Z3d-d.„ Z4e5d/krìd d0l6m7Z7 e7d1d2d3d4 d d5l8m9Z9 e9e4ƒ dS )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)Údarwinc                  C   sb   t j\} }}}}d| |f }|d|f 7 }|dkrB|d|f 7 }n|dkr^|d|d |f 7 }|S )zYFormat sys.version_info to produce the Sphinx version string used to install the chm docsz%s%sz%sÚ	candidatezrc%sÚfinalr   )ÚsysÚversion_info)ÚmajorÚminorÚmicroÚlevelÚserialÚrelease© r!   ú$/usr/lib/python3.9/idlelib/editor.pyÚ_sphinx_version&   s    r#   c                   @   s<  e Zd ZddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZmZ ddl m!Z! ddl"m#Z# ddl$m%Z% e& '¡ Z(dZ)dZ*dZ+dÙdd„Z,dÚdd„Z-dd„ Z.dd„ Z/dd„ Z0dd„ Z1dÛdd „Z2g d!¢Z3d"d#„ Z4d$d%„ Z5d&d'„ Z6d(d)„ Z7d*d+„ Z8dZ9d,d-„ Z:d.gZ;d/d0„ Z<d1d2„ Z=d3d4„ Z>d5d6„ Z?dÜd7d8„Z@dÝd9d:„ZAdÞd;d<„ZBdßd=d>„ZCd?d@„ ZDdAdB„ ZEdCdD„ ZFdàdEdF„ZGdádGdH„ZHdIdJ„ ZIdKdL„ ZJdMdN„ ZKdOdP„ ZLdQdR„ ZMdSdT„ ZNdUdV„ ZOdWdX„ ZPdYdZ„ ZQd[d\„ ZRd]d^„ ZSdâd_d`„ZTdãdadb„ZUdädcdd„ZVdedf„ ZWdgdh„ ZXdidj„ ZYdkdl„ ZZdmdn„ Z[dodp„ Z\dqdr„ Z]dsdt„ Z^e_j`e_ja du Zbdvdw„ Zcdxdy„ Zddzd{„ Zed|d}„ Zfd~d„ Zgd€d„ Zhd‚dƒ„ Zid„d…„ Zjdåd†d‡„Zkdˆd‰„ ZldŠd‹„ ZmdŒd„ ZndŽd„ Zodd‘„ Zpd’d“„ Zqd”d•„ Zrd–d—„ Zsdæd™dš„Ztd›dœ„ Zudçddž„ZvdŸd „ Zwd¡d¢„ Zxd£d¤„ Zyd¥d¦„ Zzd§d¨„ Z{d©dª„ Z|d«d¬„ Z}d­d®„ Z~d¯d°„ Zd±d²iZ€d³d´„ Zdè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Ì„ ZdÍdÎ„ ZŽdÏdÐ„ ZdÑdÒ„ ZdÓdÔ„ Z‘dÕdÖ„ Z’díd×dØ„Z“dS )îÚEditorWindowr   )Ú
Percolator)ÚColorDelegatorÚcolor_config)ÚUndoDelegator)Ú	IOBindingÚencoding)Úmainmenu)ÚMultiStatusBar)ÚAutoComplete)Ú
AutoExpand)ÚCalltip)ÚCodeContext)ÚLineNumbers)ÚFormatParagraphÚFormatRegionÚIndentsÚRstrip)Ú
ParenMatch)ÚSqueezer)Ú
ZoomHeightNTc                 C   sL	  ddl m} tjd u rtj tjdd¡}tj	 
d¡rvddtjd d…   }tj d	¡r^d
}qÌd}tj ||dd¡}nVtj	d d… dkr²tj tjddtƒ  ¡}	tj |	¡rÌ|	}ntj	dkrÌtj tjd¡}tj |¡}tj |¡r|t_tj	dkrdtj t_ndtjd d…  t_|| _|p*|j}|| _t|ƒ| _tj|| jd | _}
|rl|j| _|j| j_ni | _i | j_tjotj tjd¡| _d| _t|
ƒ | _ }t!|dd | _"}tj#ddddd}dddd|d tj#ddd!ddd"œ}t$t%ƒ|fi |¤Ž | _&}| j&| j_'|  (¡  |  )¡  | j *d#| j+¡ | j ,d$| j-¡ t. /¡ rx| ,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| jjX¡ | ,dS| jY¡ | ,dT| jZ¡ | ,dU| j[¡ |  \¡  |j]t^t_dMdV |j`dMdMdW |jadMdMdW | jb|dX< |jcdMdtddY |je|dZ< t f| jdd¡|d[< |jcdMdMtddY | g¡  |  h¡  tj#dd\d]d^d}| | _id_| _j| jj| _k|  l¡  tmtd`ƒsô| j&da t_n|  o¡  db| _p|  q|¡ | _r}|  s¡  | _t}| u|¡ |jv|_v|jw|_w| x| jy¡ |  z| ¡ | _{}| || j}¡ dc| _~|  dc¡ d | _€d | _d | _‚|rÞtj ƒ|¡rÎtj |¡sÎ| „|¡rÞdd| _~|  …|¡}|  |¡ n| †|¡ dd| _~|  ‡¡  |  y¡  |  ˆ¡  |  ‰¡  | jŠ ‹de¡}|rT| Œdf¡}|d u r(dg}|dkrB| ¡  |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| jj°¡ n|  ±d€dd‚¡ | j²	r:|  ³| ¡| _‚tj#dddƒd^d	r*|  ´¡  | ,d„| j´¡ n|  ±d€d…d‚¡ d S )†Nr   )ÚScriptBindingZ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/ÚwinzPython%s.chmr   z0Resources/English.lproj/Documentation/index.htmlzfile://zhttps://docs.python.org/%d.%d/é   )Úmenuzrecent-files.lstÚ Úvbar)ÚnameÚmainr$   ÚwidthÚint©ÚtypeÚtexté   ZnoneZwordprocessorÚheight)rA   ÚpadxÚwrapZhighlightthicknessrC   ZtabstylerI   ZWM_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>>c                 S   s   dS ©NÚbreakr!   ©Úeventr!   r!   r"   Ú<lambda>ª   ó    z'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)ZweightÚcommand)ÚrowÚcolumnZstickyZyscrollcommandÚfontÚIndentz
use-spacesÚboolr   Úblink_off_timeÚinsertofftime)é2   iô  i@KL FTr   Ú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Údisabledzline-numbers-defaultz<<toggle-line-numbers>>ú*ine*umbers)µZidlelib.runscriptr9   r$   Úhelp_urlÚosÚpathÚjoinr   Úbase_prefixÚplatformÚcountr   Úisdirr#   ÚisfileÚnormpathÚflistÚrootÚMenuÚmenubarr   ZListedToplevelÚtopÚvarsÚtkinter_varsZinversedictÚinstance_dictr   ZuserdirÚrecent_files_pathÚprompt_last_lineÚFrameÚ
text_framer   r@   Ú	GetOptionr   ÚTextrG   Zfocused_widgetÚcreatemenubarÚapply_bindingsÚprotocolÚcloseÚbindÚclose_eventr   ZisAquaTkÚ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_eventZdedent_region_eventZcomment_region_eventZuncomment_region_eventZtabify_region_eventZuntabify_region_eventr4   Ztoggle_tabs_eventZchange_indentwidth_eventÚmove_at_edge_if_selectionÚdel_word_leftÚdel_word_rightÚhome_callbackÚdictÚnew_callbackZclose_all_callbackÚopen_module_browserÚopen_path_browserÚopen_turtle_demoÚset_status_barÚpackZLEFTZBOTHZrowconfigureZcolumnconfigureÚhandle_yviewZgridZNSEWÚsetÚGetFontZ	focus_setÚ	set_widthÚusetabsÚtabwidthÚindentwidthÚset_notabs_indentwidthÚhasattrr`   Úupdate_cursor_blinkÚnum_context_linesr%   Úperr(   ÚundoÚinsertfilterÚundo_block_startÚundo_block_stopZset_saved_change_hookÚsaved_change_hookr)   ÚioZset_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_endZregister_callbackÚpostwindowsmenur   Z
askintegerr   ZaskyesnoÚ	showerrorÚ	event_addr-   Zautocomplete_eventZtry_open_completions_eventZforce_open_completions_eventr.   Zexpand_word_eventr2   Zformat_paragraph_eventr6   Zflash_paren_eventZparen_closed_eventZcheck_module_eventZrun_module_eventZrun_custom_eventr5   Z	do_rstripr/   ÚctipZtry_open_calltip_eventZrefresh_calltip_eventZforce_open_calltip_eventr8   Zzoom_height_eventÚallow_code_contextr0   Ztoggle_code_context_eventÚupdate_menu_stateÚallow_line_numbersr1   Útoggle_line_numbers_event)Úselfrr   ÚfilenameÚkeyrs   r9   ZdochomeZpyverZbasepathZchmfilerv   r}   r@   rC   Ztext_optionsrG   rœ   ÚindentsZ	usespacesr´   rµ   rº   Ú	is_py_srcr>   rc   ZautocompleteZ
parenmatchZscriptbindingrÎ   r!   r!   r"   Ú__init__I   sÀ   
ÿÿ

ÿÿ
ÿÿù







ÿ






ÿÿ
ÿÿ
ÿ
ÿÿzEditorWindow.__init__c                 C   s   |   ¡  d S ©N)r¬   ©rÓ   rQ   r!   r!   r"   r‡   a  s    zEditorWindow.handle_winconfigc                 C   s^   | j }tt|jj| d¡| d¡gƒƒ}| ¡ d|  }t|| d¡d d¡}|| | _	d S )NZborderrJ   r=   r]   )r]   Ú0)
rG   ÚsumÚmapÚtkZgetintZcgetZwinfo_widthr   ÚmeasurerC   )rÓ   rG   Zinner_paddingZpixel_widthZzero_char_widthr!   r!   r"   r¬   d  s    ÿÿzEditorWindow.set_widthc                 C   s   | j  ¡ \}}| j |¡ dS rN   )rº   Zdefaultfilenamerr   Únew)rÓ   rQ   ÚdirnameÚbasenamer!   r!   r"   r£   q  s    zEditorWindow.new_callbackc                 C   sÂ  |j d@ dkr|jdkrd S | j d¡rd| j ddd¡rd| j ddd¡rdt| j d¡ d¡d	 ƒ}n8| j dd¡}tt	|ƒƒD ]}|| d
vr~ qœq~t	|ƒ}t| j d¡ d¡d	 ƒ}||krÂd}dt
|ƒ d }|j d	@ dkrò| j ddd¡ n²| j d¡s| j dd¡ n@| j | j d¡d| j d¡¡rB| j dd¡ n| j dd¡ | j |¡}| j d¡}| j |d|¡r„|| }}| j ddd¡ | j d||¡ | j d|¡ | j d¡ dS )Né   r   ZHomeZiomarkú<=zinsert lineendúinsert linestartÚ.rV   )ú ú	Úinsertzinsert linestart+ÚcÚselú1.0rc   ú	sel.firstZ	my_anchorú<úsel.lastú>rO   )ÚstateZkeysymrG   rÈ   ÚcomparerD   ÚsplitrÇ   ÚrangeÚlenÚstrÚ
tag_removeÚmark_setÚtag_addÚsee)rÓ   rQ   ZinsertptÚlineZlineatÚdestÚfirstÚlastr!   r!   r"   r¡   v  sF    ÿþ
ÿ
zEditorWindow.home_callbackc                 C   s°   |   | j¡| _t| jdddd}tjdkr<| jjddtd | jjdd	td | jjd
dtd | jjt	t
d |jt	t
d | j d| j¡ | j ddd¡ | j | j¡ d S )NrV   Zgrey75)rI   ZborderwidthZ
backgroundr   Z	_padding1z    )rW   r\   zCol: ?rû   zLn: ?)rW   rX   z<<set-line-and-column>>z<KeyRelease>z<ButtonRelease>)r,   rv   Ú
status_barr|   r   rm   Ú	set_labelZRIGHTr¨   ZBOTTOMÚXrG   r„   Úset_line_and_columnrÍ   Z
after_idle)rÓ   Úsepr!   r!   r"   r§   ¡  s    
ÿzEditorWindow.set_status_barc                 C   s>   | j  t¡ d¡\}}| j dd| ¡ | j dd| ¡ d S )Nræ   r\   zCol: %srû   zLn: %s)rG   rÈ   ZINSERTró   rÿ   r   )rÓ   rQ   rû   r\   r!   r!   r"   r  ±  s    z EditorWindow.set_line_and_column))ÚfileZ_File)ÚeditZ_Edit)ÚformatZF_ormat)ÚrunZ_Run)re   Z_Options)r   Z_Window)r
   Z_Helpc                 C   sâ   | j }i  | _}| jD ]N\}}t|ƒ\}}t| |› dd ƒ}t||d|d ||< }|j|||d qt ¡ r’t|ddd |d< }|jd|d	 |  	¡  t| j dd
| _
| jd jddd| j
d | jd  t¡| _|  ¡  d S )NZ_menu_postcommandr   )rA   ÚtearoffÚpostcommand)Úlabelr>   Ú	underlineZapple)rA   r  ZapplicationZIDLE)r
  r>   ©r  r  r;   zRecent Files)r
  r  r>   r
   )ru   rÆ   Ú
menu_specsÚprepstrÚgetattrrt   Zadd_cascader   Z
isCarbonTkÚ
fill_menusÚrecent_files_menuZinsert_cascaderÈ   ÚENDÚbase_helpmenu_lengthÚreset_help_menu_entries)rÓ   ZmbarrÆ   rA   r
  r  r	  r>   r!   r!   r"   r€   Á  s,    
ÿÿþzEditorWindow.createmenubarc                 C   sJ   | j d }| d¡}|d u r d}|| jkr<| | jd |¡ t |¡ d S )Nr   rc   rd   rV   )rÆ   rÈ   rÊ   Údeleter   Zadd_windows_to_menu)rÓ   r>   rc   r!   r!   r"   rË   ×  s    


zEditorWindow.postwindowsmenuc                 C   s   | j | }|j||d dS )z$Update label for menu item at index.)r
  N©rÆ   Úentryconfig)rÓ   r>   rÈ   r
  Úmenuitemr!   r!   r"   Úupdate_menu_labelá  s    
zEditorWindow.update_menu_labelc                 C   s   | j | }|j||d dS )z$Update state for menu item at index.©rñ   Nr  )rÓ   r>   rÈ   rñ   r  r!   r!   r"   rÐ   æ  s    
zEditorWindow.update_menu_statec                 G   sT   |dkr<t |d ƒ}t|  d¡| ƒ|  d¡ }d}|df}| jj|g|¢R Ž  dS )zHandle scrollbar.Zmovetor   rc   ú@0,0ZscrollZunitsrO   )ÚfloatÚroundÚ	getlinenorG   Úyview)rÓ   rQ   ÚargsZfractionÚlinesr!   r!   r"   r©   ë  s    ÿzEditorWindow.handle_yviewc              	   C   s0  | j }| d|j› d|j› ¡}z | dd|¡o<| |dd¡}W n tyV   d}Y n0 |sv| ddd	¡ | d
|¡ | js„|  	¡  | j}|| _
tjd d… dk}|r²|jdd | jD ]N}z|\}}	}
W n tyà   Y q¸Y n0 |
d u rìq¸t| |
ƒƒ }|j||d q¸| |j|j¡ |r,| j jdd dS )Nú@ú,rí   rä   rï   Frë   rì   rc   ré   r;   r<   Zarrow)Zcursorr  ZibeamrO   )rG   rÈ   ÚxÚyrò   ÚTclErrorr÷   rø   ÚrmenuÚ
make_rmenurQ   r   rm   ZconfigÚrmenu_specsÚ
ValueErrorr  ZentryconfigureZtk_popupZx_rootZy_root)rÓ   rQ   rG   ZnewdexZin_selectionr'  ZiswinÚitemr
  Ú	eventnameZverify_staterñ   r!   r!   r"   r†   ø  s>    ÿ


zEditorWindow.right_menu_event)ÚCloserL   Nc                 C   sf   t | jdd}| jD ]F}|d |d  }}|d urR| j|fdd„}|j||d q| ¡  q|| _d S )Nr   r  rV   c                 S   s   |   |¡ d S rÙ   ©Úevent_generate©rG   r,  r!   r!   r"   rZ   %  s    z(EditorWindow.make_rmenu.<locals>.command©r
  rZ   )rt   rG   r)  Úadd_commandrÉ   r'  )rÓ   r'  r+  r
  r,  rZ   r!   r!   r"   r(     s    

zEditorWindow.make_rmenuc                 C   s   |   ¡ S rÙ   )Úrmenu_check_copy©rÓ   r!   r!   r"   Úrmenu_check_cut,  s    zEditorWindow.rmenu_check_cutc                 C   s6   z| j  d¡}W n ty$   Y dS 0 |r.dS dS d S )Nrí   rf   Únormal©rG   rÈ   r&  )rÓ   Zindxr!   r!   r"   r3  /  s
    zEditorWindow.rmenu_check_copyc                 C   s6   z| j j d| j d¡ W n ty,   Y dS 0 dS d S )Nztk::GetSelectionZ	CLIPBOARDrf   r6  )rG   rÞ   Úcallr&  r4  r!   r!   r"   Úrmenu_check_paste7  s
    zEditorWindow.rmenu_check_pastec                 C   s   t  | j¡ dS )zHandle Help 'About IDLE' event.rO   )r   ZAboutDialogrv   rÚ   r!   r!   r"   rŽ   ?  s    zEditorWindow.about_dialogc                 C   s   t  | jd¡ dS )z&Handle Options 'Configure IDLE' event.ZSettingsrO   )r   ZConfigDialogrv   rÚ   r!   r!   r"   r   E  s    zEditorWindow.config_dialogc                 C   s"   | j r| j }n| j}t |¡ dS )zHandle Help 'IDLE Help' event.rO   )rs   rv   r
   Zshow_idlehelp)rÓ   rQ   Úparentr!   r!   r"   rŒ   K  s
    
zEditorWindow.help_dialogc              
   C   sp   t jd d… dkr`zt | j¡ W ql ty\ } z"tjdt|ƒ| j	d W Y d }~qld }~0 0 nt
 | j¡ dS )Nr;   r<   úDocument Start Failure©ÚtitleÚmessager:  rO   )r   rm   ri   Ú	startfilerh   ÚOSErrorr   rÌ   rö   rG   Ú
webbrowserÚopen)rÓ   rQ   Úwhyr!   r!   r"   r   U  s    
ÿzEditorWindow.python_docsc                 C   s   | j  d¡ dS )Nz<<Cut>>rO   ©rG   r/  rÚ   r!   r!   r"   rˆ   `  s    zEditorWindow.cutc                 C   s    | j  d¡sd S | j  d¡ dS )Nrë   z<<Copy>>rO   )rG   Z
tag_rangesr/  rÚ   r!   r!   r"   r‰   d  s    zEditorWindow.copyc                 C   s   | j  d¡ | j  d¡ dS )Nz	<<Paste>>ré   rO   )rG   r/  rú   rÚ   r!   r!   r"   rŠ   k  s    zEditorWindow.pastec                 C   s.   | j  ddd¡ | j  dd¡ | j  d¡ dS )Nrë   rì   zend-1cré   rO   )rG   rù   rø   rú   rÚ   r!   r!   r"   r‘   p  s    zEditorWindow.select_allc                 C   s    | j  ddd¡ | j  d¡ dS )Nrë   rì   rc   ré   rO   )rG   r÷   rú   rÚ   r!   r!   r"   r’   v  s    zEditorWindow.remove_selectionc                    s*   | j j‰| j j‰d‰‡ ‡‡‡fdd„}|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-1cc                    s@   | j d@ dkr<zˆdƒ ˆdˆˆ  ƒ W n ty:   Y n0 d S )NrH   r   rí   ré   )rñ   r&  rP   ©Ú
edge_indexZedges_tableZself_text_indexZself_text_mark_setr!   r"   Úmove_at_edge†  s    z<EditorWindow.move_at_edge_if_selection.<locals>.move_at_edge)rG   rÈ   rø   )rÓ   rF  rG  r!   rE  r"   rž   {  s
    z&EditorWindow.move_at_edge_if_selectionc                 C   s   | j  d¡ dS )Nz<Meta-Delete>rO   rD  rÚ   r!   r!   r"   rŸ     s    zEditorWindow.del_word_leftc                 C   s   | j  d¡ dS )Nz<Meta-d>rO   rD  rÚ   r!   r!   r"   r    “  s    zEditorWindow.del_word_rightc                 C   s   t  | j¡ dS rN   )r   ÚfindrG   rÚ   r!   r!   r"   r“   —  s    zEditorWindow.find_eventc                 C   s   t  | j¡ dS rN   )r   Z
find_againrG   rÚ   r!   r!   r"   r”   ›  s    zEditorWindow.find_again_eventc                 C   s   t  | j¡ dS rN   )r   Zfind_selectionrG   rÚ   r!   r!   r"   r–   Ÿ  s    z!EditorWindow.find_selection_eventc                 C   s   t   | j| j| j¡ dS rN   )r	   rG   rº   rr   rÚ   r!   r!   r"   r•   £  s    z EditorWindow.find_in_files_eventc                 C   s   t   | j¡ dS rN   )r   rG   rÚ   r!   r!   r"   r—   §  s    zEditorWindow.replace_eventc                 C   sT   | j }t |dd¡j}|d urP| ddd¡ | d|› d¡ | d¡ |  ¡  dS )	Nz
Go To Linez/Enter a positive integer
('big' = end of file):rë   rì   rc   ré   ú.0rO   )rG   r   ZGotoÚresultr÷   rø   rú   r  )rÓ   rQ   rG   Úlinenor!   r!   r"   r˜   «  s    þ
zEditorWindow.goto_line_eventc                 C   sn   z| j  dd¡ ¡ }W n ty,   d}Y n0 t | j dd|¡j}|durj| jr^| 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.
        rí   rï   r?   zOpen ModulezAEnter the name of a Python module
to search on sys.path and open:N)rG   rÇ   Ústripr&  r   Z
ModuleNamerJ  rr   rB  rº   rÁ   )rÓ   rA   Ú	file_pathr!   r!   r"   Úopen_module¹  s    
üzEditorWindow.open_modulec                 C   s   |   ¡  dS rN   )rN  rÚ   r!   r!   r"   r   Ñ  s    zEditorWindow.open_module_eventc                 C   sJ   | j j}| jjdkr|s,|  ¡ }|d u r,dS ddlm} | | j|¡ dS )NZPyShellEditorWindowrO   r   )Úbrowser)	rº   rÔ   Ú	__class__Ú__name__rN  ÚidlelibrO  ZModuleBrowserrs   )rÓ   rQ   rÔ   rO  r!   r!   r"   r¤   Õ  s    ÿz EditorWindow.open_module_browserc                 C   s   ddl m} | | j¡ dS )Nr   )ÚpathbrowserrO   )rR  rS  ZPathBrowserrs   )rÓ   rQ   rS  r!   r!   r"   r¥   à  s    zEditorWindow.open_path_browserc                 C   s&   dd l }tjddg}|j|dd dS )Nr   z-cz,from turtledemo.__main__ import main; main()F)ÚshellrO   )Ú
subprocessr   Ú
executableÚPopen)rÓ   rQ   rU  Úcmdr!   r!   r"   r¦   å  s    þzEditorWindow.open_turtle_democ                 C   sN   |d urJ|dkrJ| j  dd| ¡ | j  ddd¡ | j  ddd¡ |  ¡  d S )Nr   ré   z%d.0rë   rì   rc   z
insert +1l)rG   rø   r÷   rù   Úcenter)rÓ   rK  r!   r!   r"   Úgotolineî  s
    zEditorWindow.gotolinec                 C   s`   |rt j |¡rdS t j t j |¡¡\}}t j |¡tv r@dS | j dd¡}| 	d¡o^d|v S )NTrì   z1.0 lineendz#!Zpython)
ri   rj   ro   Úsplitextrâ   Únormcaser   rG   rÇ   Ú
startswith)rÓ   rÔ   ÚbaseÚextrû   r!   r!   r"   rÂ   õ  s    zEditorWindow.ispythonsourcec                 C   s   | j r| j  | ¡ d | _ d S rÙ   )rr   Zunregister_maybe_terminater4  r!   r!   r"   Ú
close_hookþ  s    zEditorWindow.close_hookc                 C   s
   || _ d S rÙ   )r`  )rÓ   r`  r!   r!   r"   Úset_close_hook  s    zEditorWindow.set_close_hookc                 C   s2   | j r| j  | ¡ |  ¡  | j | ¡ |  ¡  d S rÙ   )rr   Zfilename_changed_editr¹   rv   Zupdate_windowlist_registryrÃ   r4  r!   r!   r"   r»     s
    z!EditorWindow.filename_change_hookc                 C   sV   | j r
d S |  | jj¡r"|  ¡ | _ | j rR| j | j¡ | j | j ¡ | j | j¡ d S rÙ   )	r½   rÂ   rº   rÔ   r&   r´   Úremovefilterrµ   r¶   r4  r!   r!   r"   Ú_addcolorizer  s    
zEditorWindow._addcolorizerc                 C   s,   | j s
d S | j  ¡  | j | j ¡ d | _ d S rÙ   )r½   Zremovecolorsr´   rb  r4  r!   r!   r"   Ú_rmcolorizer  s
    
zEditorWindow._rmcolorizerc                 C   sH   |   ¡  |  ¡  t | j¡ | jdur0| j ¡  | jdurD| j ¡  dS )zUpdate the color themeN)	rd  rc  r$   r'   rG   r¾   Zupdate_highlight_colorsr¿   Zupdate_colorsr4  r!   r!   r"   rÃ     s    


zEditorWindow.ResetColorizerÚ_c                 C   sp   |  d|¡ | |¡}|r6|| jv r6|  d|d |¡ d| |¡krR| d|¡ n| d|d ¡ | |¡ d S )NÚERRORz
 wordstartÚ
ré   z+1c)rù   rÇ   Ú
IDENTCHARSrø   rú   )rÓ   rG   ÚposÚcharr!   r!   r"   Úcolorize_syntax_error.  s    
z"EditorWindow.colorize_syntax_errorc                 C   s2   t jddddd}|s"d| jd< nt j| jd< dS )	z&Update the cursor blink configuration.rB   r$   zcursor-blinkr_   rE   r   ra   N)r   r~   rG   r`   )rÓ   Zcursorblinkr!   r!   r"   r²   9  s    ÿz EditorWindow.update_cursor_blinkc                 C   sN   | j dur| j  ¡  | jdur(| j ¡  t | jdd¡}|| jd< |  ¡  dS )z.Update the text widgets' font if it is changedNrB   r$   r]   )r¾   Zupdate_fontr¿   r   r«   rs   rG   r¬   )rÓ   Znew_fontr!   r!   r"   Ú	ResetFontC  s    




zEditorWindow.ResetFontc                 C   s|   t  ¡  | j_}| ¡ D ]\}}| jj|g|¢R Ž  q|  ¡ D ]8}t  |¡}|r>| ¡ D ]\}}| jj|g|¢R Ž  qXq>dS )z/Remove the keybindings before they are changed.N)	r   ÚGetCurrentKeySetr+   Údefault_keydefsÚitemsrG   Zevent_deleteÚget_standard_extension_namesÚGetExtensionBindings)rÓ   ÚkeydefsrQ   ÚkeylistÚextensionNameÚxkeydefsr!   r!   r"   ÚRemoveKeybindingsT  s    
zEditorWindow.RemoveKeybindingsc                 C   sB  t  ¡  | j_}|  ¡  |  ¡ D ]}t  |¡}|r |  |¡ q i }| jjD ]B}i ||d < |d D ](}|rb|d ||d  t|d ƒd < qbqJ| j	D ]¨}| j	| }| 
t¡}|du r¶q”|d7 }td|ƒD ]r}	| |	¡dkrÈ| |	d¡}
|
rÈ| |	d¡}d}||v r||| v r|| | }|rÈt||ƒ}
|j|	|
d qÈq”dS )	z-Update the keybindings after they are changedr   rV   NrZ   Úacceleratorr
  r?   )rw  )r   rm  r+   rn  r   rp  rq  Úmenudefsr  rÆ   rÈ   r  rô   rF   Z	entrycgetÚget_acceleratorr  )rÓ   rr  rt  ru  ZmenuEventDictr>   r+  ZmenubarItemrc   rÈ   ZaccelZitemNamerQ   r!   r!   r"   ÚApplyKeybindings`  s<    
$




zEditorWindow.ApplyKeybindingsc                 C   s   | j stjddddd| _dS )zCUpdate the indentwidth if changed and not using tabs in this windowrB   r^   z
num-spacesrD   rE   N)r­   r   r~   r¯   r4  r!   r!   r"   r°   „  s    
ÿz#EditorWindow.set_notabs_indentwidthc                 C   s|   t  ¡ }| jd }| t¡}|| jkr8| | jd |¡ |rn| ¡  |D ]$}|  |d ¡}|j	|d |d qH|| jd< dS )z3Update the additional help entries on the Help menur
   rV   r   r1  N)
r   ZGetAllExtraHelpSourcesListrÆ   rÈ   r  r  r  rÉ   Ú"_EditorWindow__extra_help_callbackr2  )rÓ   Z	help_listZhelpmenuZhelpmenu_lengthÚentryrX  r!   r!   r"   r  ‹  s    


z$EditorWindow.reset_help_menu_entriesc                    s   |f‡ fdd„	}|S )zCCreate a callback with the helpfile value frozen at definition timec              
      s‚   |   d¡stj | ¡} tjd d… dkrtzt | ¡ W q~ typ } z"tj	dt
|ƒˆ jd W Y d }~q~d }~0 0 n
t | ¡ d S )N)ZwwwÚhttpr;   r<   r;  r<  )r]  ri   rj   rq   r   rm   r?  r@  r   rÌ   rö   rG   rA  rB  )ÚhelpfilerC  r4  r!   r"   Údisplay_extra_helpž  s    

ÿz>EditorWindow.__extra_help_callback.<locals>.display_extra_helpr!   )rÓ   r~  r  r!   r4  r"   Z__extra_help_callbackœ  s    z"EditorWindow.__extra_help_callbackc              
      sæ  g }| j }|rRtj |¡rRt|dddd}| ¡ }W d  ƒ n1 sH0    Y  |r„tj |¡d }||v rx| |¡ | d|¡ g ‰ |D ]*}d|v s¬tj |dd	… ¡sŒˆ  	|¡ qŒ‡ fd
d„|D ƒ}d}|dt
|ƒ… }|r~z@t|dddd}| |¡ W d  ƒ n1 s0    Y  W nX ty| } z>t| jddƒshd| j_tjdd|› d| jd W Y d}~n
d}~0 0 | jjD ]Z}	|	j}
|
 dt¡ t|ƒD ]8\}}| ¡ }|	 |¡}|
j|| d | |dd q¤q†dS )z/Load and update the recent files list and menusÚrÚutf_8r   )r*   ÚerrorsNrg  r   ú rd   c                    s   g | ]}|ˆ vr|‘qS r!   r!   )Ú.0rj   ©Z	bad_pathsr!   r"   Ú
<listcomp>¾  rS   z9EditorWindow.update_recent_files_list.<locals>.<listcomp>Z1234567890ABCDEFGHIJKÚwÚrecentfiles_messageFTzIDLE Warningz)Cannot save Recent Files list to disk.
  z
Select OK to continue.r<  rç   )r
  rZ   r  )rz   ri   rj   rÀ   rB  Ú	readlinesÚabspathÚremoveré   Úappendrõ   Ú
writelinesr@  r  rs   rˆ  r   ÚshowwarningrG   rv   ry   r  r  r  Ú	enumerateÚrstripÚ#_EditorWindow__recent_file_callbackr2  )rÓ   Únew_fileZrf_listrM  Zrf_list_filerj   ZulcharsZrf_fileÚerrÚinstancer>   ÚiÚ	file_nameÚcallbackr!   r…  r"   rÄ   «  s\    ÿ&
ÿ.ÿü
þz%EditorWindow.update_recent_files_listc                    s   |f‡ fdd„	}|S )Nc                    s   ˆ j j| d d S )N)ZeditFile)rº   rB  )Z
fn_closurer4  r!   r"   Úopen_recent_fileÚ  s    z=EditorWindow.__recent_file_callback.<locals>.open_recent_filer!   )rÓ   r–  r˜  r!   r4  r"   Z__recent_file_callbackÙ  s    z#EditorWindow.__recent_file_callbackc                 C   s‚   |   ¡ }|  ¡ }|r*|r*|d | t }n|r4|}n|r>|}nd}|pL|pL|}|  ¡ sfd| }d| }| j |¡ | j |¡ d S )Nz - Úuntitledz*%s*z*%s)Úshort_titleÚ
long_titleÚ_py_versionÚ	get_savedrv   Zwm_titleZwm_iconname)rÓ   ZshortÚlongr=  Ziconr!   r!   r"   r¹   Þ  s    zEditorWindow.saved_change_hookc                 C   s
   | j  ¡ S rÙ   )rµ   r  r4  r!   r!   r"   r  ð  s    zEditorWindow.get_savedc                 C   s   | j  |¡ d S rÙ   )rµ   Ú	set_saved)rÓ   Úflagr!   r!   r"   rŸ  ó  s    zEditorWindow.set_savedc                 C   s   | j  ¡  d S rÙ   )rµ   Ú
reset_undor4  r!   r!   r"   r¡  ö  s    zEditorWindow.reset_undoc                 C   s   | j j}|rtj |¡S dS )Nr™  )rº   rÔ   ri   rj   râ   )rÓ   rÔ   r!   r!   r"   rš  ù  s    zEditorWindow.short_titlec                 C   s   | j jp
dS )Nr?   )rº   rÔ   r4  r!   r!   r"   r›  ý  s    zEditorWindow.long_titlec                 C   s   |   ¡  dS rN   )rY  rÚ   r!   r!   r"   r‹      s    z EditorWindow.center_insert_eventré   c                 C   sH   | j }|  ¡ \}}|  |¡}|| }td||d  ƒ}| t|ƒ¡ d S )NrV   r=   )rG   Úgetwindowlinesr  Úmaxr  r  )rÓ   ÚmarkrG   rv   ÚbotrK  rI   Znewtopr!   r!   r"   rY    s    
zEditorWindow.centerc                 C   sN   | j }|  d¡}|  d¡}||krF| ¡ dkrFt|d ƒ}|| d }||fS )Nr  z@0,65535rV   rI   )rG   r  Zwinfo_heightrD   )rÓ   rG   rv   r¥  rI   r!   r!   r"   r¢    s    

zEditorWindow.getwindowlinesc                 C   s   | j }tt| |¡ƒƒS rÙ   )rG   rD   r  rÈ   )rÓ   r¤  rG   r!   r!   r"   r    s    zEditorWindow.getlinenoc                 C   s(   | j  ¡ }t d|¡}ttt| ¡ ƒƒS )zReturn (width, height, x, y)z(\d+)x(\d+)\+(-?\d+)\+(-?\d+))rv   Zwm_geometryÚreÚmatchÚlistrÝ   rD   Úgroups)rÓ   ZgeomÚmr!   r!   r"   Úget_geometry  s    
zEditorWindow.get_geometryc                 C   s   |   ¡  dS rN   )rƒ   rÚ   r!   r!   r"   r…      s    zEditorWindow.close_eventc                 C   sH   | j rD|  ¡ s:| j ¡ dkr&| j ¡  | j ¡  | j ¡  | j  ¡ S d S )Nr6  )rº   r  rv   rñ   Z	deiconifyÚlowerZliftÚ	maybesaver4  r!   r!   r"   r­  $  s    


zEditorWindow.maybesavec                 C   s:   z"|   ¡ }t|ƒdkr|  ¡  |W S  ty4   Y n0 d S )NÚcancel)r­  rö   Ú_closeÚAttributeError)rÓ   Zreplyr!   r!   r"   rƒ   -  s    zEditorWindow.closec                 C   s   | j jr| j| j jd t | j¡ |  ¡  | j  ¡  d | _ d | _| j	rX| j	 ¡  d | _	d | _
d | _| j ¡  d | _| j ¡  | jrŒ|  ¡  d S )N)r’  )rº   rÔ   rÄ   r   Zunregister_callbackrË   Úunload_extensionsrƒ   rµ   r½   rG   rx   r´   rv   Zdestroyr`  r4  r!   r!   r"   r¯  6  s"    



zEditorWindow._closec                 C   s   i | _ |  ¡  d S rÙ   )Ú
extensionsÚload_standard_extensionsr4  r!   r!   r"   rÅ   J  s    zEditorWindow.load_extensionsc                 C   s0   t | j ¡ ƒD ]}t|dƒr| ¡  qi | _d S )Nrƒ   )r¨  r²  Úvaluesr±   rƒ   )rÓ   Úinsr!   r!   r"   r±  N  s    

zEditorWindow.unload_extensionsc                 C   sD   |   ¡ D ]6}z|  |¡ W q   tdt|ƒƒ t ¡  Y q0 qd S )NzFailed to load extension)rp  Úload_extensionÚprintÚreprÚ	tracebackÚ	print_exc)rÓ   rA   r!   r!   r"   r³  T  s    z%EditorWindow.load_standard_extensionsc                 C   s   t jddS )NT)Zeditor_only)r   ZGetExtensionsr4  r!   r!   r"   rp  \  s    z)EditorWindow.get_standard_extension_namesZZzDummyZzzdummyc           	   	   C   s6  | j  ||¡}z<ztjd| td}W n  ttfyF   t |¡}Y n0 W n tyh   td|ƒ ‚ Y n0 t||ƒ}t	 
|¡}t|dƒr–|  |j|¡ || ƒ}|| j|< |r2|  |¡ |D ]t}| dd¡}|d d… dkrê|dd … }qÌ|d	d … d
kr
|d d	… }qê|d }t||ƒr¼| j |t||ƒ¡ q¼d S )Nræ   )Úpackagez
Failed to import extension: rx  ú-re  rV   rî   rd   rð   Z_event)ÚextfilesrÇ   Ú	importlibÚimport_moduleÚ__package__ÚImportErrorÚ	TypeErrorr·  r  r   rq  r±   r  rx  r²  r   r   rG   r„   )	rÓ   rA   ZfnameÚmodÚclsrr  rµ  ZveventZ
methodnamer!   r!   r"   r¶  c  s4    






zEditorWindow.load_extensionc                 C   sH   |d u r| j j}| j}||_| ¡ D ]\}}|r$|j|g|¢R Ž  q$d S rÙ   )r+   rn  rG   rr  ro  rÍ   )rÓ   rr  rG   rQ   rs  r!   r!   r"   r     s    zEditorWindow.apply_bindingsc              	   C   sê   |du r| j j}|du r | j j}| j}| j}|D ]´\}}| |¡}|sHq0|D ]–}|s^| ¡  qL|\}	}
|	dd… dk}|r†|	dd… }	t|	ƒ\}}	t||
ƒ}||
fdd„}|rÐ|  	|
t
¡}|j|	||||d qL|j|	|||d qLq0dS )zAdd appropriate entries to the menus and submenus

        Menus that are absent or None in self.menudict are ignored.
        NrV   ú!c                 S   s   |   |¡ d S rÙ   r.  r0  r!   r!   r"   rZ   ¡  s    z(EditorWindow.fill_menus.<locals>.command)r
  r  rZ   rw  Úvariable)r
  r  rZ   rw  )r+   rx  rn  rÆ   rG   rÇ   rÉ   r  ry  Úget_var_objZ
BooleanVarZadd_checkbuttonr2  )rÓ   rx  rr  rÆ   rG   ZmnameZ	entrylistr>   r|  r
  r,  Zcheckbuttonr  rw  rZ   Úvarr!   r!   r"   r  ˆ  s<    


þþzEditorWindow.fill_menusc                 C   s&   |   |¡}|r| ¡ }|S t|ƒ‚d S rÙ   )rÇ  rÇ   Ú	NameError)rÓ   rA   rÈ  Úvaluer!   r!   r"   Úgetvar­  s
    
zEditorWindow.getvarc                 C   s(   |   ||¡}|r| |¡ nt|ƒ‚d S rÙ   )rÇ  rª   rÉ  )rÓ   rA   rÊ  ÚvartyperÈ  r!   r!   r"   Úsetvarµ  s    zEditorWindow.setvarc                 C   s,   | j  |¡}|s(|r(|| jƒ | j |< }|S rÙ   )rx   rÇ   rG   )rÓ   rA   rÌ  rÈ  r!   r!   r"   rÇ  ¼  s    zEditorWindow.get_var_objc                 C   s,   | j r$| j d|¡p"d| j |¡v S dS d S )NZTODOÚSTRINGrV   )r½   rG   Útag_prevrangeZ	tag_names)rÓ   Z
text_indexr!   r!   r"   Úis_char_in_stringÌ  s
    ÿzEditorWindow.is_char_in_stringc                 C   s<   z"| j  d¡}| j  d¡}||fW S  ty6   Y dS 0 d S )Nrí   rï   )NNr7  )rÓ   rý   rþ   r!   r!   r"   Úget_selection_indicesØ  s    
z"EditorWindow.get_selection_indicesc                 C   s   | j d pt}t|ƒS )NÚtabs)rG   ÚTK_TABWIDTH_DEFAULTrD   )rÓ   Úcurrentr!   r!   r"   Úget_tk_tabwidthã  s    zEditorWindow.get_tk_tabwidthc              	   C   sB   | j }|  ¡ |kr>|j dd|d d|jd| ¡}|j|d d S )Nr]   rß   z
-displayofÚn)rÒ  )rG   rÕ  rÞ   r8  ZmasterZ	configure)rÓ   ZnewtabwidthrG   Zpixelsr!   r!   r"   Úset_tk_tabwidthé  s    þzEditorWindow.set_tk_tabwidthc                 C   sP   |r@|r@|   ¡ }d|  kr$dkr.n n|| _| j| jkr@d| _|  | j¡ d S )Nr=   r   F)Úguess_indentr¯   r®   r­   r×  )rÓ   r×   Zguessr•  r!   r!   r"   r¼   ô  s    z#EditorWindow.set_indentation_paramsc           
      C   s>  | j }|  ¡ \}}|r6|r6| ||¡ | d|¡ dS | dd¡}|dkrp| ddd¡rd| d¡ n| ¡  dS |d d	vrŠ| d¡ dS | j}t| 	|¡ƒ}|d
 | j
 | j
 }d}	|| jkrÂqü|d d… }|	d
 }	t| 	|¡ƒ}||ksü|d d	vr¶qüq¶| ¡  | d|	 d¡ ||k r2| dd||  ¡ | ¡  dS )Nré   rO   rå   r?   rð   rì   z	insert-1crd   ú 	rV   r   z
insert-%dcrç   )rG   rÑ  r  rø   rÇ   rò   Zbellr®   rõ   Ú
expandtabsr¯   r{   r·   ré   r¸   )
rÓ   rQ   rG   rý   rþ   Úcharsr®   ZhaveZwantZncharsdeletedr!   r!   r"   r™   ý  s@    


z"EditorWindow.smart_backspace_eventc           
      C   s   | j }|  ¡ \}}| ¡  zÖ|rb|rbt|ƒt|ƒkrJ| j |¡W | ¡  S | ||¡ | d|¡ | 	dd¡}t
|| jƒ\}}|t|ƒkrœ|  || j ¡ n>| jr¨d}n&t| | j¡ƒ}| j}	d|	||	   }| d|¡ | d¡ W | ¡  dS | ¡  0 d S )Nré   rå   rè   rç   rO   )rG   rÑ  r·   Ú
index2linerœ   r   r¸   r  rø   rÇ   Úget_line_indentr®   rõ   Úreindent_tor¯   r­   rÚ  ré   rú   )
rÓ   rQ   rG   rý   rþ   ÚprefixÚrawZ	effectiveZpadrÖ  r!   r!   r"   r›   )  s4    ì
þzEditorWindow.smart_indent_eventc              	   C   s  | j }|  ¡ \}}| ¡  zä|r>|r>| ||¡ | d|¡ | dd¡}dt|ƒ }}||k rv|| dv rv|d7 }qX||kr¢| dd¡ W | d¡ | 	¡  dS |d|… }d}|râ|d	 dv râ|| j
krâ|dd	… }|d7 }q²|rö| d
| d¡ | d¡dv r| d¡ qö| dd¡ t| d¡ƒ}	t | j| j¡}
| j
s¾| jD ]`}t|	| dƒ}t|ƒd }| |d¡}|
 |¡ |
 |  |¡¡}|dus¢|dkrJ q¬qJ|
 |p¸d¡ n@| dd¡}|rÚ|d }nd}| |d¡}|
 |¡ |
 d¡ |
 ¡ }|tjkr¦|tjkr nn|tjkr:| d|¡ nT|tjkrV|  |
 ¡ ¡ n8|tj krŽ|
 !¡ dkr~| d|¡ n|  |
 "¡ ¡ n W | d¡ | 	¡  dS |
 #¡ }| d|¡ |
 $¡ rÐ|  %|¡ n|rê|
 &¡ rê|  '|¡ W | d¡ | 	¡  dS | d¡ | 	¡  0 dS )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å   r   rÙ  rV   rg  rO   Nrd   zinsert - %d charsrI  Zconsolerì   )(rG   rÑ  r·   r  rø   rÇ   rõ   ré   rú   r¸   r{   rÜ  rÈ   r   ZParserr¯   r®   r³   r£  r¸  Zset_codeZfind_good_parse_startÚ_build_char_in_string_funcZset_lorÏ  Zget_continuation_typeZC_NONEZC_STRING_FIRST_LINEZC_STRING_NEXT_LINESZ	C_BRACKETrÞ  Zcompute_bracket_indentZC_BACKSLASHZget_num_lines_in_stmtZcompute_backslash_indentZget_base_indent_stringZis_block_openerr›   Zis_block_closerr™   )rÓ   rQ   rG   rý   rþ   rû   r•  rÖ  ÚindentÚlnor%  ÚcontextZstartatZstartatindexZrawtextZbodr€  rê   r!   r!   r"   rš   L  sœ    	
T
«


ÿ




ò


ý  ÿ
z%EditorWindow.newline_and_indent_eventc                 C   s   || j fdd„}|S )Nc                 S   s   ||d|   ƒS )Nz+%dcr!   )ÚoffsetZ_startindexZ_icisr!   r!   r"   ÚinnerÃ  s    z6EditorWindow._build_char_in_string_func.<locals>.inner)rÐ  )rÓ   Z
startindexræ  r!   r!   r"   rá  Â  s    ÿ
z'EditorWindow._build_char_in_string_funcc                 C   s2   | j r&t|| jƒ\}}d| d|  S d| S d S )Nrè   rç   )r­   Údivmodr®   )rÓ   rÖ  ZntabsZnspacesr!   r!   r"   Ú_make_blanksÒ  s    zEditorWindow._make_blanksc                 C   sJ   | j }| ¡  | ddd¡r(| dd¡ |r>| d|  |¡¡ | ¡  d S )Nrå   z!=ré   )rG   r·   rò   r  ré   rè  r¸   )rÓ   r\   rG   r!   r!   r"   rÞ  Ü  s    zEditorWindow.reindent_toc                 C   sP   t | j| jƒ ¡ \}}|r@|r@t|| jƒ\}}t|| jƒ\}}nd }}|| S ©Nr   )ÚIndentSearcherrG   r®   r  rÝ  )rÓ   ÚopenerZindentedrà  ZindentsmallZindentlarger!   r!   r"   rØ  ê  s    zEditorWindow.guess_indentc                 C   sN   | j d u rd S | j jr&| j  ¡  d}n| j  ¡  d}| jdd|› dd d S )NZShowZHidere   rg   z Line Numbers)r>   rÈ   r
  )r¿   Zis_shownZhide_sidebarZshow_sidebarr  )rÓ   rQ   Z
menu_labelr!   r!   r"   rÒ   ó  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)”rQ  Ú
__module__Ú__qualname__Zidlelib.percolatorr%   Zidlelib.colorizerr&   r'   Zidlelib.undor(   Zidlelib.iomenur)   r*   rR  r+   Zidlelib.statusbarr,   Zidlelib.autocompleter-   Zidlelib.autoexpandr.   Zidlelib.calltipr/   Zidlelib.codecontextr0   Zidlelib.sidebarr1   Zidlelib.formatr2   r3   r4   r5   Zidlelib.parenmatchr6   Zidlelib.squeezerr7   Zidlelib.zoomheightr8   r   ÚgetfilesystemencodingZfilesystemencodingrh   rÏ   rÑ   rØ   r‡   r¬   r£   r¡   r§   r  r  r€   rË   r  rÐ   r©   r'  r†   r)  r(  r5  r3  r9  rŽ   r   rŒ   r   rˆ   r‰   rŠ   r‘   r’   rž   rŸ   r    r“   r”   r–   r•   r—   r˜   rN  r   r¤   r¥   r¦   rZ  rÂ   r`  ra  r»   rc  rd  rÃ   ÚstringÚascii_lettersÚdigitsrh  rk  r²   rl  rv  rz  r°   r  r{  rÄ   r‘  r¹   r  rŸ  r¡  rš  r›  r‹   rY  r¢  r  r«  r…   r­  rƒ   r¯  rÅ   r±  r³  rp  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$   2   sø   
  
+

%þ









		
$
.


		ÿ
	
%


	,#v
	r$   c                 C   s   t t| ƒƒS rÙ   )rD   r  )rÈ   r!   r!   r"   rÜ    s    rÜ  z[ \t]*c                 C   s$   t  | ¡}| ¡ t| ¡  |¡ƒfS )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§  rc   rõ   ÚgrouprÚ  )rû   r®   rª  r!   r!   r"   rÝ    s    
rÝ  c                   @   s8   e Zd Zdd„ Zdd„ Zejejdfdd„Zdd	„ Z	d
S )rê  c                 C   s(   || _ || _d | _| _d  | _| _d S ré  )rG   r®   r•  ÚfinishedÚblkopenlineÚindentedline)rÓ   rG   r®   r!   r!   r"   rØ     s    zIndentSearcher.__init__c                 C   sL   | j r
dS | jd  }| _t|ƒd }| j |dd¡r:dS | j ||d ¡S )Nr?   rV   rI  z>=rc   z lineend+1c)rô  r•  r¸  rG   rò   rÇ   )rÓ   r•  r¤  r!   r!   r"   Úreadline  s    zIndentSearcher.readline)ÚclassÚdefÚforÚifÚtryÚwhilec	           	      C   s>   | j rn2||kr ||v r || _n||kr:| jr:|| _d| _ d S )NrV   )rô  rõ  rö  )	rÓ   rF   ÚtokenÚstartrc   rû   ÚINDENTÚNAMEZOPENERSr!   r!   r"   Ú
tokeneater&  s    zIndentSearcher.tokeneaterc              	   C   sl   t j}| jt _zHz$t  | j¡}|D ]}| j|Ž  q"W n t jtfyL   Y n0 W |t _n|t _0 | j| j	fS rÙ   )
ÚtokenizeÚtabsizer®   Úgenerate_tokensr÷  r  Ú
TokenErrorÚSyntaxErrorrõ  rö  )rÓ   Zsave_tabsizeÚtokensrþ  r!   r!   r"   r  2  s    zIndentSearcher.runN)
rQ  rì  rí  rØ   r÷  r  r   r  r  r  r!   r!   r!   r"   rê    s   
ý
rê  c                 C   s6   |   d¡}|dkr.| d |… | |d d …  } || fS )Nre  r   rV   )rH  )Úsr•  r!   r!   r"   r  D  s    
r  ú[ú]ú/)ZbracketleftZbracketrightZslashc                 C   s´   |   |¡}|rt ¡ r"|dv r"dS |d }t ddd„ |¡}t ddd„ |¡}t d	d|¡}t d
d|¡}t dd|¡}t dd|¡}t dd|¡}t dd|¡}t dd|¡}|S )N>   rT   rM   rU   r?   r   z-[a-z]\bc                 S   s   |   ¡  ¡ S rÙ   )ró  Úupper©rª  r!   r!   r"   rR   ]  rS   z!get_accelerator.<locals>.<lambda>z\b\w+\bc                 S   s   t  |  ¡ |  ¡ ¡S rÙ   )ÚkeynamesrÇ   ró  r  r!   r!   r"   rR   ^  rS   zKey-ZCancelz
Ctrl-BreakzControl-zCtrl-r¼  ú+z><rç   rî   rð   )rÇ   r   Z	isCocoaTkr¦  Úsub)rr  r,  rs  r	  r!   r!   r"   ry  S  s    
ry  c                 C   s4   | j }| ddd¡ | ddd¡ | ddd¡ d S )	NZtcl_wordBreakAfterza br   rª   Ztcl_wordcharsz\wZtcl_nonwordcharsz\W)rÞ   r8  )rs   rÞ   r!   r!   r"   Úfixwordbreaksi  s    r  c                 C   s~   | }t |ƒ tjdd … r&tjd }nd }t |d ¡ t||d}|j}d|d< tdƒD ] }| dd| t	|ƒ d ¡ qXd S )	NrV   )rs   rÔ   é
   rI   é   ré   z  rg  )
r  r   Úargvr   ZsetupAppr$   rG   rô   ré   rö   )r:  rs   rÔ   r  rG   r•  r!   r!   r"   Ú_editor_windowr  s    r  Ú__main__)rB   zidlelib.idle_test.test_editorr=   F)Ú	verbosityÚexit)r  ):Úimportlib.abcr¾  Úimportlib.utilri   rm   r¦  rï  r   r  r¹  rA  ÚtkinterZtkinter.fontr   Ztkinter.ttkr   r   r   Zidlelib.configr   rR  r   r	   r
   r   r   Zidlelib.multicallr   r   r   r   r   Zidlelib.treer   Zidlelib.utilr   r   rÓ  Zpython_versionrœ  r   r#   r$   rÜ  Úcompilerò  rÝ  rê  r  r  ry  r  r  rQ  ZunittestrB   Zidlelib.idle_test.htestr  r!   r!   r!   r"   Ú<module>   sz   
           Z

4
ý	
