3  f@sdZddlmZmZmZmZmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZGddde ZGdd d e ZGd d d e ZGd d d eZdddZdddZedkrddlmZeddddddlmZeedS)zSimple text browser for IDLE ) ToplevelTextTclError HORIZONTALVERTICALNSEW)Frame ScrollbarButton) showerror) color_configcs0eZdZdZfddZddZddZZS)AutoHiddenScrollbarzpA scrollbar that is automatically hidden when not needed. Only the grid geometry manager is supported. cs<t|dkst|dkr"|jn|jtj||dS)Ngg?)floatgridZ grid_removesuperset)selflohi) __class__5/opt/alt/python36/lib64/python3.6/idlelib/textview.pyrs zAutoHiddenScrollbar.setcKst|jjddS)Nz does not support "pack")rr__name__)rkwargsrrrpackszAutoHiddenScrollbar.packcKst|jjddS)Nz does not support "place")rrr)rrrrrplaceszAutoHiddenScrollbar.place)r __module__ __qualname____doc__rrr __classcell__rr)rrr s rcs"eZdZdZdfdd ZZS) TextFramezDisplay text with scrollbar.wordcstj|d|d<d|d<t||dd|_}t||jddtttt d|j ddd |j ddd |j d |d |d <|j t|td |jd|_}|j|d<|jddttd|dkrt|td |jd|_}|j|d<|jddtt ddS)zvCreate a frame for Textview. parent - parent widget for this frame rawtext - text to display ZsunkenZreliefiZheightr)wrapZhighlightthickness)rowcolumnZsticky)ZweightgZdisabledstateF)Zorient takefocuscommandZyscrollcommandZnoneZxscrollcommandN)r__init__rtextrrrrr r Zgrid_rowconfigureZgrid_columnconfigureinsertZ focus_setrrZyviewyscrollrrZxviewxscroll)rparentZrawtextr%r-r/r0)rrrr,"s,     zTextFrame.__init__)r$)rrr r!r,r"rr)rrr#sr#cs,eZdZdZdfdd Zd ddZZS) ViewFramez#Display TextFrame and Close button.r$csxtj|||_|jd|j|jd|jt|||d|_t|d|jdd|_}|jj ddd d |j d d dS) Nzz)r%CloseF)r-r+r*topTboth)sideexpandfillZbottom)r6) rr,r1Zbindokr#Z textframer button_okr)rr1r-r%r:)rrrr,Gs zViewFrame.__init__NcCs|jjdS)zDismiss text viewer dialog.N)r1destroy)reventrrrr9Rsz ViewFrame.ok)r$)N)rrr r!r,r9r"rr)rrr2Es r2cs4eZdZdZd dddfdd Zd d d ZZS) ViewWindowz%A simple text viewer dialog for IDLE.Tr$F)_htest_utestc stj|d|d<|jd}|j|s.dnd} |jd|d| |j|t|||d|_|jd|j t |d |j d d |_ } |jj d d dd||_ |j r|j||j|s|jdS)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 dz =750x500++)r%ZWM_DELETE_WINDOWr3F)r-r+r*r4Tr5)r6r7r8N)rr,Z winfo_rootxZ winfo_rootyZgeometrytitler2Z viewframeZprotocolr9r r:ris_modalZ transientZgrab_setZ wait_window) rr1rDr-modalr%r>r?xyr:)rrrr,Zs"    zViewWindow.__init__NcCs|jr|j|jdS)zDismiss text viewer dialog.N)rEZ grab_releaser;)rr<rrrr9}sz ViewWindow.ok)Tr$)N)rrr r!r,r9r"rr)rrr=Ws"r=Tr$FcCst||||||dS)aCreate 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=)r1rDr-rFr%r?rrr view_texts rIc Csy&t|d|d}|j}WdQRXWn\tk rPtdd|d|dYnHtk r} ztdt| |dWYdd} ~ XnXt||||||d SdS) 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)encodingNzFile Load ErrorzUnable to load file z .)rDmessager1zUnicode Decode Error)r%r?)openreadOSErrorrUnicodeDecodeErrorstrrI) r1rDfilenamerKrFr%r?filecontentserrrrr view_files   rV__main__)mainzidlelib.idle_test.test_textview) verbosityexit)runN)Tr$F)Tr$F)r!Ztkinterrrrrrrrr r Z tkinter.ttkr r r Ztkinter.messageboxrZidlelib.colorizerrrr#r2r=rIrVrZunittestrXZidlelib.idle_test.htestr\rrrrs ,  &-