B
    v9a ã               @   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	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Z!de "¡  Z#e$jdkZ%dd„ Z&G dd„ de'ƒZ(dd„ Z)dd„ Z*G dd„ de'ƒZ+dd„ Z,dd d!d"œZ-d#d$„ Z.d%d&„ Z/d'd(„ Z0e1d)kr²d d*l2m3Z3 e3d+d,d-d. d d/l4m5Z5 e5e0ƒ dS )0é    N)Ú*)Ú	Scrollbar)ÚidleConf)Úconfigdialog)Úgrep)Úhelp)Ú
help_about)Úmacosx)ÚMultiCallCreator)Úpyparse)Úquery)Úreplace)Úsearch)Ú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 )Nz%s%sz%sÚ	candidatezrc%sÚfinalr   )ÚsysÚversion_info)ÚmajorÚminorÚmicroÚlevelÚserialÚrelease© r   ú/usr/lib/python3.7/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 ddlmZ ddlm Z  ddl!m"Z" e# $¡ Z%dZ&dñdd„Z'dd„ Z(dd„ Z)dd„ Z*dd„ Z+dòdd„Z,ddd d!d"d#d$gZ-d%d&„ Z.d'd(„ Z/d)d*„ Z0d+d,„ Z1d-d.„ Z2d/d0„ Z3dZ4d1d2„ Z5d3gZ6d4d5„ Z7d6d7„ Z8d8d9„ Z9d:d;„ Z:dód<d=„Z;dôd>d?„Z<dõd@dA„Z=dödBdC„Z>dDdE„ Z?dFdG„ Z@dHdI„ ZAd÷dJdK„ZBdødLdM„ZCdNdO„ ZDdPdQ„ ZEdRdS„ ZFdTdU„ ZGdVdW„ ZHdXdY„ ZIdZd[„ ZJd\d]„ ZKd^d_„ ZLd`da„ ZMdbdc„ ZNdùddde„ZOdúdfdg„ZPdûdhdi„ZQdjdk„ ZRdldm„ ZSdndo„ ZTdpdq„ ZUdrds„ ZVdtdu„ ZWdvdw„ ZXdxdy„ ZYeZj[eZj\ dz Z]d{d|„ Z^d}d~„ Z_dd€„ Z`dd‚„ Zadƒd„„ Zbd…d†„ Zcd‡dˆ„ Zddüd‰dŠ„Zed‹dŒ„ ZfddŽ„ Zgdd„ Zhd‘d’„ Zid“d”„ Zjd•d–„ Zkd—d˜„ Zld™dš„ Zmdýdœd„ZndždŸ„ Zodþd d¡„Zpd¢d£„ Zqd¤d¥„ Zrd¦d§„ Zsd¨d©„ Ztdªd«„ Zud¬d­„ Zvd®d¯„ Zwd°d±„ Zxd²d³„ Zyd´dµiZzd¶d·„ Z{dÿd¸d¹„Z|d dºd»„Z}d¼d½„ Z~dd¾d¿„ZddÀdÁ„Z€dÂdÃ„ ZdÄ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Ü„ ZdÝdÞ„ ZŽdßdà„ Zdádâ„ Zdãdä„ Z‘dådæ„ Z’dçdè„ Z“dédê„ Z”dëdì„ Z•dídî„ Z–dïdð„ Z—dS (  ÚEditorWindowr   )Ú
Percolator)ÚColorDelegatorÚcolor_config)ÚUndoDelegator)Ú	IOBindingÚencoding)Úmainmenu)ÚMultiStatusBar)ÚAutoComplete)Ú
AutoExpand)ÚCalltip)ÚCodeContext)ÚFormatParagraph)Ú
ParenMatch)ÚRstrip)ÚSqueezer)Ú
ZoomHeightNc             C   s\  ddl m} tjd k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 tjd¡| _d| _t|
ƒ | _ }t!|dd | _"}tj#ddddd| _$dddd| j$d tj#ddd!ddd"œ}t%t&ƒ|f|Ž | _'}| j'| j_(|  )¡  |  *¡  | j +d#| j,¡ | j -d$| j.¡ t/ 0¡ rp| -d$| j.¡ | -d%| j1¡ | -d&| j1¡ n| -d'| j1¡ | -d(| j2¡ | -d)| j2¡ | -d*| j2¡ | -d+| j3¡ | -d,| j4¡ | -d-| j5¡ | -d.| j6¡ | -d/| j7¡ | -d0| j8¡ | -d1| j9¡ | -d2| j:¡ | -d3| j;¡ | -d4d5d6„ ¡ | -d7| j<¡ | -d8| j=¡ | -d9| j>¡ | -d:| j?¡ | -d;| j@¡ | -d<| jA¡ | -d=| jB¡ | -d>| jC¡ | -d?| jD¡ | -d@| jE¡ | -dA| jF¡ | -dB| jG¡ | -dC| jH¡ | -dD| jI¡ | -dE| jJ¡ | -dF| jK¡ | -dG| jL¡ | -dH| jM¡ | -dI| jN¡ | -dJ|  Od¡¡ | -dK|  OdL¡¡ | -dM| jP¡ | -dN| jQ¡ | -dO| jR¡ |rö||j| < |r®| |jS|< | -dP| jT¡ | -dQ| jjU¡ | -dR| jV¡ | -dS| jW¡ | -dT| jX¡ |  Y¡  | jZ|dU< |j[t\t]dV |j^|dW< t _| jdd¡|dX< |j[t`tadLdY |j[tbtadLdY | c¡  tj#ddZd[d\d}| | _dd]| _e| je| _f|  g¡  d^| _h|  i|¡ | _j}|  k¡  | _l}| m|¡ |jn|_n|jo|_o| p| jq¡ |  r| ¡ | _s}| t| ju¡ d_| _v|  wd_¡ d | _x|rbtj y|¡rRtj |¡sR| z|¡rbd`| _v|  {|¡}|  w|¡ n| ||¡ d`| _v|  }¡  |  q¡  |  ~¡  |  ¡  | j€ da¡}|rØ| ‚db¡}|d kr¬dc}|dkrÆ| ƒ¡  |dL }|| _„t …| j†¡ t‡jˆ| _ˆt‰jŠ| _Št‡j‹| _‹| Œddde¡ | Œdfdgdhdi¡ | Œdjdk¡ | Œdldm¡ | Œdndmdodp¡ |  | ¡}| -dd|jŽ¡ | -df|j¡ | -dq|j¡ | -dr|  ‘| ¡j’¡ | -ds|  “| ¡j”¡ |  •| ¡}| -dt|j–¡ | -dn|j—¡ || ƒ}| -du|j˜¡ | -dv|j™¡ | -dw|jš¡ | -dx|  ›| ¡jœ¡ |  | ¡}| -dj|jž¡ | -dl|jŸ¡ | -dy|j ¡ | -dz|  ¡| ¡j¢¡ | -d{|  £| ¡j¤¡ d S )|Nr   )ÚScriptBindingZDocz
index.htmlZ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)r8   ZpadxÚwrapZhighlightthicknessr:   Ztabstyler?   ZWM_DELETE_WINDOWz<<close-window>>z<Control-Button-1>z<2>z<3>z<MouseWheel>z
<Button-4>z
<Button-5>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>>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>>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ÚfillZyscrollcommandÚfont)rG   rH   ÚexpandÚIndentz
use-spacesÚboolr   )é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>>)¥Zidlelib.runscriptr1   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   r7   Ú	GetOptionr:   r
   ZTextr=   Zfocused_widgetÚcreatemenubarÚapply_bindingsZprotocolÚcloseÚbindÚclose_eventr	   ZisAquaTkÚright_menu_eventÚmousescrollÚ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_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_callbackZclose_all_callbackÚopen_module_browserÚopen_path_browserÚopen_turtle_demoÚset_status_barÚhandle_yviewÚpackÚRIGHTÚYÚsetÚGetFontZLEFTZBOTHZTOPZ	focus_setÚusetabsÚtabwidthÚindentwidthÚset_notabs_indentwidthÚ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ÚexistsÚloadfileÚispythonsourceZset_filenameÚResetColorizerÚupdate_recent_files_listÚload_extensionsÚmenudictÚgetÚindexÚadd_separatorÚ	wmenu_endZregister_callbackÚpostwindowsmenuÚtkMessageBoxÚaskyesnoÚtkSimpleDialogÚ
