a XC?h°ã@s”dZddlmZddlmZmZmZmZmZm Z ddl m Z Gdd„dƒZ Gdd„de ƒZ ed krdd lmZed d d dddlmZee ƒdS)zBDefine SearchDialogBase used by Search, Replace, and Grep dialogs.é)ÚToplevel)ÚFrameÚEntryÚLabelÚButtonÚ CheckbuttonÚ Radiobutton)Ú _setup_dialogc@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||_|j|_||_d|_dS)a[Initialize root, engine, and top attributes. top (level widget): set in create_widgets() called from open(). frame: container for all widgets in dialog. 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_widgets(). title (of dialog): class attribute, override in subclasses. icon (of dialog): ditto, use unclear if cannot minimize dialog. N)ÚrootZbellÚengineÚtop)Úselfr r ©rú7/opt/alt/python39/lib64/python3.9/idlelib/searchbase.pyÚ__init__!s zSearchDialogBase.__init__NcCsŒ||_|js| ¡n|j ¡|j ¡|j | ¡¡|rZ|j dd¡|j  d|¡|j  ¡|j  dd¡|j  d¡|j  ¡dS)z6Make dialog visible on top of others and ready to use.rÚendN)ÚtextrÚcreate_widgetsZ deiconifyZtkraiseÚ transientZwinfo_toplevelÚentÚdeleteÚinsertZ focus_setZselection_rangeZicursorZgrab_set)rrZ searchphraserrrÚopen3s     zSearchDialogBase.opencCs*|jr&|j ¡|j d¡|j ¡dS)zPut dialog away for later use.ÚN)rZ grab_releaserZwithdraw)rZeventrrrÚcloseDs  zSearchDialogBase.closecCsât|jƒ}| d|j¡| d|j¡| d|j¡| |j¡| |j ¡t |ƒ||_ t |dd|_ |j jdd|jdd d |jdd d d|_|j jdd dd |j jd d d d d| ¡| ¡| ¡| ¡dS)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_WINDOWZ5px)ZpaddingZnwes)Ústickyréd)Úweighté)Úpadrr )r!ZminsizerN)rr ZbindÚdefault_commandrZprotocolZwm_titleÚtitleZ wm_iconnameÚiconr rrÚframeÚgridZgrid_columnconfigureZgrid_rowconfigureÚrowÚcreate_entriesÚcreate_option_buttonsÚcreate_other_buttonsÚcreate_command_buttons)rrrrrrKs&   zSearchDialogBase.create_widgetscCsVt|j|d}|j|jdddt|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'Úcolumnr)Z textvariableZexportselectionr Únwe)rr%r&r'r)rZ label_textÚvarÚlabelÚentryrrrÚ make_entrygs  zSearchDialogBase.make_entrycCs| d|jj¡d|_dS)z/Create one or more entry lines with make_entry.zFind:rN)r4r Zpatvarr)rrrrr(tszSearchDialogBase.create_entriescCs\|r&t|j|d}|j|jdddnd}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. r,rr-r.rr r0)r'r/Z columnspanr)rr%r&r'r)rZ labeltextr2r%rrrÚ make_framexs  zSearchDialogBase.make_framecCsx| d¡d}|j}|jdf|jdf|jdfg}|jrF| |jdf¡|D]$\}}t|||d}|j dd d qJ||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©ZsideZfill) r5r ZrevarZcasevarZwordvarÚneedwrapbuttonÚappendZwrapvarrÚpack)rr%r Zoptionsr1r2Úbtnrrrr)ˆsþ z&SearchDialogBase.create_option_buttonscCsR| d¡d}|jj}ddg}|D]&\}}t||||d}|jdddq"||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 Directionr)r ZUp)rZDown)r6Úvaluerr7r8r9)r5r Zbackvarrr<)rr%r1ZothersÚvalr2r=rrrr*›s z%SearchDialogBase.create_other_buttonsrcCsPt|j|||rdpdd}|j ¡\}}|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&)rr2r@ZisdefÚbZcolsZrowsrrrÚ make_button©s þzSearchDialogBase.make_buttoncCs@t|jƒ}|_|jddddddd| d|j¡}| ¡dS)z9Place buttons in vertical command frame gridded on right.rr )r'r/ZpadxrBZipadxZipadyZCloseN)rr%rCr&rErÚlower)rÚfrDrrrr+³sz'SearchDialogBase.create_command_buttons)N)N)N)r)Ú__name__Ú __module__Ú __qualname__Ú__doc__r#r$r:rrrrr4r(r5r)r*rEr+rrrrr s     r c@s eZdZdZdd„Zdd„ZdS)Ú _searchbasez3Create auto-opening dialog with no text connection.cCs|ddl}ddlm}||_| |¡|_| ¡t| ¡ƒt t t |  d| ¡¡ƒƒ\}}}}|j  d|d|df¡dS)Nr)Ú searchenginez[x+]z+%d+%dé(é¯)ÚreZidlelibrMr Úgetr rÚprintZgeometryÚlistÚmapÚintÚsplitr)rÚparentrPrMÚwidthZheightÚxÚyrrrr¿s   "z_searchbase.__init__cCsdS)Nr)rZdummyrrrr"Êóz_searchbase.default_commandN)rHrIrJrKrr"rrrrrL¼s rLÚ__main__)Úmainz!idlelib.idle_test.test_searchbaser F)Ú verbosityÚexit)ÚrunN)rKZtkinterrZ tkinter.ttkrrrrrrZtkinter.simpledialogr r rLrHZunittestr]Zidlelib.idle_test.htestr`rrrrÚs   5