Q}0;dZddlmZddlmZmZmZmZmZm Z ddl m Z GddZ Gdde Z ed kr'dd lmZed d d ddlmZee dSdS)zBDefine SearchDialogBase used by Search, Replace, and Grep dialogs.)Toplevel)FrameEntryLabelButton Checkbutton Radiobutton) _setup_dialogcheZdZdZdZdZdZdZddZddZ d Z d Z d Z dd Z d ZdZddZdZdS)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 DialogSearchcH||_|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)rootbellenginetop)selfrrs 9/opt/alt/python311/lib64/python3.11/idlelib/searchbase.py__init__zSearchDialogBase.__init__!s& I  NcF||_|js|n2|j|j|j||r6|jdd|j d||j |j dd|j d|j dS)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 x     ! ! ! ! H   H      4..00111  0 HOOAe $ $ $ HOOE, / / /    E***  rc|jrN|j|jd|jdSdS)zPut dialog away for later use.N)r grab_releaserwithdraw)revents rclosezSearchDialogBase.closeDsZ 8 H ! ! # # # H  r " " " H         rcFt|j}|d|j|d|j|d|j||j||j t|||_ t|d|_ |j d|dd |dd d|_|j dd d |j d d d d ||||dS)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_WINDOW5px)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 ty!! T1222 TZ((( '444 TZ     """c3...  v&&&   3 /// a,,, ''q';;; ''q#c'JJJ  ""$$$ !!### ##%%%%%rct|j|}||jddt |j|d}||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_entrygsy djz222 tx$ 777djsAFFF tx% 8888a<e|rc\|d|jjd|_dS)z/Create one or more entry lines with make_entry.zFind:rN)rVrpatvarr )rs rrFzSearchDialogBase.create_entriests%??7DK,>??Brc|r4t|j|}||jddnd}t |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_framexs  $*9555E JJ48AdJ ; ; ; ;Edj!! txa FFF8a<e|rc*|dd}|j}|jdf|jdf|jdfg}|jr||jdf|D].\}}t|||}| dd /||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-L"67NL1NL13   < NNFNM: ; ; ;! / /JCec>>>C HH&vH . . . .g~rc|dd}|jj}ddg}|D]/\}}t||||}|dd0||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_buttonssz  ,,Q/k![)  / /JCec5IIIC HH&vH . . . .f}rrct|j|||rdpd}|j\}}|d|dd|j|dz|S) z/Return command button gridded in command frame.activenormal)rcommanddefaultrrew)padyrErNr4)rowspan)r buttonframe grid_sizerB)rrTryisdefbcolsrowss r make_buttonzSearchDialogBase.make_buttons 4#w -X9 ; ; ;",,.. T A$at444 d1f---rct|jx}|_|dddddd|d|j}|dS)z9Place buttons in vertical command frame gridded on right.rr7)rErNpadxr|ipadxipadyCloseN)rrAr~rBrr.lower)rfrs rrIz'SearchDialogBase.create_command_buttonss_$TZ000D  1A1!!!<<<   Wdj 1 1  rN)r)__name__ __module__ __qualname____doc__r>r@rhrr(r.rrVrFr\rGrHrrIrrr r s( E DN$"    &&&8   CCC &   rr ceZdZdZdZdZdS) _searchbasez3Create auto-opening dialog with no text connection.c ddl}ddlm}||_|||_|t|ttt| d|\}}}}|j d|dz|dzfzdS)Nr) searchenginez[x+]z+%d+%d()reidlelibrrgetrrprintgeometrylistmapintsplitr)rparentrrwidthheightxys rrz_searchbase.__init__s (((((( "&&v..   foo    S"((66??;L;L*M*M!N!NOOfa (a"fa#g%6677777rcdSrr)rdummys rr;z_searchbase.default_commandsrN)rrrrrr;rrrrrs099 8 8 8+****rr__main__)mainz!idlelib.idle_test.test_searchbaser7F) verbosityexit)runN)rtkinterr tkinter.ttkrrrrrr tkinter.simpledialogr r rrunittestridlelib.idle_test.htestrrrrrs"HHMMMMMMMMMMMMMMMM......qqqqqqqqh+++++"+++" zD ,FFFF++++++C  r