askintegerÚ	showerrorÚ	event_addr(   Zautocomplete_eventZtry_open_completions_eventZforce_open_completions_eventr)   Zexpand_word_eventr,   Zformat_paragraph_eventr-   Zflash_paren_eventZparen_closed_eventZcheck_module_eventZrun_module_eventZrun_custom_eventr.   Z	do_rstripr*   Ztry_open_calltip_eventZrefresh_calltip_eventZforce_open_calltip_eventr0   Zzoom_height_eventr+   Ztoggle_code_context_event)ÚselfrZ   ÚfilenameÚkeyr[   r1   ZdochomeZpyverZbasepathZchmfiler^   re   r7   Ztext_optionsr=   Z	usespacesrŸ   r    r¥   Ú	is_py_srcr5   rN   ZautocompleteZ
parenmatchZscriptbindingZctipr   r   r   Ú__init__A   sz   





















zEditorWindow.__init__c             C   sn   t |tƒr`y| | j¡}W nD tk
r^   y| | j¡}W n tk
rX   | d¡}Y nX Y nX t dd|¡S )Nz	iso8859-1u   [ð€€-ô¿¿]u   ï¿½)Ú
isinstanceÚbytesÚdecodeÚfilesystemencodingÚUnicodeDecodeErrorr%   ÚreÚsub)r»   r¼   r   r   r   Ú_filename_to_unicode>  s    
z!EditorWindow._filename_to_unicodec             C   s   | j  ¡ \}}| j |¡ dS )NrA   )r¥   ZdefaultfilenamerZ   Únew)r»   rB   ÚdirnameÚbasenamer   r   r   r   M  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	 ƒ}n:| j dd¡}x*tt	|ƒƒD ]}|| d
kr€P q€W 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¡¡rD| 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iomarkz<=zinsert lineendzinsert linestartÚ.rE   )ú ú	Úinsertzinsert linestart+ÚcÚselz1.0rN   z	sel.firstZ	my_anchorú<zsel.lastú>rA   )ÚstateZkeysymr=   r±   Úcomparer;   Úsplitr°   ÚrangeÚlenÚstrÚ
tag_removeÚmark_setÚtag_addÚsee)r»   rB   ZinsertptÚlineZlineatÚdestÚfirstÚlastr   r   r   r   R  s@    
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 )NrE   Zgrey75)r?   ZborderwidthZ
backgroundr   Z	_padding1z    )rG   ÚcolumnzCol: ?rÞ   zLn: ?)rG   rH   z<<set-line-and-column>>z<KeyRelease>z<ButtonRelease>)r'   r^   Ú
status_barrd   r   rU   Ú	set_labelr–   r•   ZBOTTOMÚXr=   rj   Ú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)r=   r±   ZINSERTrÖ   rã   rä   )r»   rB   rÞ   râ   r   r   r   ræ     s    z EditorWindow.set_line_and_column)ÚfileZ_File)ÚeditZ_Edit)ÚformatZF_ormat)ÚrunZ_Run)ÚoptionsZ_Options)r   Z_Window)r   Z_Helpc             C   sÒ   | j }i  | _}xD| jD ]:\}}t|ƒ\}}t||dd ||< }|j|||d qW 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 )Nr   )r8   Útearoff)Úlabelr5   Ú	underlineZappleZapplicationZIDLE)rî   r5   )rí   rè   r2   zRecent Files)rî   rï   r5   r   )r]   r¯   Ú
menu_specsÚprepstrr\   Zadd_cascader	   Z
isCarbonTkÚ
fill_menusÚrecent_files_menuZinsert_cascader±   ÚENDÚbase_helpmenu_lengthÚreset_help_menu_entries)r»   Zmbarr¯   r8   rî   rï   r5   r   r   r   rg     s"    

zEditorWindow.createmenubarc             C   sJ   | j d }| d¡}|d kr d}|| jkr<| | jd |¡ t |¡ d S )Nr   rN   rO   rE   )r¯   r±   r³   Údeleter   Zadd_windows_to_menu)r»   r5   rN   r   r   r   r´   ±  s    


zEditorWindow.postwindowsmenuc             C   s   | j | }|j||d d S )N)rî   )r¯   Úentryconfig)r»   r5   r±   rî   Úmenuitemr   r   r   Úupdate_menu_label»  s    
zEditorWindow.update_menu_labelc             C   s   | j | }|j||d d S )N)rÔ   )r¯   rø   )r»   r5   r±   rÔ   rù   r   r   r   Úupdate_menu_stateÀ  s    
zEditorWindow.update_menu_statec             G   sR   |dkr<t |d ƒ}t|  d¡| ƒ|  d¡ }d}|df}| jj|f|žŽ  dS )NZmovetor   rN   z@0,0ZscrollÚunitsrA   )ÚfloatÚroundÚ	getlinenor=   Úyview)r»   rB   ÚargsZfractionÚlinesr   r   r   r”   Å  s    zEditorWindow.handle_yviewc             C   s@   t j|jdkt j|jdki}||j r*dnd}| j |d¡ dS )Nr   rË   éûÿÿÿr>   rü   rA   )Z	EventTypeZ
MouseWheelZdeltaZButtonZnumr<   r=   Zyview_scroll)r»   rB   Zupr  r   r   r   rm   Ð  s
    zEditorWindow.mousescrollc       	   	   C   sØ   | j  dd|j|jf ¡ | js(|  ¡  | j}|| _tjd d… dk}|rX| j j	dd xX| j
D ]N}y|\}}}W n tk
rˆ   w`Y nX |d kr”q`t| |ƒƒ }|j||d q`W | |j|j¡ |rÔ| j j	dd d	S )
NrÏ   z@%d,%dr2   r3   Zarrow)Zcursor)rÔ   ZibeamrA   )r=   rÛ   ÚxÚyÚrmenuÚ
make_rmenurB   r   rU   ZconfigÚrmenu_specsÚ
ValueErrorÚgetattrZentryconfigureZtk_popupZx_rootZy_root)	r»   rB   r  ZiswinÚitemrî   Ú	eventnameZverify_staterÔ   r   r   r   rl   ã  s*    zEditorWindow.right_menu_event)ZClosez<<close-window>>Nc             C   sj   t | jdd}xP| jD ]F}|d |d  }}|d k	rT| j|fdd„}|j||d q| ¡  qW || _d S )Nr   )rí   rE   c             S   s   |   |¡ d S )N)Úevent_generate)r=   r  r   r   r   rF     s    z(EditorWindow.make_rmenu.<locals>.command)rî   rF   )r\   r=   r  Úadd_commandr²   r  )r»   r  r  rî   r  rF   r   r   r   r    s    zEditorWindow.make_rmenuc             C   s   |   ¡ S )N)Úrmenu_check_copy)r»   r   r   r   Úrmenu_check_cut  s    zEditorWindow.rmenu_check_cutc             C   s6   y| j  d¡}W n tk
r$   dS X |r.dS dS d S )Nz	sel.firstÚdisabledÚnormal)r=   r±   ÚTclError)r»   Zindxr   r   r   r    s
    zEditorWindow.rmenu_check_copyc             C   s6   y| j j d| j d¡ W n tk
