a
    }Œ@h�  ã                   @   sò   d Z ddlmZmZmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZmZ ddlmZ ddlmZ G dd„ deƒZG dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZddd„Zddd„ZedkrîddlmZ edddd� ddlmZ eeƒ dS )zSimple text browser for IDLE

é    )ÚToplevelÚTextÚTclErrorÚ
HORIZONTALÚVERTICALÚNSÚEWÚNSEWÚNONEÚWORDÚSUNKEN)ÚFrameÚ	ScrollbarÚButton)Ú	showerror)Úcolor_configc                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚAutoHideScrollbarzpA scrollbar that is automatically hidden when not needed.

    Only the grid geometry manager is supported.
    c                    s<   t |ƒdkst |ƒdk r"|  ¡  n|  ¡  tƒ  ||¡ d S )Ng        g      ð?)ÚfloatÚgridZgrid_removeÚsuperÚset)ÚselfÚloÚhi©Ú	__class__© ú!lib/python3.9/idlelib/textview.pyr      s    
zAutoHideScrollbar.setc                 K   s   t | jj› d�ƒ‚d S )Nz does not support "pack"©r   r   Ú__name__©r   Úkwargsr   r   r   Úpack   s    zAutoHideScrollbar.packc                 K   s   t | jj› d�ƒ‚d S )Nz does not support "place"r   r    r   r   r   Úplace   s    zAutoHideScrollbar.place)r   Ú
__module__Ú__qualname__Ú__doc__r   r"   r#   Ú__classcell__r   r   r   r   r      s   r   c                       s$   e Zd ZdZef‡ fdd„	Z‡  ZS )ÚScrollableTextFramezDisplay text with scrollbar(s).c                    sÊ   t ƒ j|fi |¤Ž t| |d� }| _|jddtd� | jddd� | jddd� t| t	d|j
d�| _| jjddtd� | jj|d< |tkrÀt| td|jd�| _| jjddtd� | jj|d	< nd
| _d
S )a‘  Create a frame for Textview.

        master - master widget for this frame
        wrap - type of text wrapping to use ('word', 'char' or 'none')

        All parameters except for 'wrap' are passed to Frame.__init__().

        The Text widget is accessible via the 'text' attribute.

        Note: Changing the wrapping mode of the text widget after
        instantiation is not supported.
        ©Úwrapr   )ÚrowÚcolumnZstickyé   )ZweightF)ZorientÚ	takefocusÚcommandZyscrollcommandZxscrollcommandN)r   Ú__init__r   Útextr   r	   Zgrid_rowconfigureZgrid_columnconfigurer   r   ZyviewZyscrollr   r   r
   r   ZxviewZxscrollr   )r   Zmasterr*   r!   r1   r   r   r   r0   "   s&    þþzScrollableTextFrame.__init__)r   r$   r%   r&   r
   r0   r'   r   r   r   r   r(      s   r(   c                       s,   e Zd ZdZd‡ fdd„	Zd	dd„Z‡  ZS )
