[@smddlZddlZddlZddlZddlZddlZddlZddlZddlTddl j Z ddl j ZddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZmZmZdd lmZd Z dej!Z"ddZ#Gddde$Z%e%Z&ddZ'Gddde$Z(ddZ)ddZ*ddl+Z+e+Z,[+Gddde$Z-ddZ.idd 6d!d"6d#d$6Z/d%d&Z0d'd(Z1d)d*Z2e3d+kridd,l4m5Z5e5e'e2ndS)-N)*)MultiCallCreator)idlever) WindowList) SearchDialog) GrepDialog) ReplaceDialog)PyParse)idleConf) aboutDialogtextView configDialog) macosxSupportz (%s)cCstj\}}}}}d||f}|d|f7}|dkrY|d|f7}n'|dkr|d|d|f7}n|S)zYFormat sys.version_info to produce the Sphinx version string used to install the chm docsz%s%sz%s candidatezrc%sfinalr)sys version_info)majorminormicrolevelserialreleaser*/usr/lib/python3.4/idlelib/EditorWindow.py_sphinx_versions  rc@sReZdZddZdddZddZdd Zdd d ZdS) HelpDialogcCsd|_d|_dS)N)parentdlg)selfrrr__init__-s zHelpDialog.__init__NcCs9|jdkr|j|n|r5|j|ndS)z Display the help dialog. parent - parent widget for the help window near - a Toplevel widget (e.g. EditorWindow or PyShell) to use as a reference for placing the help window N)r show_dialog nearwindow)r rnearrrrdisplay1szHelpDialog.displaycCsr||_tjjtjjtjjtd}tj|d|dd|_ }|j d|j ddS)Nzhelp.txtZHelpZmodalFz +) rospathjoinabspathdirname__file__r Z view_filerbinddestroy)r rfnrrrrr">s -"zHelpDialog.show_dialogcCs\|j}|jd|jdf}|j|jd||j|jdS)N z=+%d+%d)rZ winfo_rootxZ winfo_rootyZwithdrawZgeometry deiconifylift)r r$rgeomrrrr#Ds     zHelpDialog.nearwindowcCsd|_d|_dS)N)rr)r evrrrr.Os zHelpDialog.destroy)__name__ __module__ __qualname__r!r%r"r#r.rrrrr+s    rcCstj|dS)N) helpDialogr")rrrr _help_dialogTsr9c@seZdZddlmZddlmZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd d d d d d Zd d ZddZddZddZddZd ddZdddddddgZd&d'Zd(d)Zd Zd*d+ZdgZ d.d/Z!d0d1Z"d2d3Z#d4d5Z$d d6d7Z%d d8d9Z&d d:d;Z'd d<d=Z(d d>d?Z)d@dAZ*dBdCZ+dDdEZ,d dFdGZ-d dHdIZ.dJdKZ/dLdMZ0dNdOZ1dPdQZ2dRdSZ3dTdUZ4dVdWZ5dXdYZ6dZd[Z7d d\d]Z8d d^d_Z9d d`daZ:d dbdcZ;dddeZ<dfdgZ=dhdiZ>djdkZ?dldmZ@dndoZAdpdqZBdrdsZCeDjEeDjFdtZGdudvZHdwdxZIdydzZJd{d|ZKd}d~ZLddZMddZNd ddZOddZPddZQddZRddZSddZTddZUddZVddZWdddZXddZYdddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdd ddZed d ddZfddZgd ddZhd ddZiddZjddZkddZlddZmdddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddZddZd S) EditorWindowr) Percolator)ColorDelegator) UndoDelegator) IOBindingfilesystemencodingencoding)Bindings)Toplevel)MultiStatusBarNcCs tjdkrtjjtjdd}tjjdrddtj dd}tjj drrd}qd }tjj||dd}ntjddd krtjjtjdd t }tjj |r|}qn*tjd krtjjtjd }ntjj |}tjj |rk|t_tjd krdtjt_qqdtj ddt_ntj} ||_|p|j}||_y tjWntk rdt_YnXt||_tj|d|j|_} |r0|j|_|j|j_ni|_i|j_tjjtjd|_t| |_ } t!| dd|_"} tj#ddddd|_$idd6dd6dd6|j$d6tj#ddd ddd 6} t%d!krd"| d#|j.d7|j?|j.d8|j@|j.d9|jA|j.d:|jB|j.d;|jC|j.d<|jD|j.d=|jE|j.d>|jF|j.d?|jG|j.d@|jH|j.dA|jI|j.dB|jJ|j.dC|jK|j.dD|jL|j.dE|jM|j.dF|jN|j.dG|jO|j.dH|jPdI|j.dJ|jPdK|j.dL|jQ|j.dM|jR|j.dN|jS|r||j|<|r||jT|>> menuzrecent-files.lstnamevbarmainr:widthtypeinttextZpadxZnoneZwrapheightg!@Z wordprocessorZtabstyleZWM_DELETE_WINDOWz<>zz<3>z<>z<>z <>z<>z<>z<>z<>z<>z!<>z<>z<>cSsdS)Nbreakr)eventrrrsz'EditorWindow.__init__..z<>z<>z<>z<>z<>z<>z <>z <>z<>z<>z<>z<>z<>z<>z<>z<>z<>z<>z<>zrzz<>z<>z<>z<>z<>z<>z<>z<>commandsidefillZyscrollcommandnormalz font-boldboolboldfontz font-sizeexpandIndentz use-spacesrF2@KLTwindowsend)r_r`ra)r:help_urlr'r(r)r base_prefixplatformcountrisdirrisfilenormpathr CurrentThemeflistrootps1AttributeErrorMenumenubarrZListedTopleveltopvars tkinter_varsZ inversedict instance_dictZ GetUserCfgDirrecent_files_pathZFrame text_frameZ ScrollbarrJ GetOptionrLZ TkVersionrZTextrOZfocused_widget createmenubarapply_bindingsZprotocolcloser- close_eventrZisAquaTkright_menu_eventcutcopypastecenter_insert_event help_dialog python_docs about_dialog config_dialogconfig_extensions_dialog open_module select_allremove_selection find_eventfind_again_eventfind_in_files_eventfind_selection_event replace_eventgoto_line_eventsmart_backspace_eventnewline_and_indent_eventsmart_indent_eventindent_region_eventdedent_region_eventcomment_region_eventuncomment_region_eventtabify_region_eventuntabify_region_eventtoggle_tabs_eventchange_indentwidth_eventmove_at_edge_if_selection del_word_leftdel_word_right home_callbackdict new_callbackZclose_all_callbackopen_class_browseropen_path_browseropen_turtle_demoset_status_baryviewpackRIGHTYsetconfigZLEFTZBOTHZTOPZ focus_setusetabstabwidth indentwidthset_notabs_indentwidthcontext_use_ps1num_context_linesr;perr=undo insertfilterundo_block_startundo_block_stopZset_saved_change_hooksaved_change_hookr>ioZset_filename_change_hookfilename_change_hookZ good_loadset_indentation_paramscolorexistsloadfileispythonsourceZ set_filenameResetColorizerupdate_recent_files_listload_extensionsmenudictgetindex add_separator wmenu_endZregister_callbackpostwindowsmenu tkMessageBoxaskyesnotkSimpleDialog askinteger showerror_highlight_workaround)r rmfilenamekeyrnZdochomeZpyverZbasepathZchmfileZ currentThemersrxrJZ text_optionsrO fontWeightZ usespacesrrr is_py_srcrHrcrrrr!csN                                            %                zEditorWindow.__init__cstjjdsdS|jjddjddfddjdfdd jdfd d dS) NrEz<>z z<>z csjd}|r|dkritjtjd}jd|jdjd|q|dkrjdddqndS)NselouthiliteZsel_fixinz1.0rc) tag_rangesr GetHighlightrlZ tag_configZ tag_raisetag_add tag_remove)ZfocusZ sel_rangeZ HILITE_CONFIG)rOrr highlight_fixPs   z9EditorWindow._highlight_workaround..highlight_fixcs dS)Nrr)r4)rrrrT]sz4EditorWindow._highlight_workaround..cs dS)Nrr)r4)rrrrT_s)rrg startswithrO event_addr-)r r)rrOrrFs   z"EditorWindow._highlight_workaroundcCs}t|ts| r|Sy|j|jSWnHtk rxy|j|jSWntk rs|jdSYnXYnXdS)z8convert filename to unicode in order to display it in Tkz iso8859-1N) isinstancestrdecoder?UnicodeDecodeErrorr@)r rrrr_filename_to_unicodebs  z!EditorWindow._filename_to_unicodecCs)|jj\}}|jj|dS)NrR)rZdefaultfilenamermnew)r rSr+basenamerrrrqszEditorWindow.new_callbackcCs||jd@dkr&|jdkr&dS|jjdr|jjdddr|jjdddrt|jjdjdd }nR|jjdd}x:tt |D]}||dkrPqqWt |}t|jjd jdd }||krd}nd t |d}|jd @dkr\|jj dddn|jjds|jj dd nY|jj|jjdd|jjd r|jj ddn|jj dd|jj|}|jjd}|jj|d|r)||}}n|jj ddd|jj d|||jj d ||jjd dS)NrZHomeZiomarkz<=zinsert lineendzinsert linestart.rU  insertzinsert linestart+crz1.0rcz sel.firstZ my_anchorrR)rr)stateZkeysymrOrcomparerNsplitrrangelenrrmark_setrsee)r rSZinsertptlineZlineatdestfirstlastrrrrvs@"( %  zEditorWindow.home_callbackcCs|j|j|_tjdkr@|jjdddtn|jjdddt|jjdddt|jjdtd t |j j d |j |j j d d d |j j|j dS) NrFZ _padding1z rWcolumnzCol: ?rzLn: ?rXz<>z z)rCrs status_barrrg set_labelrrZBOTTOMXrOr-set_line_and_columnrZ after_idle)r rrrrs  zEditorWindow.set_status_barcCsS|jjtjd\}}|jjdd||jjdd|dS)NrrzCol: %srzLn: %s)rOrZINSERTrrr)r rSrrrrrrs!z EditorWindow.set_line_and_columnfile_Fileedit_EditformatF_ormatrun_Runoptions_Optionsrb_Windowhelp_HelpcCs#|j}i|_}x_|jD]T\}}t|\}}t|d|||<}|jd|d|d|q Wtjrt|dd|d<}|jddd|n|jt|j|_ |jdj d dd dd d|j |jd j t |_ |jdS) NrIlabelrH underlineZappleZ applicationZIDLErrDz Recent Filesrr)rrr menu_specsprepstrrqZ add_cascaderZ isCarbonTk fill_menusrecent_files_menuZinsert_cascaderENDbase_helpmenu_lengthreset_help_menu_entries)r ZmbarrrIr r rHrrrrzs       zEditorWindow.createmenubarcCsk|jd}|jd}|dkr1d}n||jkrZ|j|jd|ntj|dS)NrbrcrUrd)rrrdeleterZadd_windows_to_menu)r rHrcrrrrs   zEditorWindow.postwindowsmenuc Cs,|jjdd|j|jf|js9|jn|j}||_tjdddk}|r|jj ddnxs|j D]h}y|\}}}Wnt k rwYnX|dkrqnt ||}|j |d|qW|j|j|j|r(|jj ddndS) Nrz@%d,%drDrEcursorZarrowrZibeam)rOrxyrmenu make_rmenurSrrgr rmenu_specs ValueErrorgetattrZentryconfigureZtk_popupZx_rootZy_root) r rSrZiswinitemr  eventnameZ verify_staterrrrr~s(#      zEditorWindow.right_menu_eventClose<>cCst|jdd}xj|jD]_}|d|d}}|dk rt|j|dd}|jd|d|q|jqW||_dS)NZtearoffrrUcSs|j|dS)N)event_generate)rOrrrrrVsz(EditorWindow.make_rmenu..commandr rV)rqrOr add_commandrr)r rrr rrVrrrrs zEditorWindow.make_rmenucCs |jS)N)rmenu_check_copy)r rrrrmenu_check_cut szEditorWindow.rmenu_check_cutc CsAy|jjd}Wntk r.dSYnX|r9dSdSdS)Nz sel.firstdisabledrY)rOrTclError)r Zindxrrrr! s   zEditorWindow.rmenu_check_copyc CsAy |jjjd|jdWntk r8dSYnXdSdS)Nztk::GetSelectionZ CLIPBOARDr#rY)rOtkcallr$)r rrrrmenu_check_pastes    zEditorWindow.rmenu_check_pastecCstj|jddS)Nz About IDLE)r Z AboutDialogrs)r rSrrrrszEditorWindow.about_dialogcCstj|jddS)NZSettings)r Z ConfigDialogrs)r rSrrrrszEditorWindow.config_dialogcCstj|jdS)N)r ZConfigExtensionsDialogrs)r rSrrrr!sz%EditorWindow.config_extensions_dialogcCs8|jr|j}n |j}tj|d|jdS)Nr$)rnrsr8r%)r rSrrrrr$s   zEditorWindow.help_dialogcCstjdddkr}ytj|jWqtk ry}z*tjdddt|d|j WYdd}~XqXnt j |jdS)NrDrEtitlezDocument Start FailuremessagerrR) rrgr' startfilereOSErrorrrrrO webbrowseropen)r rSwhyrrrr+s,zEditorWindow.python_docscCs|jjddS)Nz<>rR)rOr)r rSrrrr6szEditorWindow.cutcCs*|jjdsdS|jjddS)Nrz<>rR)rOrr)r rSrrrr:szEditorWindow.copycCs$|jjd|jjddS)Nz <>rrR)rOrr)r rSrrrrAszEditorWindow.pastecCs=|jjddd|jjdd|jjddS)Nrz1.0zend-1crrR)rOrrr)r rSrrrrFszEditorWindow.select_allcCs*|jjddd|jjddS)Nrz1.0rcr)rOrr)r rSrrrrLszEditorWindow.remove_selectioncs=|jj|jjdfdd}|S)zCursor move begins at start or end of selection When a left/right cursor key is pressed create and return to Tkinter a function which causes a cursor move from the associated edge of the selection. sel.first+1c sel.last-1cc sN|jd@dkrJyddWqJtk rFYqJXndS)NrPrz sel.firstr)rr$)rS) edge_index edges_tableself_text_indexself_text_mark_setrr move_at_edge[s   z.move_at_edge)r/r0)rOrr)r r1r5r)r1r2r3r4rrPs   z&EditorWindow.move_at_edge_if_selectioncCs|jjddS)Nz rR)rOr)r rSrrrrdszEditorWindow.del_word_leftcCs|jjddS)NzrR)rOr)r rSrrrrhszEditorWindow.del_word_rightcCstj|jdS)NrR)rfindrO)r rSrrrrlszEditorWindow.find_eventcCstj|jdS)NrR)rZ find_againrO)r rSrrrrpszEditorWindow.find_again_eventcCstj|jdS)NrR)rZfind_selectionrO)r rSrrrrtsz!EditorWindow.find_selection_eventcCs tj|j|j|jdS)NrR)rZgreprOrrm)r rSrrrrxsz EditorWindow.find_in_files_eventcCstj|jdS)NrR)rreplacerO)r rSrrrr|szEditorWindow.replace_eventcCsp|j}tjddd|}|dkr1dS|dkrK|jdS|jdd||jddS)NZGotozGo to line number:rrRrrz%d.0)rOrrbellrr)r rSrOlinenorrrrs     zEditorWindow.goto_line_eventc!Csy|jjdd}Wntk r3d}Yn X|j}tjddd|jd|}|rv|j}n|sdSytjj|}WnNt t fk r}z(t j dt |d|jdSWYdd}~XnX|dkrt j dd d|jdSt|jtjjsEt j dd d|jdSy|jj|}Wn/tk rt j dd d|jdSYnX|jr|jj|n|jj||S) Nz sel.firstzsel.lastZModulezAEnter the name of a Python module to search on sys.path and open:r initialvaluez Import errorzmodule not foundznot a source-based modulez$loader does not support get_filename)rOrr$striprZ askstring importlibutil find_specr ImportErrorrrrrloaderabc SourceLoader get_filenamerprmr-rr)r rSrIspecmsgZ file_pathrrrrsH            zEditorWindow.open_modulecCs|jj}|jjdko!|sC|j}|dkrCdSntjj|\}}tjj|\}}ddl m }|j |j ||gdS)NZPyShellEditorWindowr) ClassBrowser) rr __class__r5rr'r(rsplitextidlelibrGrm)r rSrheadtailbaseextrGrrrrs   zEditorWindow.open_class_browsercCs$ddlm}|j|jdS)Nr) PathBrowser)rJrOrm)r rSrOrrrrszEditorWindow.open_path_browsercCs7ddl}tjddg}|j|dd}dS)Nrz-cz,from turtledemo.__main__ import main; main()shellF) subprocessr executablePopen)r rSrQcmdprrrrs   zEditorWindow.open_turtle_democCsl|dk rh|dkrh|jjdd||jjddd|jjddd|jndS)Nrrz%d.0rz1.0rcz insert +1l)rOrrrcenter)r r9rrrgotolines zEditorWindow.gotolinecCs| stjj|rdStjjtjj|\}}tjj|dkr]dS|jjdd}|jdod|kS) NT.py.pywz1.0z 1.0 lineendz#!Zpython)rXrY) r'r(rirIrnormcaserOrr)r rrMrNrrrrrs$zEditorWindow.ispythonsourcecCs)|jr%|jj|d|_ndS)N)rmZunregister_maybe_terminate)r rrr close_hooks zEditorWindow.close_hookcCs ||_dS)N)r[)r r[rrrset_close_hookszEditorWindow.set_close_hookcCsD|jr|jj|n|j|jj||jdS)N)rmZfilename_changed_editrrsZupdate_windowlist_registryr)r rrrrs   z!EditorWindow.filename_change_hookcCs}|jr dS|j|jjr4|j|_n|jry|jj|j|jj|j|jj|jndS)N) rrrrr<r removefilterrr)r rrr _addcolorizers  zEditorWindow._addcolorizercCs:|js dS|jj|jj|jd|_dS)N)rZ removecolorsrr])r rrr _rmcolorizers   zEditorWindow._rmcolorizerc Cs|j|jtjddd}tj|d}tj|ddd}tj|d}|jjd |d d |d d |d |d d |d dS)zUpdate the color themerKZThemerIrYrZfgBgZfgrZ foregroundZ backgroundZinsertbackgroundZselectforegroundZselectbackgroundN)r_r^r ryrrOr)r ZthemeZ normal_colorsZ cursor_colorZ select_colorsrrrrs      zEditorWindow.ResetColorizer_cCs|jd||j|}|rN||jkrN|jd|d|nd|j|krv|jd|n|jd|d|j|dS)NZERRORz wordstart rz+1c)rr IDENTCHARSrr)r rOposcharrrrcolorize_syntax_errorsz"EditorWindow.colorize_syntax_errorc Csnd}tjdddddr*d}n|jjdtjdddtjddd dd |fd S) z.Update the text widgets' font if it is changedrYrKr:z font-boldrMrZr[r\z font-sizerNN)r ryrOr)r rrrr ResetFonts zEditorWindow.ResetFontcCstj|j_}x-|jD]\}}|jj||q#Wx\|jD]N}tj|}|rSx0|jD]\}}|jj||q{WqSqSWdS)z/Remove the keybindings before they are changed.N) r GetCurrentKeySetrAdefault_keydefsitemsrOZ event_deleteget_standard_extension_namesGetExtensionBindings)r keydefsrSkeylist extensionNamexkeydefsrrrRemoveKeybindings)szEditorWindow.RemoveKeybindingsc Cstj|j_}|jx9|jD]+}tj|}|r-|j|q-q-Wi}xd|jjD]V}i||d|D]3}|j|d}|j d|dd|qhWn||jdEditorWindow.__extra_help_callback..display_extra_helpr)r ryrzr)r rZ__extra_help_callbackqs z"EditorWindow.__extra_help_callbackcsqg}tjj|jrQt|jddddd}|j}WdQXn|rtjj|d}||kr|j|n|jd|ngxG|D]?}d |kstjj|dd rj |qqWfd d |D}d }|dt |}y8t|jddddd}|j |WdQXWnrt k r}zRt |jddsd|j_tjddddt|d|jnWYdd}~XnXx|jjD]}|j} | jdtxlt|D]^\} } | j} |j| } |j| } | jd|| d| d| ddqWqWdS)z/Load and update the recent files list and menusrr@utf_8errorsr7NrarrUcs"g|]}|kr|qSrr).0r() bad_pathsrr s z9EditorWindow.update_recent_files_list..Z1234567890ABCDEFGHIJKwrecentfilelist_error_displayedFTr(z IDLE Errorr)z&Unable to update Recent Files list: %srr rrVr rd)r'r(rrwr- readlinesr*removerappendr writelinesr+rrnrrrrrOrsrvrrr enumeraterstripr#_EditorWindow__recent_file_callbackr )r new_fileZrf_listZ rf_list_filer(ZulcharsZrf_fileerrinstancerHi file_nameZ ufile_namecallbackr)rrrsL  )     z%EditorWindow.update_recent_files_listcs|fdd}|S)Ncsjjd|dS)NZeditFile)rr-)Z fn_closure)r rropen_recent_filesz=EditorWindow.__recent_file_callback..open_recent_filer)r rrr)r rZ__recent_file_callbacksz#EditorWindow.__recent_file_callbackcCs|j}|j}|r9|r9|d|t}n$|rH|}n|rW|}nd}|pl|pl|}|jsd|}d|}n|jj||jj|dS)Nz - Untitledz*%s*z*%s) short_title long_title _py_version get_savedrsZwm_titleZ wm_iconname)r ZshortZlongr(Ziconrrrrs        zEditorWindow.saved_change_hookcCs |jjS)N)rr)r rrrrszEditorWindow.get_savedcCs|jj|dS)N)r set_saved)r ZflagrrrrszEditorWindow.set_savedcCs|jjdS)N)r reset_undo)r rrrrszEditorWindow.reset_undocCs:|jj}|r'tjj|}nd}|j|S)Nr)rrr'r(rr)r rrrrrs  zEditorWindow.short_titlecCs|j|jjpdS)Nr:)rrr)r rrrrszEditorWindow.long_titlecCs|jdS)N)rV)r rSrrrrsz EditorWindow.center_insert_eventrcCsb|j}|j\}}|j|}||}td||d}|jt|dS)NrUrG)rOgetwindowlines getlinenomaxrfloat)r markrOrsbotr9rQZnewtoprrrrVs   zEditorWindow.centercCsp|j}|jd}|jd}||krf|jdkrft|d}||d}n||fS)Nz@0,0z@0,65535rUrQ)rOrZ winfo_heightrN)r rOrsrrQrrrrs zEditorWindow.getwindowlinescCs"|j}tt|j|S)N)rOrNrr)r rrOrrrrs zEditorWindow.getlinenocCs:|jj}tjd|}ttt|jS)zReturn (width, height, x, y)z(\d+)x(\d+)\+(-?\d+)\+(-?\d+))rsZ wm_geometryrematchlistmaprNgroups)r r3mrrr get_geometryszEditorWindow.get_geometrycCs|jdS)N)r|)r rSrrrr}szEditorWindow.close_eventcCsh|jrd|jsW|jjdkr:|jjn|jj|jjn|jjSdS)NrY)rrrsrr1lowerr2 maybesave)r rrrrs   zEditorWindow.maybesavecCs/|j}t|dkr+|jn|S)NZcancel)rr_close)r Zreplyrrrr|s  zEditorWindow.closecCs|jjr%|jd|jjntj|j|j|jjd|_d|_|j r|j jdd|_ nd|_ d|_ |j jd|_ |j j|jr|jndS)NrF)rrrrZunregister_callbackrunload_extensionsr|rrrOrurrsr.r[)r rrrr s"             zEditorWindow._closecCsi|_|jdS)N) extensionsload_standard_extensions)r rrrrs zEditorWindow.load_extensionscCsIx9t|jjD]"}t|dr|jqqWi|_dS)Nr|)rrvalueshasattrr|)r insrrrr"szEditorWindow.unload_extensionsc CsTxM|jD]?}y|j|Wq tdt|tjYq Xq WdS)NzFailed to load extension)rjload_extensionprintrepr traceback print_exc)r rIrrrr(s z%EditorWindow.load_standard_extensionscCstjddS)NZ editor_onlyT)r Z GetExtensions)r rrrrj0sz)EditorWindow.get_standard_extension_namescCsyKytjd|dt}Wn'ttfk rItj|}YnXWn"tk rotd|YnXt||}tj|}t |dr|j |j |n||}||j |<|r|j |x|D]}|jdd}x*|dddkr*|dd}qWx*|d dd krW|dd }q.W|d }t ||r|jj|t||qqWndS) Nrpackagez Failed to import extension: rr-r`rUrrZ_eventrdrd)r= import_module __package__r@ TypeErrorrrr rkrr rrrr{r7rOr-)r rImodclsrlrZveventZ methodnamerrrr3s2       zEditorWindow.load_extensioncCsg|dkr|jj}n|j}||_x3|jD]%\}}|r:|j||q:q:WdS)N)rArhrOrlrir)r rlrOrSrmrrrr{Ns   zEditorWindow.apply_bindingsc Csu|dkr|jj}n|dkr6|jj}n|j}|j}x&|D]\}}|j|}|svqOnx|D]}|s|jq}|\} } | dddk} | r| dd} nt| \} } t|| } || dd}| rG|j | t }|j d| d| d|d | d |q}|j d| d| d|d | q}WqOWdS) zAdd appropriate entries to the menus and submenus Menus that are absent or None in self.menudict are ignored. NrU!cSs|j|dS)N)r)rOrrrrrVpsz(EditorWindow.fill_menus..commandr r rVrqZvariable) rArrrhrrOrrr rs get_var_objZ BooleanVarZadd_checkbuttonr )r rrrlrrOZmnameZ entrylistrHrvr rZ checkbuttonr rqrVvarrrrr Ws8         zEditorWindow.fill_menuscCs5|j|}|r%|j}|St|dS)N)rr NameError)r rIrvaluerrrgetvar|s  zEditorWindow.getvarcCs8|j||}|r(|j|n t|dS)N)rrr)r rIrvartyperrrrsetvarszEditorWindow.setvarcCs@|jj|}| r<|r<||j|j|<}n|S)N)rurrO)r rIrrrrrrs zEditorWindow.get_var_objcCs<|jr4|jjd|p3d|jj|kSdSdS)NZTODOSTRINGrU)rrO tag_prevrangeZ tag_names)r Z text_indexrrris_char_in_strings zEditorWindow.is_char_in_stringc CsOy2|jjd}|jjd}||fSWntk rJdSYnXdS)Nz sel.firstzsel.last)NN)rOrr$)r rrrrrget_selection_indicess  z"EditorWindow.get_selection_indicescCs|jdpt}t|S)Ntabs)rOTK_TABWIDTH_DEFAULTrN)r Zcurrentrrrget_tk_tabwidthszEditorWindow.get_tk_tabwidthcCs^|j}|j|krZ|jjdd|dd|jd|}|jd|ndS)Nr\Zmeasurez -displayofnr)rOrr%r&ZmasterZ configure)r Z newtabwidthrOZpixelsrrrset_tk_tabwidths    zEditorWindow.set_tk_tabwidthTcCsu|ra|ra|j}d|ko/dknr@||_n|j|jkrad|_qan|j|jdS)NrGrF) guess_indentrrrr)r rZguessrrrrrs   z#EditorWindow.set_indentation_paramsc Cs|j}|j\}}|rK|rK|j|||jd|dS|jdd}|dkr|jdddr|jdn |jdS|dd kr|jddS|j}t|j |}|d kst |d|j |j }|j r't jjd d} nd} d } xc|| krFPn|dd}| d} t|j |}||ks|dd kr6Pq6q6W|j|jd | d||kr|jdd ||n|jdS)NrrRzinsert linestartr:rz1.0z insert-1crUz rraz insert-%dcrrdrdrdrd)rOrrrrrr8rr expandtabsAssertionErrorrrrrorrrr) r rSrOrrcharsrZhaveZwantlast_line_of_promptZ ncharsdeletedrrrrsJ            z"EditorWindow.smart_backspace_eventc CsH|j}|j\}}|jz|r||r|t|t|krY|j|S|j|||jd|n|jdd}t||j \}}|t |kr|j ||j nU|j rd}n3t |j|j }|j } d| || }|jd||jddSWd|jXdS)Nrzinsert linestartrrrR)rOrr index2linerrrr classifywsrr reindent_torrrrrr) r rSrOrrprefixraw effectiveZpadrrrrrs,        zEditorWindow.smart_indent_eventc Cs|j}|j\}}|jz|rW|rW|j|||jd|n|jdd}dt|}}x*||kr||dkr|d}qW||kr|jdddS|d|}d}tj j dd } x@|r7|ddkr7|| kr7|dd}|d}qW|rU|jd|dnx&|jddkr}|jdqXW|jddt |j d} t j|j|j} |jsjx|jD]} t| | d} t| d }|j|d}| j|| j|j|j|}|dk sL| dkrPqqW| j|pcdnW|jd d}|r|d}nd }|j|d}| j|| jd| j}|t jkr|t jkrn|t jkr|jd|n|t jkr5|j| j nc|t j!kr| j"dkri|jd|q|j| j#ndst$d |fdS| j%}|jd|| j&r|j'|n"|r| j(r|j)|ndSWd|j*d|j+XdS)Nrzinsert linestartrz rUrarRzinsert - %d charsz.0Zconsolez1.0zbogus continuation type %rrdrdrd),rOrrrrrrrrrorrrr ZParserrrrrrrZset_strZfind_good_parse_start_build_char_in_string_funcZset_lorZget_continuation_typeZC_NONEZC_STRING_FIRST_LINEZC_STRING_NEXT_LINESZ C_BRACKETrZcompute_bracket_indentZ C_BACKSLASHZget_num_lines_in_stmtZcompute_backslash_indentrZget_base_indent_stringZis_block_openerrZis_block_closerrrr)r rSrOrrrrrindentrZlnorcontextZstartatZ startatindexZrawtextZbodr{rrrrrs    %         z%EditorWindow.newline_and_indent_eventcCs||jdd}|S)NcSs||d|S)Nz+%dcr)offsetZ _startindexZ_icisrrrinnersz6EditorWindow._build_char_in_string_func..inner)r)r Z startindexrrrrrsz'EditorWindow._build_char_in_string_funcc Cs|j\}}}}xstt|D]_}||}|r+t||j\}} | |j} |j| ||d||r?r@rJrAtkinterrBZidlelib.MultiStatusBarrCrer!rrrrrrr rzrrr~rrr"r!r'rrrrrrrrrrrrrrrrrrrrrrrrWrr[r\rr^r_rstringZ ascii_lettersZdigitsrbrerfrprtrrrurrrrrrrrrrVrrrr}rr|rrrrrjrr{r rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr:Xs     +                     +        $   ,                  %    0 # k      r:cCstt|S)N)rNr)rrrrr8srcCstd}}x]|D]U}|dkr:|d}|d}q|dkre|d}||d|}qPqW||fS)NrrrUrr)srrrZchrrrr@s       rc@sOeZdZddZddZejejdd d Zd dZ dS)rcCs6||_||_d|_|_d|_|_dS)Nr)rOrrfinished blkopenline indentedline)r rOrrrrr!Xs  zIndentSearcher.__init__cCsd|jr dS|jd}|_t|d}|jj|ddrMdS|jj||dS)Nr:rUz.0z>=rcz lineend+1c)rrrrOrr)r rrrrrreadline^s zIndentSearcher.readlineclassdefforiftrywhilec Cs^|jr nN||kr0||kr0||_n*||krZ|jrZ||_d|_ndS)NrU)rrr) r rMtokenstartrcrINDENTNAMEZOPENERSrrr tokeneatergs   zIndentSearcher.tokeneatercCstj}|jt_zVy4tj|j}x|D]}|j|q4WWntjtfk riYnXWd|t_X|j|j fS)N) _tokenizetabsizergenerate_tokensrr TokenError SyntaxErrorrr)r Z save_tabsizetokensrrrrrss     zIndentSearcher.runN)zclasszdefzforzifztryzwhile) r5r6r7r!rrrrrrrrrrrQs    rcCsJ|jd}|dkr@|d|||dd}n||fS)Nr`rrU)r6)rrrrrr s %r [Z bracketleft]Z bracketright/ZslashcCs |j|}| s.tjr2|dkr2dS|d}tjddd|}tjd d d|}tjd d|}tjd d |}tjdd|}tjdd|}tjdd|}tjdd|}tjdd|}|S)N<> <><>r:rz-[a-z]\bcSs|jjS)N)groupupper)rrrrrTsz!get_accelerator..z\b\w+\bcSstj|j|jS)N)keynamesrr )rrrrrTszKey-ZCancelz Ctrl-BreakzControl-zCtrl-rr&z>r r r )rrZ isCocoaTkrsub)rlrrmrrrrrss"  rscCsF|j}|jddd|jddd|jddddS) NZtcl_wordBreakAfterza brrZ tcl_wordcharsz [a-zA-Z0-9_]Ztcl_nonwordcharsz [^a-zA-Z0-9_])r%r&)rnr%rrr fixwordbreakss rcCsx|}t|tjddr3tjd}nd}tj|dtd|d|}|jjd|jdS)NrUrnrz<>) rrargvrZsetupAppr:rOr-r})rrnrrrrr_editor_windows r__main__)r)6r=Z importlib.abcimportlib.utilr'rgrrrrZtkinter.simpledialogZ simpledialogrZtkinter.messageboxZ messageboxrrr,Zidlelib.MultiCallrrJrrrrrr Zidlelib.configHandlerr r r r rrZpython_versionrrobjectrr8r9r:rrtokenizerrr rrsrrr5Zidlelib.idle_test.htestrrrrrsf            (    4