r,   dS X dS d S )Nztk::GetSelectionZ	CLIPBOARDr  r  )r=   ÚtkÚcallr  )r»   r   r   r   Úrmenu_check_paste  s
    zEditorWindow.rmenu_check_pastec             C   s   t  | j¡ dS )NrA   )r   ZAboutDialogr^   )r»   rB   r   r   r   rt   "  s    zEditorWindow.about_dialogc             C   s   t  | jd¡ dS )NZSettingsrA   )r   ZConfigDialogr^   )r»   rB   r   r   r   ru   (  s    zEditorWindow.config_dialogc             C   s"   | j r| j }n| j}t |¡ dS )NrA   )r[   r^   r   Zshow_idlehelp)r»   rB   Úparentr   r   r   rr   .  s
    
zEditorWindow.help_dialogc          
   C   sn   t jd d… dkr^yt | j¡ W qj tk
rZ } ztjdt|ƒ| j	d W d d }~X Y qjX nt
 | j¡ dS )Nr2   r3   zDocument Start Failure)ÚtitleÚmessager  rA   )r   rU   rQ   Ú	startfilerP   ÚOSErrorrµ   r¹   rÙ   r=   Ú
webbrowserÚopen)r»   rB   Úwhyr   r   r   rs   8  s    $zEditorWindow.python_docsc             C   s   | j  d¡ dS )Nz<<Cut>>rA   )r=   r  )r»   rB   r   r   r   rn   C  s    zEditorWindow.cutc             C   s    | j  d¡sd S | j  d¡ dS )NrÑ   z<<Copy>>rA   )r=   Z
tag_rangesr  )r»   rB   r   r   r   ro   G  s    zEditorWindow.copyc             C   s   | j  d¡ | j  d¡ dS )Nz	<<Paste>>rÏ   rA   )r=   r  rÝ   )r»   rB   r   r   r   rp   N  s    zEditorWindow.pastec             C   s.   | j  ddd¡ | j  dd¡ | j  d¡ dS )NrÑ   z1.0zend-1crÏ   rA   )r=   rÜ   rÛ   rÝ   )r»   rB   r   r   r   rw   S  s    zEditorWindow.select_allc             C   s    | j  ddd¡ | j  d¡ dS )NrÑ   z1.0rN   rÏ   rA   )r=   rÚ   rÝ   )r»   rB   r   r   r   rx   Y  s    zEditorWindow.remove_selectionc                s*   | j j‰| j j‰d‰‡ ‡‡‡fdd„}|S )N)zsel.first+1czsel.last-1cc                sB   | j d@ dkr>yˆdƒ ˆdˆˆ  ƒ W n tk
r<   Y nX d S )Nr>   r   z	sel.firstrÏ   )rÔ   r  )rB   )Ú
edge_indexÚedges_tableÚself_text_indexÚself_text_mark_setr   r   Úmove_at_edgei  s    z<EditorWindow.move_at_edge_if_selection.<locals>.move_at_edge)r=   r±   rÛ   )r»   r  r#  r   )r  r   r!  r"  r   rŠ   ^  s
    z&EditorWindow.move_at_edge_if_selectionc             C   s   | j  d¡ dS )Nz<Meta-Delete>rA   )r=   r  )r»   rB   r   r   r   r‹   r  s    zEditorWindow.del_word_leftc             C   s   | j  d¡ dS )Nz<Meta-d>rA   )r=   r  )r»   rB   r   r   r   rŒ   v  s    zEditorWindow.del_word_rightc             C   s   t  | j¡ dS )NrA   )r   Úfindr=   )r»   rB   r   r   r   ry   z  s    zEditorWindow.find_eventc             C   s   t  | j¡ dS )NrA   )r   Z
find_againr=   )r»   rB   r   r   r   rz   ~  s    zEditorWindow.find_again_eventc             C   s   t  | j¡ dS )NrA   )r   Zfind_selectionr=   )r»   rB   r   r   r   r|   ‚  s    z!EditorWindow.find_selection_eventc             C   s   t   | j| j| j¡ dS )NrA   )r   r=   r¥   rZ   )r»   rB   r   r   r   r{   †  s    z EditorWindow.find_in_files_eventc             C   s   t   | j¡ dS )NrA   )r   r=   )r»   rB   r   r   r   r}   Š  s    zEditorWindow.replace_eventc             C   sT   | j }tjdd|d}|d kr"dS |dkr6| ¡  dS | dd| ¡ | d¡ dS )NZGotozGo to line number:)r  rA   r   rÏ   z%d.0)r=   r·   r¸   ÚbellrÛ   rÝ   )r»   rB   r=   Úlinenor   r   r   r~   Ž  s    

