
    d                     H   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e          Z G d d	e          Z G d
 de          Z G d de          ZddZ	 	 ddZedk    r'ddlmZ  e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                   .     e Zd ZdZ fdZd Zd Z xZS )AutoHideScrollbarzpA scrollbar that is automatically hidden when not needed.

    Only the grid geometry manager is supported.
    c                     t          |          dk    st          |          dk     r|                                  n|                                  t                                          ||           d S )Ng        g      ?)floatgridgrid_removesuperset)selflohi	__class__s      "  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/idlelib/textview.pyr   zAutoHideScrollbar.set   s_    99s??eBii#ooIIKKKKB    c                 :    t          | j        j         d          )Nz does not support "pack"r   r   __name__r   kwargss     r   packzAutoHideScrollbar.pack   s    $.1KKKLLLr    c                 :    t          | j        j         d          )Nz does not support "place"r"   r$   s     r   placezAutoHideScrollbar.place   s    $.1LLLMMMr    )r#   
__module____qualname____doc__r   r&   r(   __classcell__r   s   @r   r   r      sj             M M MN N N N N N Nr    r   c                   &     e Zd ZdZef fd	Z xZS )ScrollableTextFramezDisplay text with scrollbar(s).c                 v    t                      j        |fi | t          | |          x}| _        |                    ddt
                     |                     dd           |                     dd           t          | t          d|j
                  | _        | j                            ddt                     | j        j        |d<   |t          k    rUt          | t          d|j                  | _        | j                            ddt$                     | 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columnsticky   )weightF)orient	takefocuscommandyscrollcommandxscrollcommandN)r   __init__r   textr   r
   grid_rowconfiguregrid_columnconfigurer   r   yviewyscrollr   r   r   r   xviewxscrollr	   )r   masterr2   r%   r>   r   s        r   r=   zScrollableTextFrame.__init__"   sJ    	**6***40000ty		a$	///q+++!!!A!... )h3815= = = 	a"555!%!1 4<<,T*7<59ZA A ADL L!Ab999%)\%5D!"""DLLLr    )r#   r)   r*   r+   r   r=   r,   r-   s   @r   r/   r/      sF        ))$( #  #  #  #  #  #  #  #  #  # r    r/   c                   ,     e Zd ZdZd fd	ZddZ xZS )	ViewFramez#Display TextFrame and Close button.wordc                 h   t                                          |           || _        |                     d| j                   |                     d| j                   t          | t          d          | _        | j        j        x}| _        |	                    d|           |
                    |dd           t          |           |                                 t          | d	| j        d
          x| _        }| j                            dd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  )reliefheightz1.0r   disabled)r2   highlightthicknessstateCloseFr>   r:   r9   topTbothsideexpandfillbottom)rT   N)r   r=   parentbindokr/   r   	textframer>   insert	configurer   	focus_setr   	button_okr&   )r   rX   contentsr2   r>   r_   r   s         r   r=   zViewFrame.__init__J   s$    	   		*dg&&&		*dg&&&,T&MMM>..tyE8$$$DQjIIIT%+7DGu&F &F &F 	Ft&AAAH%%%%%r    Nc                 8    | j                                          dS zDismiss text viewer dialog.N)rX   destroyr   events     r   rZ   zViewFrame.okd   s    r    )rH   N)r#   r)   r*   r+   r=   rZ   r,   r-   s   @r   rG   rG   H   sW        ))& & & & & &4       r    rG   c                   8     e Zd ZdZdefddd fdZddZ xZS )	
ViewWindowz%A simple text viewer dialog for IDLE.TF)_htest_utestc                   t                                          |           d| d<   |                                dz   }|                                |sdndz   }	|                     d| d|	            |                     |           t          | ||          | _        |                     d| j	                   t          | d	| j	        d
          x| _        }
| j                            ddd           || _        | j        rA|                     |           |                                  |s|                                  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.
           borderwidth
   d   z	=750x500++r1   WM_DELETE_WINDOWrO   FrP   rQ   TrR   rS   N)r   r=   winfo_rootxwinfo_rootygeometrytitlerG   	viewframeprotocolrZ   r   r_   r&   is_modal	transientgrab_setwait_window)r   rX   ru   r`   modalr2   ri   rj   xyr_   r   s              r   r=   zViewWindow.__init__l   sk    	   ]  2%  f$=BB#>)!))a))***

5"4===($'222%+Dw48Gu&N &N &N 	Nt&AAA= 	#NN6"""MMOOO #  """""		# 	## #r    Nc                 d    | j         r|                                  |                                  dS rb   )rx   grab_releaserc   rd   s     r   rZ   zViewWindow.ok   s/    = 	 r    rf   )r#   r)   r*   r+   r   r=   rZ   r,   r-   s   @r   rh   rh   i   sl        ++6: !# !# !# !# !# !# !# !#F       r    rh   TrH   Fc                 ,    t          | |||||          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
    r2   rj   )rh   )rX   ru   r`   r|   r2   rj   s         r   	view_textr      s     feXu4OOOOr    c                 Z   	 t          ||          5 }|                                }ddd           n# 1 swxY w Y   t          | |||||          S # t          $ r t	          dd|d|            Y n5t
          $ r)}	t	          dt          |	          |            Y d}	~	nd}	~	ww xY w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.
    )encodingNr   zFile Load ErrorzUnable to load file z .)ru   messagerX   zUnicode Decode Error)openreadr   OSErrorr   UnicodeDecodeErrorstr)
rX   ru   filenamer   r|   r2   rj   filer`   errs
             r   	view_filer      sO   ((X... 	#$yy{{H	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# %d &( ( ( 	(  ! ! !)????	! 	! 	! 	! 	! 	!  ! ! !.c((	! 	! 	! 	! 	! 	! 	! 	! 	!! 4s8   A 4A 8A 8A  B(6	B(?B##B(__main__)mainzidlelib.idle_test.test_textview   )	verbosityexit)runN)TrH   F) r+   tkinterr   r   r   r   r   r   r	   r
   r   r   r   tkinter.ttkr   r   r   tkinter.messageboxr   idlelib.colorizerr   r   r/   rG   rh   r   r   r#   unittestr   idlelib.idle_test.htestr    r    r   <module>r      s   ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 0 0 0 0 0 0 0 0 0 0 ( ( ( ( ( ( * * * * * *N N N N N	 N N N&&  &  &  &  & % &  &  & R       B* * * * * * * *ZP P P P CI   0 zD	*aeDDDD++++++C
OOOOO r    