a
    If                     @   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rd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rt| 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 )
zCreate 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)!-
  
