a
    zeM                     @   s   d dl Z d dlmZ d dlmZ g dZdadd Zdd ZG d	d
 d
eZ	G dd dZ
edkr|d dlmZ edddd dS )    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                   C   s   dd t D ad S )Nc                 S   s   g | ]}t |t jqS  )recompile
IGNORECASE).0patr   r   $/usr/lib/python3.9/idlelib/outwin.py
<listcomp>   s   z!compile_progs.<locals>.<listcomp>)file_line_patsfile_line_progsr   r   r   r
   compile_progs   s    r   c              	   C   s   t s
t  t D ]V}|| }|r|dd\}}zt|d}|  W  qjW q tyb   Y qY q0 qd S z|t|fW S  ty   Y d S 0 d S )N      r)	r   r   searchgroupopencloseOSErrorint	TypeError)lineprogmatchfilenamelinenofr   r   r
   file_line_helper   s"    


r   c                   @   sd   e Zd Zg dZdZdd Zdd Zdd Zd	d
 ZdddZ	dd Z
dd Zdd ZdddZdS )OutputWindow))ZCutz<<cut>>Zrmenu_check_cut)ZCopyz<<copy>>Zrmenu_check_copy)ZPastez	<<paste>>Zrmenu_check_paste)NNN)zGo to file/line<<goto-file-line>>NFc                 G   s&   t j| g|R   | jd| j d S )Nr!   )r   __init__textbindgoto_file_line)selfargsr   r   r
   r"   N   s    zOutputWindow.__init__c                 C   s   dS )NFr   )r&   r   r   r   r
   ispythonsourceS   s    zOutputWindow.ispythonsourcec                 C   s   dS )NZOutputr   r&   r   r   r
   short_titleW   s    zOutputWindow.short_titlec                 C   s   |   rdS dS )NZyesno)Z	get_savedr)   r   r   r
   	maybesave[   s    zOutputWindow.maybesaver   insertc                 C   s.   | j ||| | j | | j   t|S N)r#   r-   Zseeupdatelenr&   stagsZmarkr   r   r
   write`   s    
zOutputWindow.writec                 C   s   |D ]}|  | qd S r.   )r4   )r&   linesr   r   r   r
   
writelinesv   s    zOutputWindow.writelinesc                 C   s   d S r.   r   r)   r   r   r
   flush{   s    zOutputWindow.flushc                 O   s   t j|i | d S r.   )r   	showerror)r&   r'   kwargsr   r   r
   r8      s    zOutputWindow.showerrorNc                 C   sd   | j dd}t|}|sJ| j dd}t|}|sJ| jdd| j d d S |\}}| j|| d S )Nz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.)parent)r#   getr   r8   flistZgotofileline)r&   eventr   resultr   r   r   r   r
   r%      s     	zOutputWindow.goto_file_line)r   r-   )N)__name__
__module____qualname__Zrmenu_specsZallow_code_contextr"   r(   r*   r,   r4   r6   r7   r8   r%   r   r   r   r
   r    :   s   

r    c                   @   s6   e Zd ZddiddidZdd Zdd Zd	d
 ZdS )OnDemandOutputWindowZ
foregroundZbluez#007700)stdoutstderrc                 C   s   || _ d | _d S r.   )r<   owin)r&   r<   r   r   r
   r"      s    zOnDemandOutputWindow.__init__c                 C   s"   | j s|   | j ||| d S r.   )rE   setupr4   r1   r   r   r
   r4      s    zOnDemandOutputWindow.writec                 C   sX   t | j | _}|j}| j D ]\}}|r |j|fi | q |d | jj| _d S )NZsel)	r    r<   rE   r#   tagdefsitemsZtag_configureZ	tag_raiser4   )r&   rE   r#   tagZcnfr   r   r
   rF      s    
zOnDemandOutputWindow.setupN)r?   r@   rA   rG   r"   r4   rF   r   r   r   r
   rB      s   rB   __main__)mainzidlelib.idle_test.test_outwinr   F)	verbosityexit)r   tkinterr   Zidlelib.editorr   r   r   r   r   r    rB   r?   ZunittestrK   r   r   r   r
   <module>   s   	e