zEditorWindow.goto_line_eventc             C   sp   y| j  dd¡ ¡ }W n tk
r.   d}Y nX t | j dd|¡j}|d k	rl| jr`| j |¡ n| j	 
|¡ |S )Nz	sel.firstzsel.lastr6   zOpen ModulezAEnter the name of a Python module
to search on sys.path and open:)r=   r°   Ústripr  r   Z
ModuleNameÚresultrZ   r  r¥   rª   )r»   r8   Z	file_pathr   r   r   Úopen_module›  s    
zEditorWindow.open_modulec             C   s   |   ¡  dS )NrA   )r)  )r»   rB   r   r   r   rv   ³  s    zEditorWindow.open_module_eventc             C   sJ   | j j}| jjdkr|s,|  ¡ }|d kr,dS ddlm} | | j|¡ dS )NZPyShellEditorWindowrA   r   )Úbrowser)	r¥   r¼   Ú	__class__Ú__name__r)  Úidlelibr*  ZModuleBrowserr[   )r»   rB   r¼   r*  r   r   r   r   ·  s    z EditorWindow.open_module_browserc             C   s   ddl m} | | j¡ dS )Nr   )ÚpathbrowserrA   )r-  r.  ZPathBrowserr[   )r»   rB   r.  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)ÚshellrA   )Ú
subprocessr   Ú
executableÚPopen)r»   rB   r0  Úcmdr   r   r   r’   Ç  s    zEditorWindow.open_turtle_democ             C   sN   |d k	rJ|dkrJ| j  dd| ¡ | j  ddd¡ | j  ddd¡ |  ¡  d S )Nr   rÏ   z%d.0rÑ   z1.0rN   z
insert +1l)r=   rÛ   rÚ   rÜ   Úcenter)r»   r&  r   r   r   ÚgotolineÐ  s
    zEditorWindow.gotolinec             C   s`   |rt j |¡rdS t j t j |¡¡\}}t j |¡dkr@dS | j dd¡}| d¡o^d|kS )NT)z.pyz.pywz1.0z1.0 lineendz#!Zpython)	rQ   rR   rW   ÚsplitextrÊ   Únormcaser=   r°   Ú
startswith)r»   r¼   ÚbaseZextrÞ   r   r   r   r«   ×  s    zEditorWindow.ispythonsourcec             C   s   | j r| j  | ¡ d | _ d S )N)rZ   Zunregister_maybe_terminate)r»   r   r   r   Ú
close_hookà  s    zEditorWindow.close_hookc             C   s
   || _ d S )N)r:  )r»   r:  r   r   r   Úset_close_hookå  s    zEditorWindow.set_close_hookc             C   s2   | j r| j  | ¡ |  ¡  | j | ¡ |  ¡  d S )N)rZ   Zfilename_changed_editr¤   r^   Zupdate_windowlist_registryr¬   )r»   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 )N)	r¨   r«   r¥   r¼   r!   rŸ   Úremovefilterr    r¡   )r»   r   r   r   Ú_addcolorizerï  s    
zEditorWindow._addcolorizerc             C   s,   | j s
d S | j  ¡  | j | j ¡ d | _ d S )N)r¨   ZremovecolorsrŸ   r<  )r»   r   r   r   Ú_rmcolorizerú  s
    
zEditorWindow._rmcolorizerc             C   s    |   ¡  |  ¡  t | j¡ d S )N)r>  r=  r   r"   r=   )r»   r   r   r   r¬     s    zEditorWindow.ResetColorizerÚ_c             C   sp   |  d|¡ | |¡}|r6|| jkr6|  d|d |¡ d| |¡krR| d|¡ n| d|d ¡ | |¡ d S )NZERRORz
 wordstartÚ
rÏ   z+1c)rÜ   r°   Ú
IDENTCHARSrÛ   rÝ   )r»   r=   ÚposÚcharr   r   r   Úcolorize_syntax_error
  s    
z"EditorWindow.colorize_syntax_errorc             C   s   t  | jdd¡| jd< d S )Nr9   r   rI   )r   r™   r[   r=   )r»   r   r   r   Ú	ResetFont  s    zEditorWindow.ResetFontc             C   s„   t  ¡  | j_}x&| ¡ D ]\}}| jj|f|žŽ  qW xF|  ¡ D ]:}t  |¡}|rBx&| ¡ D ]\}}| jj|f|žŽ  q^W qBW d S )N)	r   ÚGetCurrentKeySetr&   Údefault_keydefsÚitemsr=   Zevent_deleteÚget_standard_extension_namesÚGetExtensionBindings)r»   ÚkeydefsrB   ÚkeylistÚextensionNameÚxkeydefsr   r   r   ÚRemoveKeybindings  s    
zEditorWindow.RemoveKeybindingsc             C   sV  t  ¡  | j_}|  ¡  x(|  ¡ D ]}t  |¡}|r"|  |¡ q"W i }xR| jjD ]F}i ||d < x4|d D ](}|rj|d ||d  t|d ƒd < qjW qPW x¶| j	D ]¬}| j	| }| 
t¡}|d krÄq¢|d7 }x€td|ƒD ]r}	| |	¡dkrØ| |	d¡}
|
rØ| |	d¡}d}||kr.||| kr.|| | }|rØt||ƒ}
|j|	|
d qØW q¢W d S )Nr   rE   rF   Úacceleratorrî   r6   )rP  )r   rF  r&   rG  rh   rI  rJ  Úmenudefsrñ   r¯   r±   rô   r×   r<   Z	entrycgetÚget_acceleratorrø   )r»   rK  rM  rN  ZmenuEventDictr5   r  ZmenubarItemrN   r±   ZaccelZitemNamerB   r   r   r   ÚApplyKeybindings'  s<    
(



zEditorWindow.ApplyKeybindingsc             C   s   | j stjddddd| _d S )Nr9   rK   z
num-spacesr;   )r<   )rš   r   rf   rœ   )r»   r   r   r   r   K  s    
z#EditorWindow.set_notabs_indentwidthc             C   s€   t  ¡ }| jd }| t¡}|| jkr8| | jd |¡ |rr| ¡  x,|D ]$}|  |d ¡}|j	|d |d qJW || jd< d S )Nr   rE   r   )rî   rF   )
r   ZGetAllExtraHelpSourcesListr¯   r±   rô   rõ   r÷   r²   Ú"_EditorWindow__extra_help_callbackr  )r»   Z	help_listZhelpmenuZhelpmenu_lengthÚentryr3  r   r   r   rö   R  s    



