3  f@sdZddlZddlmZddlmZddlmZdddd d gZda d d Z d dZ GdddeZ GdddZ edkrddlmZedddddS)z0Editor window that can serve as an output file. N) 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|]}tj|tjqS)recompile IGNORECASE).0Zpatrr3/opt/alt/python36/lib64/python3.6/idlelib/outwin.py sz!compile_progs..N)file_line_patsfile_line_progsrrrr compile_progssrc Csts tx^tD]R}|j|}|r|jdd\}}yt|d}|jPWqtk 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. rN) r rsearchgroupopencloseOSErrorint TypeError)lineprogmatchfilenamelinenofrrr file_line_helpers"     rc@sneZdZdZd!d"d#d$d%gZddZddZddZddZfdfddZ ddZ ddZ ddZ d&dd Z d S)' 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. Cut<>rmenu_check_cutCopy<>rmenu_check_copyPaste <>rmenu_check_pasteNGo to file/line<>cGs0tj|f||jjd|j|jjddS)Nz<>z<>)r__init__textZbindgoto_file_lineZunbind)selfargsrrr r,MszOutputWindow.__init__cCsdS)z6Python source is only part of output: do not colorize.Fr)r/rrrr ispythonsourceSszOutputWindow.ispythonsourcecCsdS)zCustomize EditorWindow title.ZOutputr)r/rrr short_titleWszOutputWindow.short_titlecCs|jr dSdS)z;Customize EditorWindow to not display save file messagebox.yesno)Z get_saved)r/rrr maybesave[szOutputWindow.maybesaveinsertcCsFt|tr|jtjd}|jj||||jj||jjt |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. replace) isinstancebytesdecoderencodingr-r6Zseeupdatelen)r/stagsmarkrrr write`s    zOutputWindow.writecCsx|D]}|j|qWdS)z"Write each item in lines iterable.N)rA)r/linesrrrr writelinesws zOutputWindow.writelinescCsdS)z8No flushing needed as write() directly writes to widget.Nr)r/rrr flush|szOutputWindow.flushcOstj||dS)N)r showerror)r/r0kwargsrrr rEszOutputWindow.showerrorcCsd|jjdd}t|}|sJ|jjdd}t|}|sJ|jdd|jddS|\}}|jj||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.)parentN)r-getrrEflistZ gotofileline)r/Zeventrresultrrrrr r.s  zOutputWindow.goto_file_line)r!r"r#)r$r%r&)r'r(r))NNN)r*r+N)N)__name__ __module__ __qualname____doc__Z rmenu_specsr,r1r2r5rArCrDrEr.rrrr r ;sr c@s6eZdZddiddidZddZddZd d Zd S) OnDemandOutputWindowZ foregroundZbluez#007700)stdoutstderrcCs||_d|_dS)N)rIowin)r/rIrrr r,szOnDemandOutputWindow.__init__cCs"|js|j|jj|||dS)N)rRsetuprA)r/r>r?r@rrr rAszOnDemandOutputWindow.writecCsXt|j|_}|j}x(|jjD]\}}|r"|j|f|q"W|jd|jj|_dS)NZsel) r rIrRr-tagdefsitemsZ tag_configureZ tag_raiserA)r/rRr-tagZcnfrrr rSs zOnDemandOutputWindow.setupN)rKrLrMrTr,rArSrrrr rOs  rO__main__)mainzidlelib.idle_test.test_outwinrF) verbosityexit)rNrZtkinterrZidlelib.editorrZidlelibrr r rrr rOrKZunittestrXrrrr s"   e