/B ͞dZddlmZddlmZmZmZmZmZm Z ddl m Z GddZ Gdde Z ed k(r dd lmZed d d ddlmZee yy)zBDefine SearchDialogBase used by Search, Replace, and Grep dialogs.)Toplevel)FrameEntryLabelButton Checkbutton Radiobutton) _setup_dialogcfeZdZdZdZdZdZdZddZddZ d Z d Z d Z dd Z d ZdZddZdZy)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 DialogSearchcP||_|j|_||_d|_y)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)rootbellenginetop)selfrrs 9/opt/alt/python312/lib64/python3.12/idlelib/searchbase.py__init__zSearchDialogBase.__init__!s$ II  NcP||_|js|jn4|jj|jj |jj |j |r8|jjdd|jjd||jj|jjdd|jjd|jjy)z6Make dialog visible on top of others and ready to use.rendN)textrcreate_widgets deiconifytkraise transientwinfo_toplevelentdeleteinsert focus_setselection_rangeicursorgrab_set)rr searchphrases ropenzSearchDialogBase.open3s xx    ! HH   HH    4..01  HHOOAe $ HHOOE, /    E*  rc|jrP|jj|jjd|jjyy)zPut dialog away for later use.N)r grab_releaserwithdraw)revents rclosezSearchDialogBase.closeDs@ 88 HH ! ! # HH  r " HH    rct|j}|jd|j|jd|j|j d|j|j |j|j|jt|||_ t|d|_ |jjd|jdd |j!dd d|_|jjdd d |jjd d d d |j%|j'|j)|j+y)zCreate 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. zzWM_DELETE_WINDOW)paddingnwes)stickyrd)weight)padr6r)r8minsizer6N)rrbinddefault_commandr.protocolwm_titletitle wm_iconnameiconr rrframegridgrid_columnconfiguregrid_rowconfigurerowcreate_entriescreate_option_buttonscreate_other_buttonscreate_command_buttons)rrs rrzSearchDialogBase.create_widgetsKs+ tyy! T112 TZZ( '4 TZZ   "c3*  v&   3 / a, ''q'; ''q#c'J  ""$ !!# ##%rct|j|}|j|jddt |j|d}|j|jdd|jdz|_||fS)zReturn (entry, label), . entry - gridded labeled Entry for text entry. label - Label widget, returned for testing. rrnwrEcolumnr4) textvariableexportselectionrnwe)rrArBrEr)r label_textvarlabelentrys r make_entryzSearchDialogBase.make_entrygsk djjz2 txx$ 7djjsAF txx% 888a<e|rc`|jd|jjd|_y)z/Create one or more entry lines with make_entry.zFind:rN)rVrpatvarr )rs rrFzSearchDialogBase.create_entriests#??7DKK,>,>?Brc|r6t|j|}|j|jddnd}t |j}|j|jddd|jdz|_||fS) zReturn (frame, label). frame - gridded labeled Frame for option or other buttons. label - Label widget, returned for testing. rKrrLrMr*rrQ)rErN columnspanr4)rrArBrEr)r labeltextrTrAs r make_framezSearchDialogBase.make_framexsq $**95E JJ488AdJ ;Edjj! txxa F88a<e|rcD|jdd}|j}|jdf|jdf|jdfg}|j r|j |jdf|D]&\}}t|||}|jdd (||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. OptionsrzRegular expressionz Match casez Whole wordz Wrap around)variablerleftbothsidefill) r\rrevarcasevarwordvarneedwrapbuttonappendwrapvarrpack)rrAroptionsrSrTbtns rrGz&SearchDialogBase.create_option_buttonss *1-LL"67NNL1NNL13    NNFNNM: ;!JCec>C HH&vH ."g~rc|jdd}|jj}ddg}|D]'\}}t||||}|j dd)||fS) zReturn (frame, others) for testing. Others is a list of value, label pairs. A gridded frame from make_frame is filled with radio buttons. Directionr)rUp)rDown)r_valuerr`rarb)r\rbackvarr rk)rrArSothersvalrTrms rrHz%SearchDialogBase.create_other_buttonssj  ,Q/kk!![) JCec5IC HH&vH .!f}rct|j|||xrdxsd}|jj\}}|jd|dd|jj|dz|S) z/Return command button gridded in command frame.activenormal)rcommanddefaultrrew)padyrErNr4)rowspan)r buttonframe grid_sizerB)rrTryisdefbcolsrowss r make_buttonzSearchDialogBase.make_buttonst 4##w -X9 ;"",,. T A$at4 d1f-rct|jx}|_|jdddddd|j d|j }|j y)z9Place buttons in vertical command frame gridded on right.rr7)rErNpadxr|ipadxipadyCloseN)rrAr~rBrr.lower)rfrs rrIz'SearchDialogBase.create_command_buttonssO$TZZ00D  1A1!!!<   Wdjj 1  rN)r)__name__ __module__ __qualname____doc__r>r@rhrr(r.rrVrFr\rGrHrrIrrr r sP( E DN$" &8 C & rr ceZdZdZdZdZy) _searchbasez3Create auto-opening dialog with no text connection.c hddl}ddlm}||_|j ||_|j t|jttt|jd|j\}}}}|jjd|dz|dzfzy)Nr) searchenginez[x+]z+%d+%d()reidlelibrrgetrrprintgeometrylistmapintsplitr)rparentrrwidthheightxys rrz_searchbase.__init__s( "&&v.   foo  S"((66??;L*M!NOfa (a"fa#g%667rcyrr)rdummys rr;z_searchbase.default_commandsdrN)rrrrrr;rrrrrs9 8+rr__main__)mainz!idlelib.idle_test.test_searchbaser7F) verbosityexit)runN)rtkinterr tkinter.ttkrrrrrr tkinter.simpledialogr r rrunittestridlelib.idle_test.htestrrrrrsXHMM.qqh+"+" z ,F+  r