z$EditorWindow.reset_help_menu_entriesc                s   |f‡ fdd„	}|S )Nc          
      s€   |   d¡stj | ¡} tjd d… dkrryt | ¡ W q| tk
rn } ztj	dt
|ƒˆ jd W d d }~X Y q|X n
t | ¡ d S )N)ZwwwZhttpr2   r3   zDocument Start Failure)r  r  r  )r8  rQ   rR   rY   r   rU   r  r  rµ   r¹   rÙ   r=   r  r  )Úhelpfiler  )r»   r   r   Údisplay_extra_helpe  s    
$z>EditorWindow.__extra_help_callback.<locals>.display_extra_helpr   )r»   rV  rW  r   )r»   r   Z__extra_help_callbackc  s    z"EditorWindow.__extra_help_callbackc          
      sÌ  g }t j | j¡r8t| jdddd}| ¡ }W d Q R X |rjt j |¡d }||kr^| |¡ | d|¡ g ‰ x2|D ]*}d|ks”t j |dd… ¡stˆ  	|¡ qtW ‡ fd	d
„|D ƒ}d}|dt
|ƒ… }y,t| jdddd}| |¡ W d Q R X W n\ tk
rP } z<t| jddƒs@d| j_tjdd|  t|ƒ¡ | jd W d d }~X Y nX xt| jjD ]h}|j}	|	 dt¡ xNt|ƒD ]B\}
}| ¡ }|  |¡}| |¡}|	j||
 d | |dd q|W q\W d S )NÚrÚutf_8r   )r%   Úerrorsr@  r   ú rO   c                s   g | ]}|ˆ kr|‘qS r   r   )Ú.0rR   )Ú	bad_pathsr   r   ú
<listcomp>ƒ  s    z9EditorWindow.update_recent_files_list.<locals>.<listcomp>Z1234567890ABCDEFGHIJKÚwÚrecentfilelist_error_displayedFTzIDLE Warningz|Cannot update File menu Recent Files list. Your operating system says:
%s
Select OK and IDLE will continue without updating.)r  r  r  rÍ   )rî   rF   rï   )rQ   rR   r©   rb   r  Ú	readlinesÚabspathÚremoverÏ   ÚappendrØ   Ú
writelinesr  r
  r[   r`  rµ   ÚshowwarningrÇ   rÙ   r=   r^   ra   ró   r÷   rô   Ú	enumerateÚrstripÚ#_EditorWindow__recent_file_callbackr  )r»   Únew_fileZrf_listZrf_list_filerR   ZulcharsZrf_fileÚerrÚinstancer5   ÚiÚ	file_nameZ
ufile_nameÚcallbackr   )r]  r   r­   r  sL    



z%EditorWindow.update_recent_files_listc                s   |f‡ fdd„	}|S )Nc                s   ˆ j j| d d S )N)ZeditFile)r¥   r  )Z
fn_closure)r»   r   r   Úopen_recent_file¡  s    z=EditorWindow.__recent_file_callback.<locals>.open_recent_filer   )r»   rn  rp  r   )r»   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_savedr^   Zwm_titleZwm_iconname)r»   ZshortZlongr  Ziconr   r   r   r¤   ¥  s    zEditorWindow.saved_change_hookc             C   s
   | j  ¡ S )N)r    ru  )r»   r   r   r   ru  ·  s    zEditorWindow.get_savedc             C   s   | j  |¡ d S )N)r    Ú	set_saved)r»   Úflagr   r   r   rv  º  s    zEditorWindow.set_savedc             C   s   | j  ¡  d S )N)r    Ú
reset_undo)r»   r   r   r   rx  ½  s    zEditorWindow.reset_undoc             C   s(   | j j}|rtj |¡}nd}|  |¡S )Nrq  )r¥   r¼   rQ   rR   rÊ   rÇ   )r»   r¼   r   r   r   rr  À  s
    zEditorWindow.short_titlec             C   s   |   | jjpd¡S )Nr6   )rÇ   r¥   r¼   )r»   r   r   r   rs  É  s    zEditorWindow.long_titlec             C   s   |   ¡  dS )NrA   )r4  )r»   rB   r   r   r   rq   Í  s    z EditorWindow.center_insert_eventrÏ   c             C   sH   | j }|  ¡ \}}|  |¡}|| }td||d  ƒ}| t|ƒ¡ d S )NrE   r4   )r=   Úgetwindowlinesrÿ   Úmaxr   rý   )r»   Úmarkr=   r^   Úbotr&  r?   Znewtopr   r   r   r4  Ñ  s    
zEditorWindow.centerc             C   sN   | j }|  d¡}|  d¡}||krF| ¡ dkrFt|d ƒ}|| d }||fS )Nz@0,0z@0,65535rE   r?   )r=   rÿ   Zwinfo_heightr;   )r»   r=   r^   r|  r?   r   r   r   ry  Ù  s    

zEditorWindow.getwindowlinesc             C   s   | j }tt| |¡ƒƒS )N)r=   r;   rý   r±   )r»   r{  r=   r   r   r   rÿ   ã  s    zEditorWindow.getlinenoc             C   s(   | j  ¡ }t d|¡}ttt| ¡ ƒƒS )Nz(\d+)x(\d+)\+(-?\d+)\+(-?\d+))r^   Zwm_geometryrÅ   ÚmatchÚlistÚmapr;   Úgroups)r»   ZgeomÚmr   r   r   Úget_geometryç  s    
zEditorWindow.get_geometryc             C   s   |   ¡  dS )NrA   )ri   )r»   rB   r   r   r   rk   í  s    zEditorWindow.close_eventc             C   sH   | j rD|  ¡ s:| j ¡ dkr&| j ¡  | j ¡  | j ¡  | j  ¡ S d S )Nr  )r¥   ru  r^   rÔ   Z	deiconifyÚlowerZliftÚ	maybesave)r»   r   r   r   r„  ñ  s    


zEditorWindow.maybesavec             C   s    |   ¡ }t|ƒdkr|  ¡  |S )NZcancel)r„  rÙ   Ú_close)r»   Zreplyr   r   r   ri   ú  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)rj  )r¥   r¼   r­   r   Zunregister_callbackr´   Úunload_extensionsri   r    r¨   r=   r`   rŸ   r^   Zdestroyr:  )r»   r   r   r   r…     s"    



