
    dR                         d Z ddlZddlmZ ddlmZ g dZdad Zd Z	 G d d	e          Z
 G d
 d          Zedk    rddlmZ  eddd           dS dS )z0Editor window that can serve as an output file.
    N)
messagebox)EditorWindow)zfile "([^"]*)", line (\d+)z([^\s]+)\((\d+)\)z^(\s*\S.*?):\s*(\d+):z([^\s]+):\s*(\d+):z^\s*(\S.*?):\s*(\d+):c                  (    d t           D             adS )z?Compile the patterns for matching to file name and line number.c                 L    g | ]!}t          j        |t           j                  "S  )recompile
IGNORECASE).0pats        /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/idlelib/outwin.py
<listcomp>z!compile_progs.<locals>.<listcomp>   s6     2 2 2 z#r}55 2 2 2    N)file_line_patsfile_line_progsr   r   r   compile_progsr      s$    2 2"02 2 2OOOr   c                 V   t           st                       t           D ]h}|                    |           }|rO|                    dd          \  }}	 t	          |          }|                                  n# t          $ r Y dw xY widS 	 |t          |          fS # t          $ r Y dS w xY w)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.
          N)	r   r   searchgroupopencloseOSErrorint	TypeError)lineprogmatchfilenamelinenofs         r   file_line_helperr#      s        D!! 	${{1a00HfNN			   	 tV$$   tts$   #A55
BB	B 
B('B(c                   X    e Zd ZdZg dZdZd Zd Zd Zd Z	dd
Z
d Zd Zd Zdd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.
    ))Cutz<<cut>>rmenu_check_cut)Copyz<<copy>>rmenu_check_copy)Pastez	<<paste>>rmenu_check_paste)NNN)zGo to file/line<<goto-file-line>>NFc                 j    t          j        | g|R   | j                            d| j                   d S )Nr,   )r   __init__textbindgoto_file_line)selfargss     r   r.   zOutputWindow.__init__N   s;    d*T****	+T-@AAAAAr   c                     dS )z6Python source is only part of output: do not colorize.Fr   )r2   r    s     r   ispythonsourcezOutputWindow.ispythonsourceS   s    ur   c                     dS )zCustomize EditorWindow title.Outputr   r2   s    r   short_titlezOutputWindow.short_titleW   s    xr   c                 2    |                                  rdndS )z;Customize EditorWindow to not display save file messagebox.yesno)	get_savedr8   s    r   	maybesavezOutputWindow.maybesave[   s    ((2uud2r   r   insertc                     t          |t                    sJ | j                            |||           | j                            |           | j                                         t          |          S )a  Write 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.
        )
isinstancestrr/   r?   seeupdate_idletaskslenr2   stagsmarks       r   writezOutputWindow.write`   sg      !S!!!!!	q$'''	d	""$$$1vvr   c                 :    |D ]}|                      |           dS )z"Write each item in lines iterable.N)rJ   )r2   linesr   s      r   
writelineszOutputWindow.writelinesv   s0     	 	DJJt	 	r   c                     dS )z8No flushing needed as write() directly writes to widget.Nr   r8   s    r   flushzOutputWindow.flush{   s    r   c                 (    t          j        |i | d S N)r   	showerror)r2   r3   kwargss      r   rR   zOutputWindow.showerror   s    d-f-----r   Nc                 4   | j                             dd          }t          |          }|sK| j                             dd          }t          |          }|s|                     dd| j                    dS |\  }}| j                            ||           dS )	a  Handle 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.
        zinsert linestartzinsert lineendzinsert -1line linestartzinsert -1line lineendzNo special linezTThe line you point at doesn't look like a valid file name followed by a line number.)parentN)r/   getr#   rR   flistgotofileline)r2   eventr   resultr    r!   s         r   r1   zOutputWindow.goto_file_line   s     y}}/1ABB!$'' 	 9==!:!8: :D%d++F %C9	  & & &
 !&
&11111r   )r   r?   rQ   )__name__
__module____qualname____doc__rmenu_specsallow_code_contextr.   r5   r9   r>   rJ   rM   rO   rR   r1   r   r   r   r%   r%   :   s           K B B B
    3 3 3
   ,  
  . . .2 2 2 2 2 2r   r%   c                   2    e Zd ZddiddidZd Zd Zd ZdS )	OnDemandOutputWindow
foregroundbluez#007700)stdoutstderrc                 "    || _         d | _        d S rQ   )rW   owin)r2   rW   s     r   r.   zOnDemandOutputWindow.__init__   s    
			r   c                 t    | j         s|                                  | j                             |||           d S rQ   )rh   setuprJ   rF   s       r   rJ   zOnDemandOutputWindow.write   s7    y 	JJLLL	4&&&&&r   c                     t          | j                  x| _        }|j        }| j                                        D ]\  }}|r |j        |fi | |                    d           | j        j        | _        d S )Nsel)	r%   rW   rh   r/   tagdefsitemstag_configure	tag_raiserJ   )r2   rh   r/   tagcnfs        r   rj   zOnDemandOutputWindow.setup   s    '
333	Dy**,, 	/ 	/HC /""3..#...uY_


r   N)r[   r\   r]   rm   r.   rJ   rj   r   r   r   rb   rb      s_         !&) ), G  ' ' '
% % % % %r   rb   __main__)mainzidlelib.idle_test.test_outwinr   F)	verbosityexit)r^   r   tkinterr   idlelib.editorr   r   r   r   r#   r%   rb   r[   unittestrt   r   r   r   <module>rz      s    
			       ' ' ' ' ' '   2 2 2  8a2 a2 a2 a2 a2< a2 a2 a2J% % % % % % % %4 zD	(AEBBBBBB r   