
    "e                        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       yy)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kD  st        |      dk  r| j                          n| j                          t        |   ||       y )Ng        g      ?)floatgridgrid_removesuperset)selflohi	__class__s      "lib/python3.12/idlelib/textview.pyr   zAutoHideScrollbar.set   s;    9s?eBi#oIIKB    c                 F    t        | j                  j                   d      )Nz does not support "pack"r   r   __name__r   kwargss     r   packzAutoHideScrollbar.pack   s     $..1122JKLLr    c                 F    t        | j                  j                   d      )Nz does not support "place"r"   r$   s     r   placezAutoHideScrollbar.place   s     $..1122KLMMr    )r#   
__module____qualname____doc__r   r&   r(   __classcell__r   s   @r   r   r      s    M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                 `   t        |   |fi | t        | |      x}| _        |j	                  ddt
               | j                  dd       | j                  dd       t        | t        d|j                        | _        | j                  j	                  ddt               | j                  j                  |d<   |t        k(  r^t        | t        d|j                         | _        | j"                  j	                  ddt$               | j"                  j                  |d	<   y
d
| _        y
)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__"   s	    	*6*400ty		a$	/q+!!!A!. )h3815= 	a"5!%!1!1 4<,T*7<59ZZADL LL!Ab9%)\\%5%5D!"DLr    )r#   r)   r*   r+   r   r=   r,   r-   s   @r   r/   r/      s    )$( #  # 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.c                 ,   t         |   |       || _        | j                  d| j                         | j                  d| j                         t        | t        d      | _        | j                  j                  x}| _        |j                  d|       |j                  |dd       t        |       |j                          t        | d	| j                  d
      x| _        }| j                  j                  ddd       |j                  d       y)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)rS   N)r   r=   parentbindokr/   r   	textframer>   insert	configurer   	focus_setr   	button_okr&   )r   rW   contentsr2   r>   r^   r   s         r   r=   zViewFrame.__init__J   s     	 		*dgg&		*dgg&,T&M>>...tyE8$DQjIT%+7DGGu&F 	Ft&AH%r    c                 8    | j                   j                          yzDismiss text viewer dialog.N)rW   destroyr   events     r   rY   zViewFrame.okd   s    r    )wordN)r#   r)   r*   r+   r=   rY   r,   r-   s   @r   rG   rG   H   s    )&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<   |j                         dz   }|j                         |sdndz   }	| j	                  d| d|	        | j                  |       t        | ||      | _        | j                  d| j                         t        | d	| j                  d
      x| _        }
| j                  j                  ddd       || _        | j                  r5| j                  |       | j                          |s| j!                          yyy)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_WINDOWrN   FrO   rP   TrQ   rR   N)r   r=   winfo_rootxwinfo_rootygeometrytitlerG   	viewframeprotocolrY   r   r^   r&   is_modal	transientgrab_setwait_window)r   rW   ru   r_   modalr2   ri   rj   xyr^   r   s              r   r=   zViewWindow.__init__l   s    	 ] 2% fB#>	!AaS)*

5"4=($''2%+Dw48GGu&N 	Nt&A==NN6"MMO  "  r    c                 \    | j                   r| j                          | j                          yra   )rx   grab_releaserb   rc   s     r   rY   zViewWindow.ok   s    ==r    rf   )r#   r)   r*   r+   r   r=   rY   r,   r-   s   @r   rh   rh   i   s     +6: !# !#Fr    rh   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   )rW   ru   r_   r|   r2   rj   s         r   	view_textr      s     feXu4OOr    c                    	 t        ||      5 }|j                         }ddd       t        | ||||      S # 1 sw Y   xY w# t        $ r t	        dd|d|        Y yt
        $ r!}	t	        dt        |	      |        Y d}	~	yd}	~	ww xY w)	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   messagerW   zUnicode Decode Error)openreadr   OSErrorr   UnicodeDecodeErrorstr)
rW   ru   filenamer   r|   r2   rj   filer_   errs
             r   	view_filer      s    ((X. 	#$yy{H	# %d &( 	(	# 	# !)0B?	!   !.c(	! 	! !s0   A 9A AA B"B*BB__main__)mainzidlelib.idle_test.test_textview   )	verbosityexit)runN)Tre   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 ( *N	 N&& % & R B* *ZP CI0 z	*aeD+
O r    