zEditorWindow._closec             C   s   i | _ |  ¡  d S )N)Ú
extensionsÚload_standard_extensions)r»   r   r   r   r®     s    zEditorWindow.load_extensionsc             C   s4   x(t | j ¡ ƒD ]}t|dƒr| ¡  qW i | _d S )Nri   )r~  r‡  ÚvaluesÚhasattrri   )r»   Úinsr   r   r   r†    s    
zEditorWindow.unload_extensionsc             C   sH   xB|   ¡ D ]6}y|  |¡ W q
   tdt|ƒƒ t ¡  Y q
X q
W d S )NzFailed to load extension)rI  Úload_extensionÚprintÚreprÚ	tracebackÚ	print_exc)r»   r8   r   r   r   rˆ    s    z%EditorWindow.load_standard_extensionsc             C   s   t jddS )NT)Zeditor_only)r   ZGetExtensions)r»   r   r   r   rI  &  s    z)EditorWindow.get_standard_extension_namesZZzDummyZzzdummyc       	   	   C   sF  | j  ||¡}y>ytjd| td}W n" ttfk
rH   t |¡}Y nX W n  tk
rl   td|ƒ ‚ Y nX t||ƒ}t	 
|¡}t|dƒrš|  |j|¡ || ƒ}|| j|< |rB|  |¡ x„|D ]|}| dd¡}x |d d… dkrò|dd … }qÔW x"|d	d … d
kr|d d	… }qöW |d }t||ƒrÂ| j |t||ƒ¡ qÂW d S )NrÌ   )Úpackagez
Failed to import extension: rQ  ú-r?  rE   rÒ   rO   rÓ   Z_event)Úextfilesr°   Ú	importlibÚimport_moduleÚ__package__ÚImportErrorÚ	TypeErrorr  r
  r   rJ  rŠ  rò   rQ  r‡  rh   r   r=   rj   )	r»   r8   ZfnameÚmodÚclsrK  r‹  ZveventZ
methodnamer   r   r   rŒ  -  s4    







zEditorWindow.load_extensionc             C   sJ   |d kr| j j}| j}||_x(| ¡ D ]\}}|r&|j|f|žŽ  q&W d S )N)r&   rG  r=   rK  rH  rº   )r»   rK  r=   rB   rL  r   r   r   rh   I  s    zEditorWindow.apply_bindingsc          	   C   sò   |d kr| j j}|d kr | j j}| j}| j}xÀ|D ]¸\}}| |¡}|sJq2xž|D ]–}|sb| ¡  qP|\}	}
|	d d… dk}|rŠ|	dd … }	t|	ƒ\}}	t||
ƒ}||
fdd„}|rÔ|  	|
t
¡}|j|	||||d qP|j|	|||d qPW q2W d S )NrE   ú!c             S   s   |   |¡ d S )N)r  )r=   r  r   r   r   rF   k  s    z(EditorWindow.fill_menus.<locals>.command)rî   rï   rF   rP  Úvariable)rî   rï   rF   rP  )r&   rQ  rG  r¯   r=   r°   r²   rñ   rR  Úget_var_objZ
BooleanVarZadd_checkbuttonr  )r»   rQ  rK  r¯   r=   ZmnameZ	entrylistr5   rU  rî   r  Zcheckbuttonrï   rP  rF   Úvarr   r   r   rò   R  s8    




zEditorWindow.fill_menusc             C   s&   |   |¡}|r| ¡ }|S t|ƒ‚d S )N)r  r°   Ú	NameError)r»   r8   rž  Úvaluer   r   r   Úgetvarw  s
    
