o
     JAf                     @   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 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__ '/usr/lib/python3.10/idlelib/textview.pyr      s   
zAutoHideScrollbar.setc                 K      t | jj d)Nz does not support "pack"r   r   __name__r   kwargsr   r   r   pack      zAutoHideScrollbar.packc                 K   r   )Nz does not support "place"r   r!   r   r   r   place   r$   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rat| td|jd| _| jjddtd | jj|d	< d
S 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"   r3   r   r   r   r2   "   s&   
zScrollableTextFrame.__init__)r    r&   r'   r(   r
   r2   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   disabled)r,   ZhighlightthicknessstateCloseFr3   r1   r0   topTbothsideexpandfillZbottom)r=   N)r   r2   parentbindokr*   r   Z	textframer3   insertZ	configurer   Z	focus_setr   	button_okr#   )r   r@   contentsr,   r3   rD   r   r   r   r2   J   s   	
zViewFrame.__init__Nc                 C   s   | j   dS zDismiss text viewer dialog.N)r@   destroyr   eventr   r   r   rB   d   s   zViewFrame.ok)r5   N)r    r&   r'   r(   r2   rB   r)   r   r   r   r   r4   H   s    r4   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re| | |   |sg|   dS d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_WINDOWr8   Fr9   r:   Tr;   r<   N)r   r2   Zwinfo_rootxZwinfo_rootyZgeometrytitler4   Z	viewframeprotocolrB   r   rD   r#   is_modalZ	transientZgrab_setZwait_window)r   r@   rR   rE   modalr,   rL   rM   xyrD   r   r   r   r2   l   s(   

zViewWindow.__init__Nc                 C   s   | j r|   |   dS rF   )rT   Zgrab_releaserG   rH   r   r   r   rB      s   zViewWindow.okrJ   )r    r&   r'   r(   r   r2   rB   r)   r   r   r   r   rK   i   s    #rK   Tr5   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,   rM   )rK   )r@   rR   rE   rU   r,   rM   r   r   r   	view_text   s   rY   c           
   
   C   s   zt |d|d}| }W d   n1 sw   Y  W n0 ty2   tdd|d| d Y dS  tyM }	 ztdt|	| d W Y d}	~	dS d}	~	ww t| |||||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 .)rR   messager@   zUnicode Decode ErrorrX   )openreadOSErrorr   UnicodeDecodeErrorstrrY   )
r@   rR   filenamer[   rU   r,   rM   filerE   errr   r   r   	view_file   s,   


re   __main__)mainzidlelib.idle_test.test_textview   )	verbosityexit)runN)Tr5   F) r(   tkinterr   r   r   r   r   r   r   r	   r
   r   r   Ztkinter.ttkr   r   r   Ztkinter.messageboxr   Zidlelib.colorizerr   r   r*   r4   rK   rY   re   r    Zunittestrg   Zidlelib.idle_test.htestrk   r   r   r   r   <module>   s&    4)!
-
