3 § fã@sˆdZddlmZmZddlmZmZmZmZm Z Gdd„dƒZ Gdd„de ƒZ e dkr„dd l mZed d d d �ddlmZee ƒdS)zBDefine SearchDialogBase used by Search, Replace, and Grep dialogs.é)ÚToplevelÚFrame)ÚEntryÚLabelÚButtonÚ CheckbuttonÚ Radiobuttonc@s|eZdZdZdZdZdZdd„Zddd „Zdd d „Z d d „Z dd„Z dd„Z ddd„Z dd„Zdd„Zd dd„Zdd„ZdS)!ÚSearchDialogBaseayCreate most of a 3 or 4 row, 3 column search dialog. The left and wide middle column contain: 1 or 2 labeled text entry lines (make_entry, create_entries); a row of standard Checkbuttons (make_frame, create_option_buttons), each of which corresponds to a search engine Variable; a row of dialog-specific Check/Radiobuttons (create_other_buttons). The narrow right column contains command buttons (make_button, create_command_buttons). These are bound to functions that execute the command. Except for command buttons, this base class is not limited to items common to all three subclasses. Rather, it is the Find dialog minus the "Find Next" command, its execution function, and the default_command attribute needed in create_widgets. The other dialogs override attributes and methods, the latter to replace and add widgets. z Search DialogZSearchécCs||_||_d|_dS)a'Initialize root, engine, and top attributes. top (level widget): set in create_widgets() called from open(). text (Text searched): set in open(), only used in subclasses(). ent (ry): created in make_entry() called from create_entry(). row (of grid): 0 in create_widgets(), +1 in make_entry/frame(). default_command: set in subclasses, used in create_widgers(). title (of dialog): class attribute, override in subclasses. icon (of dialog): ditto, use unclear if cannot minimize dialog. N)ÚrootÚengineÚtop)Úselfr r ©rú7/opt/alt/python36/lib64/python3.6/idlelib/searchbase.pyÚ__init__ s zSearchDialogBase.__init__NcCs|||_|js|jƒn|jjƒ|jjƒ|rJ|jjddƒ|jjd|ƒ|jjƒ|jj ddƒ|jj dƒ|jj ƒdS)z6Make dialog visible on top of others and ready to use.rÚendN) Útextr Úcreate_widgetsZ deiconifyZtkraiseÚentÚdeleteÚinsertZ focus_setZselection_rangeZicursorZgrab_set)rrZ searchphraserrrÚopen0s     zSearchDialogBase.opencCs|jr|jjƒ|jjƒdS)zPut dialog away for later use.N)r Z grab_releaseZwithdraw)rZeventrrrÚclose@s zSearchDialogBase.closecCsªt|jƒ}|jd|jƒ|jd|jƒ|jd|jƒ|j|jƒ|j|j ƒ||_ |j |_ d|_ |j j dddd�|j j ddddd �|jƒ|jƒ|jƒ|jƒd S) z¹Create basic 3 row x 3 col search (find) dialog. Other dialogs override subsidiary create_x methods as needed. Replace and Find-in-Files add another entry row. zzZWM_DELETE_WINDOWré)ÚpadÚweightr éd)rZminsizerN)rr ZbindÚdefault_commandrZprotocolZwm_titleÚtitleZ wm_iconnameÚiconr ZbellÚrowZgrid_columnconfigureÚcreate_entriesÚcreate_option_buttonsÚcreate_other_buttonsÚcreate_command_buttons)rr rrrrFs   zSearchDialogBase.create_widgetscCsVt|j|d�}|j|jddd�t|j|dd�}|j|jddd�|jd|_||fS)zŒReturn (entry, label), . entry - gridded labeled Entry for text entry. label - Label widget, returned for testing. )rrÚnw)r!ÚcolumnÚsticky)Z textvariableZexportselectionr Únwe)rr Úgridr!r)rZ label_textÚvarÚlabelÚentryrrrÚ make_entry^s  zSearchDialogBase.make_entrycCs|jd|jjƒd|_dS)z/Create one or more entry lines with make_entry.zFind:rN)r.r Zpatvarr)rrrrr"kszSearchDialogBase.create_entriescCs\|r&t|j|d�}|j|jddd�nd}t|jƒ}|j|jdddd�|jd|_||fS) z—Return (frame, label). frame - gridded labeled Frame for option or other buttons. label - Label widget, returned for testing. )rrr&)r!r'r(Úr r))r!r'Z columnspanr()rr r*r!r)rZ labeltextr,ÚframerrrÚ make_frameos  zSearchDialogBase.make_framecCs||jdƒd}|j}|jdf|jdf|jdfg}|jrF|j|jdfƒx,|D]$\}}t|||d�}|j dd d �qLW||fS) aReturn (filled frame, options) for testing. Options is a list of searchengine booleanvar, label pairs. A gridded frame from make_frame is filled with a Checkbutton for each pair, bound to the var, with the corresponding label. ZOptionsrzRegular expressionz Match casez Whole wordz Wrap around)ÚvariablerÚleftÚboth)ÚsideÚfill) r1r ZrevarZcasevarZwordvarÚneedwrapbuttonÚappendZwrapvarrÚpack)rr0r Zoptionsr+r,Úbtnrrrr#s z&SearchDialogBase.create_option_buttonscCsV|jdƒd}|jj}d d g}x.|D]&\}}t||||d�}|jddd �q$W||fS) z£Return (frame, others) for testing. Others is a list of value, label pairs. A gridded frame from make_frame is filled with radio buttons. Z Directionrr ÚUpÚDown)r2Úvaluerr3r4)r5r6)r r;)rr<)r1r Zbackvarrr9)rr0r+ZothersÚvalr,r:rrrr$’sz%SearchDialogBase.create_other_buttonsrcCsPt|j|||rdpdd�}|jjƒ\}}|jd|ddd�|jj|dd�|S) z/Return command button gridded in command frame.ZactiveZnormal)rÚcommandÚdefaultr rZew)Úpadyr!r'r()Zrowspan)rÚ buttonframeZ grid_sizer*)rr,r?ZisdefÚbZcolsZrowsrrrÚ make_button szSearchDialogBase.make_buttoncCs@t|jƒ}|_|jddddddd�|jd|jƒ}|jƒdS)z9Place buttons in vertical command frame gridded on right.rr)r!r'ZpadxrAZipadxZipadyrN)rr rBr*rDrÚlower)rÚfrCrrrr%ªsz'SearchDialogBase.create_command_buttons)N)N)N)r)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr r7rrrrr.r"r1r#r$rDr%rrrrr s     r c@s eZdZdZdd„Zdd„ZdS)Ú _searchbasez3Create auto-opening dialog with no text connection.cCs|ddl}ddlm}||_|j|ƒ|_|jƒt|jƒƒt t t |j d|jƒƒƒƒ\}}}}|j jd|d|dfƒdS)Nr)Ú searchenginez[x+]z+%d+%dé(é¯)ÚreZidlelibrLr Úgetr rÚprintZgeometryÚlistÚmapÚintÚsplitr )rÚparentrOrLÚwidthZheightÚxÚyrrrr¶s   "z_searchbase.__init__cCsdS)Nr)rZdummyrrrrÁsz_searchbase.default_commandN)rGrHrIrJrrrrrrrK³s rKÚ__main__)Úmainz!idlelib.idle_test.test_searchbaserF)Ú verbosityÚexit)ÚrunN)rJZtkinterrrZ tkinter.ttkrrrrrr rKrGZunittestr[Zidlelib.idle_test.htestr^rrrrÚs-