[y@sdZddlZddlZddlZddlZddlZddljZddl m Z ddl m Z m Z ddlmZddl mZdZGdd d ZdS) a?Extension to execute code outside the Python shell window. This adds the following commands: - Check module does a full syntax check of the current module. It also runs the tabnanny to catch any inconsistent tabs. - Run module executes the module's code in the __main__ namespace. The window must have been saved previously. The module is added to sys.modules, and is also added to the __main__ namespace. XXX GvR Redesign this interface (yet again) as follows: - Present a dialog box for ``Run Module'' - Allow specify command line arguments in the dialog box N) EditorWindow)PyShell IOBinding)idleConf) macosxSupporta/Error: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR 2) Your indentation mixes tabs and spaces. To fix case 2, change all tabs to spaces by using Edit->Select All followed by Format->Untabify Region and specify the number of columns used by each tab. c@seZdZddddgfgZddZd d Zd d Zd dZddZddZ ddZ ddZ ddZ dS) ScriptBindingZrunN Check Module<> Run Module<>cCsS||_|jj|_|jj|_tjrO|jjjd|jndS)Nz<>)editwinflistrootr isCocoaTk text_frameZbind_run_module_event)selfr r+/usr/lib/python3.4/idlelib/ScriptBinding.py__init__1s   zScriptBinding.__init__cCs@|j}|sdS|j|s)dS|j|s<dSdS)Nbreak) getfilename checksyntaxtabnanny)reventfilenamerrrcheck_module_event;s z ScriptBinding.check_module_eventcCstj|}ytjtj|jWntjk r}z?|\}\}}|jj||j dd|dSWYdd}~XnRtj k r}z/|jj|j |j dt dSWYdd}~XnXWdQXdS)NzTabnanny Tokenizing ErrorzToken Error: %sFzTab/space errorT) tokenizeopenrZprocess_tokensgenerate_tokensreadline TokenErrorr ZgotolineerrorboxZNannyNagZ get_linenoindent_message)rrfmsgZmsgtxtlinenostartZnagrrrrDs  zScriptBinding.tabnannyc Cs|jj|_}|j}|j|jt|d}|j}WdQXd|kr|jdd}|jdd}n|r|dt dkr|d}n|j }|j }|j dddzyt ||d SWntttfk r}zt|d d p'|p'd } t|d d p?d} t|dd pWd} | dkrs| d7} nd| d| df} |j|| |jdd| dSWYdd}~XnXWd|j|XdS)Nrbs s s ZERRORz1.0endexecr%zr&offsetrz0.0 + %d lines + %d chars SyntaxErrorz%-20sF)r Z open_shellshellZget_warning_streamZset_warning_streamstderrrreadreplaceordr textZ tag_removecompiler. OverflowError ValueErrorgetattrZcolorize_syntax_errorr") rrr0Z saved_streamr$sourcer r5valuer%r&r-posrrrrVs4       zScriptBinding.checksyntaxcsCtjr2jjjdfdddSj|SdS)NcsjjjdS)Nz<>)r rZevent_generater)rrr|sz0ScriptBinding.run_module_event..r)rrr rZafterr)rrr)rrrun_module_eventts  zScriptBinding.run_module_eventcCs|j}|sdS|j|}|s/dS|j|sBdS|jj}tjrj|jddntj j |}|j dj d|d||j ||j|dS)aXRun the module after setting up the environment. First check the syntax. If OK, make sure the shell is active and then transfer the arguments, set the run environment's working directory to the directory of the module being executed and also add that directory to its sys.path if not already included. rZwith_cwdFazif 1: __file__ = {filename!r} import sys as _sys from os.path import basename as _basename if (not _sys.argv or _basename(_sys.argv[0]) != _basename(__file__)): _sys.argv = [__file__] import os as _os _os.chdir({dirname!r}) del _sys, _basename, _os rdirname)rrrr0interprZuse_subprocessZrestart_subprocessospathr@Z runcommandformatZprepend_syspathZruncode)rrrcoderAr@rrrrs"      zScriptBinding._run_module_eventcCs|jjj}|jjstjddddd}|r[|r[|jjjdq|j}|jjj |r|jjjd|jjj}qd}n|S)aGet source filename. If not saved, offer to save (or create) file The debugger requires a source file. Make sure there is one, and that the current version of the source buffer has been saved. If the user declines to save or cancels the Save As dialog, return None. If the user has configured IDLE for Autosave, the file will be silently saved if it already exists and is dirty. mainZGeneralautosavetypeboolN) r iorZ get_savedrZ GetOptionZsaveask_save_dialogr5 focus_set)rrrGconfirmrrrrs     zScriptBinding.getfilenamec Cs?dd d}tjddd|dtjd |jj}|S) NzSource Must Be Saved  z OK to Save?titlezSave Before Run or Checkmessagedefaultmasterz ) tkMessageBoxZ askokcancelZOKr r5)rr%rMrrrrKs  zScriptBinding.ask_save_dialogcCs0tj||d|jj|jjjdS)NrS)rTZ showerrorr r5rL)rrPrQrrrr"szScriptBinding.errorbox)rr )r r ) __name__ __module__ __qualname__Zmenudefsrrrrr?rrrKr"rrrrr*s    (  r)__doc__rBrestringrrZtkinter.messageboxZ messageboxrTZidlelib.EditorWindowrZidlelibrrZidlelib.configHandlerrrr#rrrrrs