zEditorWindow.getvarc             C   s(   |   ||¡}|r| |¡ nt|ƒ‚d S )N)r  r˜   rŸ  )r»   r8   r   Úvartyperž  r   r   r   Úsetvar  s    zEditorWindow.setvarc             C   s,   | j  |¡}|s(|r(|| jƒ | j |< }|S )N)r`   r°   r=   )r»   r8   r¢  rž  r   r   r   r  †  s    zEditorWindow.get_var_objc             C   s,   | j r$| j d|¡p"d| j |¡kS dS d S )NZTODOÚSTRINGrE   )r¨   r=   Útag_prevrangeZ	tag_names)r»   Z
text_indexr   r   r   Úis_char_in_string–  s    zEditorWindow.is_char_in_stringc             C   s:   y | j  d¡}| j  d¡}||fS  tk
r4   dS X d S )Nz	sel.firstzsel.last)NN)r=   r±   r  )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)r=   ÚTK_TABWIDTH_DEFAULTr;   )r»   Z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 )NrI   Zmeasurez
-displayofÚn)r¨  )r=   rª  r  r  ZmasterZ	configure)r»   Znewtabwidthr=   Zpixelsr   r   r   Úset_tk_tabwidth³  s    
zEditorWindow.set_tk_tabwidthTc             C   sP   |r@|r@|   ¡ }d|  kr$dkr.n n|| _| j| jkr@d| _|  | j¡ d S )Nr4   r   F)Úguess_indentrœ   r›   rš   r¬  )r»   r¾   Zguessrm  r   r   r   r§   ¾  s    z#EditorWindow.set_indentation_paramsc       
      C   sB  | j }|  ¡ \}}|r6|r6| ||¡ | d|¡ dS | dd¡}|dkrp| ddd¡rd| d¡ n| ¡  dS |d d	krŠ| d¡ dS | j}t| 	|¡ƒ}|d
 | j
 | j
 }d}	xH|| jkrÄP |d d… }|	d
 }	t| 	|¡ƒ}||ksú|d d	kr¸P q¸W | ¡  | d|	 d¡ ||k r6| dd||  ¡ | ¡  dS )NrÏ   rA   zinsert linestartr6   rÓ   z1.0z	insert-1crO   z 	rE   r   z
insert-%dcrÍ   )r=   r§  r÷   rÛ   r°   rÕ   r%  r›   rØ   Ú
expandtabsrœ   rc   r¢   rÏ   r£   )
r»   rB   r=   rà   rá   Úcharsr›   ZhaveZwantZncharsdeletedr   r   r   r   Ç  sB    


z"EditorWindow.smart_backspace_eventc       
      C   sê   | j }|  ¡ \}}| ¡  zÀ|rV|rVt|ƒt|ƒkr>|  |¡S | ||¡ | d|¡ | dd¡}t|| j	ƒ\}}|t
|ƒkr|  || j ¡ n>| jrœd}n&t
| | j	¡ƒ}| j}	d|	||	   }| d|¡ | d¡ dS | ¡  X d S )NrÏ   zinsert linestartrÎ   rÍ   rA   )r=   r§  r¢   Ú
index2liner‚   r÷   rÛ   r°   Ú
classifywsr›   rØ   Úreindent_torœ   rš   r®  rÏ   rÝ   r£   )
r»   rB   r=   rà   rá   ÚprefixÚrawÚ	effectiveZpadr«  r   r   r   r   ó  s,    

zEditorWindow.smart_indent_eventc          	   C   sê  | j }|  ¡ \}}| ¡  z´|r>|r>| ||¡ | d|¡ | dd¡}dt|ƒ }}x ||k rx|| dkrx|d }qZW ||kr’| dd¡ dS |d |… }d}x2|rÔ|d dkrÔ|| jkrÔ|d d… }|d }q¤W |rê| d	| d¡ x| d¡dkr| d¡ qìW | dd¡ t	| 
d¡ƒ}	t | j| j¡}
| js¶xf| jD ]\}t|	| dƒ}t|ƒd
 }| |d¡}|
 |¡ |
 |  |¡¡}|d k	sœ|dkrDP qDW |
 |p°d¡ n@| dd¡}|rÒ|d }nd}| |d¡}|
 |¡ |
 d¡ |
 ¡ }|tjkrŠ|tjkrnn|tjkr2| d|¡ nT|tjkrN|  |
 ¡ ¡ n8|tjkr†|
 ¡ dkrv| d|¡ n|  |
  ¡ ¡ n dS |
 !¡ }| d|¡ |
 "¡ r´|  #|¡ n|rÎ|
 $¡ rÎ|  %|¡ dS | &d¡ | '¡  X d S )NrÏ   zinsert linestartr   z 	rE   r@  rA   rO   zinsert - %d charsz.0Zconsolez1.0)(r=   r§  r¢   r÷   rÛ   r°   rØ   rÏ   rc   r°  r±   r   ZParserrœ   r›   rž   rz  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Ý   r£   )r»   rB   r=   rà   rá   rÞ   rm  r«  ÚindentZlnor  ÚcontextZstartatZstartatindexZrawtextZbodrX  rÐ   r   r   r   r€     s„    






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   sz   |   ¡ \}}}}xTtt|ƒƒD ]D}|| }|rt|| jƒ\}}	|	| j }	|  |	¡||d …  ||< qW |  ||||¡ dS )NrA   )Ú
get_regionr×   rØ   r±  r›   rœ   Ú_make_blanksÚ
set_region)
r»   rB   ÚheadÚtailr¯  r  rB  rÞ   r´  rµ  r   r   r   r‚   …  s    
z EditorWindow.indent_region_eventc       
      C   s€   |   ¡ \}}}}xZtt|ƒƒD ]J}|| }|rt|| jƒ\}}	t|	| j dƒ}	|  |	¡||d …  ||< qW |  ||||¡ dS )Nr   rA   )	r»  r×   rØ   r±  r›   rz  rœ   r¼  r½  )
r»   rB   r¾  r¿  r¯  r  rB  rÞ   r´  rµ  r   r   r   rƒ     s    z EditorWindow.dedent_region_eventc             C   sR   |   ¡ \}}}}x,tt|ƒd ƒD ]}|| }d| ||< q"W |  ||||¡ dS )NrE   z##rA   )r»  r×   rØ   r½  )r»   rB   r¾  r¿  r¯  r  rB  rÞ   r   r   r   r„   ›  s    z!EditorWindow.comment_region_eventc             C   sŠ   |   ¡ \}}}}xdtt|ƒƒD ]T}|| }|s0q|d d… dkrN|dd … }n|d d… dkrj|dd … }|||< qW |  ||||¡ dS )Nr4   z##rE   ú#rA   )r»  r×   rØ   r½  )r»   rB   r¾  r¿  r¯  r  rB  rÞ   r   r   r   r…   £  s    z#EditorWindow.uncomment_region_eventc             C   s–   |   ¡ \}}}}|  ¡ }|d kr$d S x\tt|ƒƒD ]L}|| }|r2t||ƒ\}	}
t|
|ƒ\}}d| d|  ||	d …  ||< q2W |  ||||¡ dS )NrÎ   rÍ   rA   )r»  Ú_asktabwidthr×   rØ   r±  Údivmodr½  )r»   rB   r¾  r¿  r¯  r  r›   rB  rÞ   r´  rµ  ÚntabsÚnspacesr   r   r   r†   ±  s     $z EditorWindow.tabify_region_eventc             C   s`   |   ¡ \}}}}|  ¡ }|d kr$d S x&tt|ƒƒD ]}||  |¡||< q2W |  ||||¡ dS )NrA   )r»  rÁ  r×   rØ   r®  r½  )r»   rB   r¾  r¿  r¯  r  r›   rB  r   r   r   r‡   ¾  s     z"EditorWindow.untabify_region_eventc             C   sF   | j ddd| j  d d| j  d d | jdrB| j | _d	| _d
S )NzToggle tabsz
Turn tabs )ZonZoffz?
Indent width )zwill bez
remains atz 8.z!
 Note: a tab is always 8 columns)r  r   rA   )r¶   rš   r=   rœ   )r»   rB   r   r   r   rˆ   Ç  s    

zEditorWindow.toggle_tabs_eventc             C   s8   | j dd| j| jddd}|r4|| jkr4| js4|| _dS )NzIndent widthz6New indent width (2-16)
(Always use 8 when using tabs)r4   é   )r  ÚinitialvalueÚminvalueÚmaxvaluerA   )r¸   r=   rœ   rš   )r»   rB   rÈ   r   r   r   r‰   Ý  s    z%EditorWindow.change_indentwidth_eventc             C   sn   | j }|  ¡ \}}|r8|r8| |d ¡}| |d ¡}n| d¡}| d¡}| ||¡}| d¡}||||fS )Nz
 linestartz-1c lineend +1czinsert linestartzinsert lineend +1cr@  )r=   r§  r±   r°   rÖ   )r»   r=   rà   rá   r¾  r¿  r¯  r  r   r   r   r»  é  s    


