B /g^c@sdZddlZddlmZddlmZddlmZdddd d gZda d d Z d dZ GdddeZ GdddZ edkrddlmZedddddS)z0Editor window that can serve as an output file. iN) messagebox) EditorWindow)iomenuzfile "([^"]*)", line (\d+)z([^\s]+)\((\d+)\)z^(\s*\S.*?):\s*(\d+):z([^\s]+):\s*(\d+):z^\s*(\S.*?):\s*(\d+):cCsddtDadS)z?Compile the patterns for matching to file name and line number.cSsg|]}t|tjqS)reZcompileZ IGNORECASE)Z.0Zpatrr&/usr/lib64/python3.7/idlelib/outwin.pyz sz!compile_progs..N)file_line_patsfile_line_progsrrrr compile_progssrc Csts tx^tD]R}||}|r|dd\}}yt|d}|PWqtk r`wYqXqWdSy |t|fStk rdSXdS)a-Extract file name and line number from line of text. Check if line of text contains one of the file/line patterns. If it does and if the file and line are valid, return a tuple of the file name and line number. If it doesn't match or if the file or line is invalid, return None. iZrN) rrZsearchZgroupZopenZcloseZOSErrorZintZ TypeError)lineZprogZmatchfilenamelinenoZfrrrfile_line_helpers"     r c@sneZdZdZdddddgZdZdd Zd d Zd d ZddZ dddZ ddZ ddZ ddZ dddZdS) OutputWindowzAn editor window that can serve as an output file. Also the future base class for the Python shell window. This class has no input facilities. Adds binding to open a file at a line to the text widget. )ZCutz<>Zrmenu_check_cut)ZCopyz<>Zrmenu_check_copy)ZPastez <>Zrmenu_check_paste)NNN)zGo to file/line<>NFcGs$tj|f||jd|jdS)Nr)r__init__textZbindgoto_file_line)selfargsrrrrOszOutputWindow.__init__cCdS)z6Python source is only part of output: do not colorize.Fr)rr rrrispythonsourceTzOutputWindow.ispythonsourcecCr)zCustomize EditorWindow title.ZOutputrrrrr short_titleXrzOutputWindow.short_titlecCs|r dSdS)z;Customize EditorWindow to not display save file messagebox.ZyesZno)Z get_savedrrrr maybesave\rzOutputWindow.maybesaverinsertcCsFt|tr|tjd}|j||||j||jt |S)aWrite text to text widget. The text is inserted at the given index with the provided tags. The text widget is then scrolled to make it visible and updated to display it, giving the effect of seeing each line as it is added. Args: s: Text to insert into text widget. tags: Tuple of tag strings to apply on the insert. mark: Index for the insert. Return: Length of text inserted. Zreplace) Z isinstanceZbytesZdecoderZencodingrrZseeZupdateZlenrZsZtagsZmarkrrrwriteas    zOutputWindow.writecCsx|D]}||qWdS)z"Write each item in lines iterable.N)r)rZlinesr rrr writelinesxs zOutputWindow.writelinescCr)z8No flushing needed as write() directly writes to widget.Nrrrrrflush}rzOutputWindow.flushcOstj||dSN)r showerror)rrZkwargsrrrr!szOutputWindow.showerrorNcCsd|jdd}t|}|sJ|jdd}t|}|sJ|jdd|jddS|\}}|j||dS) aHandle request to open file/line. If the selected or previous line in the output window contains a file name and line number, then open that file name in a new window and position on the line number. Otherwise, display an error messagebox. zinsert linestartzinsert lineendzinsert -1line linestartzinsert -1line lineendzNo special linezTThe line you point at doesn't look like a valid file name followed by a line number.)ZparentN)rZgetr r!flistZ gotofileline)rZeventr Zresultr r rrrrs  zOutputWindow.goto_file_line)rrr )__name__ __module__ __qualname____doc__Z rmenu_specsZallow_code_contextrrrrrrrr!rrrrrr;s  rc@s6eZdZddiddidZddZddZd d Zd S) OnDemandOutputWindowZ foregroundZbluez#007700)ZstdoutZstderrcCs||_d|_dSr )r"owin)rr"rrrrszOnDemandOutputWindow.__init__cCs"|js||j|||dSr )r(setuprrrrrrszOnDemandOutputWindow.writecCsXt|j|_}|j}x(|jD]\}}|r"|j|f|q"W|d|jj|_dS)NZsel) rr"r(rtagdefsZitemsZ tag_configureZ tag_raiser)rr(rZtagZcnfrrrr)s zOnDemandOutputWindow.setupN)r#r$r%r*rrr)rrrrr's  r'Z__main__)mainzidlelib.idle_test.test_outwinr F)Z verbosityZexit)r&rZtkinterrZidlelib.editorrZidlelibrrrrr rr'r#Zunittestr+rrrrZs"   f