B
    ^ c                 @   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.7/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   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| 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   r-   )r   r   r   r,   "   s"    zScrollableTextFrame.__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.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)r-   r+   r*   topTboth)sideexpandfillZbottom)r4   N)r   r,   parentZbindokr%   r   Z	textframer-   insertZ	configurer   Z	focus_setr   	button_okr   )r   r7   contentsr&   r-   r:   )r   r   r   r,   J   s    	zViewFrame.__init__Nc             C   s   | j   dS )zDismiss text viewer dialog.N)r7   destroy)r   eventr   r   r   r8   d   s    zViewFrame.ok)r/   )N)r   r!   r"   r#   r,   r8   r$   r   r   )r   r   r.   H   s   r.   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_WINDOWr1   F)r-   r+   r*   r2   Tr3   )r4   r5   r6   N)r   r,   Zwinfo_rootxZwinfo_rootyZgeometrytitler.   Z	viewframeZprotocolr8   r   r:   r   is_modalZ	transientZgrab_setZwait_window)r   r7   rE   r;   modalr&   r?   r@   xyr:   )r   r   r   r,   l   s"    

zViewWindow.__init__Nc             C   s   | j r|   |   dS )zDismiss text viewer dialog.N)rF   Zgrab_releaser<   )r   r=   r   r   r   r8      s    zViewWindow.ok)N)r   r!   r"   r#   r   r,   r8   r$   r   r   )r   r   r>   i   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
    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&   r@   )r>   )r7   rE   r;   rG   r&   r@   r   r   r   	view_text   s    rJ   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 .)rE   messager7   zUnicode Decode Error)r&   r@   )openreadOSErrorr   UnicodeDecodeErrorstrrJ   )
r7   rE   filenamerL   rG   r&   r@   filer;   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
   r   r   Ztkinter.ttkr   r   r   Ztkinter.messageboxr   Zidlelib.colorizerr   r   r%   r.   r>   rJ   rV   r   ZunittestrX   Zidlelib.idle_test.htestr\   r   r   r   r   <module>   s    4)!-
 