zEditorWindow.get_regionc             C   sx   | j }d |¡}||kr$| ¡  d S | ddd¡ | d|¡ | ¡  | ||¡ | ||¡ | ¡  | 	d|d¡ d S )Nr@  rÑ   z1.0rN   rÏ   )
r=   rS   r%  rÚ   rÛ   r¢   r÷   rÏ   r£   rÜ   )r»   r¾  r¿  r¯  r  r=   Únewcharsr   r   r   r½  ö  s    
zEditorWindow.set_regionc             C   s2   | j r&t|| jƒ\}}d| d|  S d| S d S )NrÎ   rÍ   )rš   rÂ  r›   )r»   r«  rÃ  rÄ  r   r   r   r¼    s    zEditorWindow._make_blanksc             C   sJ   | j }| ¡  | ddd¡r(| dd¡ |r>| d|  |¡¡ | ¡  d S )Nzinsert linestartz!=rÏ   )r=   r¢   rÕ   r÷   rÏ   r¼  r£   )r»   râ   r=   r   r   r   r²    s    zEditorWindow.reindent_toc             C   s   | j dd| j| jdddS )Nz	Tab widthzColumns per tab? (2-16)r4   rÅ  )r  rÆ  rÇ  rÈ  )r¸   r=   rœ   )r»   r   r   r   rÁ    s    zEditorWindow._asktabwidthc             C   sP   t | j| jƒ ¡ \}}|r@|r@t|| jƒ\}}t|| jƒ\}}nd }}|| S )Nr   )ÚIndentSearcherr=   r›   rë   r±  )r»   ÚopenerZindentedr´  ZindentsmallZindentlarger   r   r   r­  '  s    zEditorWindow.guess_indent)NNNN)N)N)N)N)N)N)N)N)N)N)N)rÏ   )rÏ   )N)NN)N)N)T)˜r,  Ú
__module__Ú__qualname__Zidlelib.percolatorr    Zidlelib.colorizerr!   r"   Zidlelib.undor#   Zidlelib.iomenur$   r%   r-  r&   Zidlelib.statusbarr'   Zidlelib.autocompleter(   Zidlelib.autoexpandr)   Zidlelib.calltipr*   Zidlelib.codecontextr+   Zidlelib.paragraphr,   Zidlelib.parenmatchr-   Zidlelib.rstripr.   Zidlelib.squeezerr/   Zidlelib.zoomheightr0   r   ÚgetfilesystemencodingrÃ   rP   r¿   rÇ   r   r   r“   ræ   rð   rg   r´   rú   rû   r”   rm   r  rl   r  r  r  r  r  rt   ru   rr   rs   rn   ro   rp   rw   rx   rŠ   r‹   rŒ   ry   rz   r|   r{   r}   r~   r)  rv   r   r‘   r’   r5  r«   r:  r;  r¦   r=  r>  r¬   ÚstringZascii_lettersÚdigitsrA  rD  rE  rO  rS  r   rö   rT  r­   ri  r¤   ru  rv  rx  rr  rs  rq   r4  ry  rÿ   r‚  rk   r„  ri   r…  r®   r†  rˆ  rI  r“  rŒ  rh   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   r   r   r   r   -   s  
 ~+






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

	
	%	,#i	
	r   c             C   s   t t| ƒƒS )N)r;   rý   )r±   r   r   r   r°  1  s    r°  c             C   s\   d }}xJ| D ]B}|dkr,|d }|d }q|dkrN|d }|| d | }qP qW ||fS )Nr   rÍ   rE   rÎ   r   )Úsr›   r´  rµ  Zchr   r   r   r±  9  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 )Nr   )r=   r›   rm  ÚfinishedÚblkopenlineÚindentedline)r»   r=   r›   r   r   r   r¿   N  s    zIndentSearcher.__init__c             C   sL   | j r
dS | jd  }| _t|ƒd }| j |dd¡r:dS | j ||d ¡S )Nr6   rE   z.0z>=rN   z lineend+1c)rÒ  rm  rŽ  r=   rÕ   r°   )r»   rm  r{  r   r   r   ÚreadlineT  s    zIndentSearcher.readline)ÚclassÚdefÚforÚifÚtryÚwhilec	       	      C   s>   | j rn2||kr ||kr || _n||kr:| jr:|| _d| _ d S )NrE   )rÒ  rÓ  rÔ  )	r»   r<   ÚtokenÚstartrN   rÞ   ÚINDENTÚNAMEZOPENERSr   r   r   Ú
tokeneater]  s    zIndentSearcher.tokeneaterc          	   C   sl   t j}| jt _zHy(t  | j¡}x|D ]}| j|Ž  q$W W n t jtfk
rR   Y nX W d |t _X | j| j	fS )N)
ÚtokenizeÚtabsizer›   Úgenerate_tokensrÕ  rà  Ú
TokenErrorÚSyntaxErrorrÓ  rÔ  )r»   Zsave_tabsizeÚtokensrÜ  r   r   r   rë   i  s    

zIndentSearcher.runN)
r,  rÌ  rÍ  r¿   rÕ  rá  rÞ  rß  rà  rë   r   r   r   r   rÊ  G  s   
	rÊ  c             C   s6   |   d¡}|dkr.| d |… | |d d …  } || fS )Nr?  r   rE   )r$  )rÑ  rm  r   r   r   rñ   {  s    
rñ   ú[ú]ú/)ZbracketleftZbracketrightZslashc             C   s´   |   |¡}|rt ¡ r"|dk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>   ú<<change-indentwidth>>ú<<open-module>>ú<<goto-line>>r6   r   z-[a-z]\bc             S   s   |   ¡  ¡ S )N)ÚgroupÚupper)r  r   r   r   rC   ”  rD   z!get_accelerator.<locals>.<lambda>z\b\w+\bc             S   s   t  |  ¡ |  ¡ ¡S )N)Úkeynamesr°   rí  )r  r   r   r   rC   •  rD   zKey-ZCancelz
Ctrl-BreakzControl-zCtrl-r’  ú+z><rÍ   rÒ   rÓ   )r°   r	   Z	isCocoaTkrÅ   rÆ   )rK  r  rL  rÑ  r   r   r   rR  Š  s    
rR  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  r  )r[   r  r   r   r   Úfixwordbreaks   s    rñ  c             C   s‚   | }t |ƒ tjdd … r&tjd }nd }t |d ¡ t||d}|j}d|d< x,tdƒD ] }| dd| t	|ƒ d ¡ qZW d S )	NrE   )r[   r¼   é
   r?   é   rÏ   z  r@  )
rñ  r   Úargvr	   ZsetupAppr   r=   r×   rÏ   rÙ   )r  r[   r¼   ré   r=   rm  r   r   r   Ú_editor_window©  s    rõ  Ú__main__)r9   zidlelib.idle_test.test_editorr4   F)Ú	verbosityÚexit)rë   )6Zimportlib.abcr”  Úimportlib.utilrQ   rU   rÏ  rá  r  r  ZtkinterZtkinter.ttkr   Ztkinter.simpledialogZsimpledialogr·   Ztkinter.messageboxZ
messageboxrµ   Zidlelib.configr   r-  r   r   r   r   r	   Zidlelib.multicallr
   r   r   r   r   r   r©  Zpython_versionrt  r   r   r   Úobjectr   r°  r±  rÊ  rñ   rï  rR  rñ  rõ  r,  Zunittestr9   Zidlelib.idle_test.htestrë   r   r   r   r   Ú<module>   sn   
            4
	
