B
     S]                 @   s   d Z ddl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NSEW)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 )AutoHiddenScrollbarzpA 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.7/idlelib/textview.pyr      s    
zAutoHiddenScrollbar.setc             K   s   t | jj dd S )Nz does not support "pack")r   r   __name__)r   kwargsr   r   r   pack   s    zAutoHiddenScrollbar.packc             K   s   t | jj dd S )Nz does not support "place")r   r   r   )r   r   r   r   r   place   s    zAutoHiddenScrollbar.place)r   
__module____qualname____doc__r   r   r   __classcell__r   r   )r   r   r      s   r   c                   s"   e Zd ZdZd fdd	Z  ZS )	TextFramezDisplay text with scrollbar.wordc                s  t  | d| d< d| d< t| |dd | _}t| |jddtt t t	 d | j
ddd	 | jddd	 |d
| d|d< |  t| td|jd | _}|j|d< |jddtt d |dkrt| td|jd | _}|j|d< |jddtt	 d dS )zvCreate a frame for Textview.

        parent - parent widget for this frame
        rawtext - text to display
        ZsunkenZreliefi  Zheightr   )wrapZhighlightthickness)rowcolumnZsticky   )Zweightg        ZdisabledstateF)Zorient	takefocuscommandZyscrollcommandZnoneZxscrollcommandN)r   __init__r   textr   r   r   r   r	   r
   Zgrid_rowconfigureZgrid_columnconfigureinsertZ	focus_setr   r   Zyviewyscrollr   r   Zxviewxscroll)r   parentZrawtextr%   r-   r/   r0   )r   r   r   r,   "   s,    


zTextFrame.__init__)r$   )r   r   r    r!   r,   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.r$   c                sx   t  | || _| d| j | d| j t| ||d| _t| d| jdd | _}| jj	ddd	d
 |j	dd d S )Nz<Return>z<Escape>)r%   CloseF)r-   r+   r*   topTboth)sideexpandfillZbottom)r6   )
r   r,   r1   Zbindokr#   Z	textframer   	button_okr   )r   r1   r-   r%   r:   )r   r   r   r,   G   s    zViewFrame.__init__Nc             C   s   | j   dS )zDismiss text viewer dialog.N)r1   destroy)r   eventr   r   r   r9   R   s    zViewFrame.ok)r$   )N)r   r   r    r!   r,   r9   r"   r   r   )r   r   r2   E   s   r2   c                   s4   e Zd ZdZdddd fddZdd	d
Z  ZS )
ViewWindowz%A simple text viewer dialog for IDLE.Tr$   F)_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
        text - 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_WINDOWr3   F)r-   r+   r*   r4   Tr5   )r6   r7   r8   N)r   r,   Zwinfo_rootxZwinfo_rootyZgeometrytitler2   Z	viewframeZprotocolr9   r   r:   r   is_modalZ	transientZgrab_setZwait_window)r   r1   rD   r-   modalr%   r>   r?   xyr:   )r   r   r   r,   Z   s"    

zViewWindow.__init__Nc             C   s   | j r|   |   dS )zDismiss text viewer dialog.N)rE   Zgrab_releaser;   )r   r<   r   r   r   r9   }   s    zViewWindow.ok)Tr$   )N)r   r   r    r!   r,   r9   r"   r   r   )r   r   r=   W   s   "r=   Tr$   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
    text - 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%   r?   )r=   )r1   rD   r-   rF   r%   r?   r   r   r   	view_text   s    rI   c       
   
   C   s   y&t |d|d}| }W dQ R X W n\ tk
rP   tdd|d| d Y nH tk
r }	 ztdt|	| d W dd}	~	X Y nX 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 .)rD   messager1   zUnicode Decode Error)r%   r?   )openreadOSErrorr   UnicodeDecodeErrorstrrI   )
r1   rD   filenamerK   rF   r%   r?   filecontentserrr   r   r   	view_file   s    
rV   __main__)mainzidlelib.idle_test.test_textview   )	verbosityexit)runN)Tr$   F)Tr$   F)r!   Ztkinterr   r   r   r   r   r   r   r	   r
   Ztkinter.ttkr   r   r   Ztkinter.messageboxr   Zidlelib.colorizerr   r   r#   r2   r=   rI   rV   r   ZunittestrX   Zidlelib.idle_test.htestr\   r   r   r   r   <module>   s    ,&-
 