Ú	ViewFramez#Display TextFrame and Close button.Úwordc                    s²   t ƒ  |¡ || _|  d| j¡ |  d| j¡ t| tdd�| _| jj }| _| 	d|¡ |j
|ddd� t|ƒ | ¡  t| d	| jd
d� | _}| jjdddd� |jdd� dS )a  Create a frame for viewing text with a "Close" button.

        parent - parent widget for this frame
        contents - text to display
        wrap - type of text wrapping to use ('word', 'char' or 'none')

        The Text widget is accessible via the 'text' attribute.
        z<Return>z<Escape>i¼  )ZreliefZheightz1.0r   Zdisabled)r*   ZhighlightthicknessÚstateÚCloseF©r1   r/   r.   ÚtopTÚboth©ÚsideÚexpandZfillZbottom)r:   N)r   r0   ÚparentZbindÚokr(   r   Z	textframer1   ÚinsertZ	configurer   Z	focus_setr   Ú	button_okr"   )r   r<   Úcontentsr*   r1   r?   r   r   r   r0   J   s    	
ÿzViewFrame.__init__Nc                 C   s   | j  ¡  dS ©zDismiss text viewer dialog.N)r<   Údestroy©r   Zeventr   r   r   r=   d   s    zViewFrame.ok)r3   )N)r   r$   r%   r&   r0   r=   r'   r   r   r   r   r2   H   s   r2   c                       s8   e Zd ZdZdefdddœ‡ fdd„Zd
dd	„Z‡  ZS )Ú
ViewWindowz%A simple text viewer dialog for IDLE.TF)Ú_htestÚ_utestc                   sÊ   t ƒ  |¡ d| d< | ¡ d }| ¡ |s.dnd }	|  d|› d|	› �¡ |  |¡ t| ||d�| _|  d| j	¡ t
| d	| j	d
d� | _}
| jjdddd� || _| jrÆ|  |¡ |  ¡  |sÆ|  ¡  dS )a  Show the given text in a scrollable window with a 'close' button.

        If modal is left True, users cannot interact with other windows
        until the textview window is closed.

        parent - parent of this dialog
        title - string which is title of popup dialog
        contents - text to display in dialog
        wrap - type of text wrapping to use ('word', 'char' or 'none')
        _htest - bool; change box location when running htest.
        _utest - bool; don't wait_window when running unittest.
        é   Zborderwidthé
   éd   z	=750x500+ú+r)   ZWM_DELETE_WINDOWr5   Fr6   r7   Tr8   r9   N)r   r0   Zwinfo_rootxZwinfo_rootyZgeometryÚtitler2   Z	viewframeZprotocolr=   r   r?   r"   Úis_modalZ	transientZgrab_setZwait_window)r   r<   rK   r@   Úmodalr*   rE   rF   ÚxÚyr?   r   r   r   r0   l   s$    
ÿ
zViewWindow.__init__Nc                 C   s   | j r|  ¡  |  ¡  dS rA   )rL   Zgrab_releaserB   rC   r   r   r   r=   �   s    zViewWindow.ok)N)r   r$   r%   r&   r   r0   r=   r'   r   r   r   r   rD   i   s
   ÿ#rD   Tr3   Fc                 C   s   t | |||||d�S )a�  Create text viewer for given text.

    parent - parent of this dialog
    title - string which is the title of popup dialog
    contents - text to display in this dialog
    wrap - type of text wrapping to use ('word', 'char' or 'none')
    modal - controls if users can interact with other windows while this
            dialog is displayed
    _utest - bool; controls wait_window on unittest
    ©r*   rF   )rD   )r<   rK   r@   rM   r*   rF   r   r   r   Ú	view_text–   s    rQ   c           
   
   C   s°   z:t |d|d��}| ¡ }W d  ƒ n1 s.0    Y  W n\ tyb   tdd|›d�| d� Y nJ ty– }	 ztdt|	ƒ| d� W Y d}	~	nd}	~	0 0 t| |||||d	�S dS )
z™Create text viewer for text in filename.

    Return error message if file cannot be read.  Otherwise calls view_text
    with contents of the file.
    Úr)ÚencodingNzFile Load ErrorzUnable to load file z .)rK   Úmessager<   zUnicode Decode ErrorrP   )ÚopenÚreadÚOSErrorr   ÚUnicodeDecodeErrorÚstrrQ   )
r<   rK   ÚfilenamerS   rM   r*   rF   Úfiler@   Úerrr   r   r   Ú	view_file¤   s"    *
þ
þÿr]   Ú__main__)Úmainzidlelib.idle_test.test_textviewé   )Ú	verbosityÚexit)ÚrunN)Tr3   F)Tr3   F) r&   Ztkinterr   r   r   r   r   r   r   r	   r
   r   r   Ztkinter.ttkr   r   r   Ztkinter.messageboxr   Zidlelib.colorizerr   r   r(   r2   rD   rQ   r]   r   Zunittestr_   Zidlelib.idle_test.htestrc   r   r   r   r   Ú<module>   s"   4)!-
  ÿ
