î Òê[aã@sdZddlmZmZmZmZmZmZmZGdd„dƒZ e dkr{ddl Z e j ddd ƒndS) 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„Zddd„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ú./usr/lib/python3.4/idlelib/SearchDialogBase.pyÚ__init__s  zSearchDialogBase.__init__NcCs©||_|js|jƒn|jjƒ|jjƒ|rh|jjddƒ|jjd|ƒn|jjƒ|jj ddƒ|jj dƒ|jj ƒdS)z6Make dialog visible on top of others and ready to use.rÚendN) Útextr Úcreate_widgetsZ deiconifyZtkraiseÚentZdeleteÚinsertZ focus_setZselection_rangeZicursorZgrab_set)rrZ searchphraserrrÚopen/s      zSearchDialogBase.opencCs*|jr&|jjƒ|jjƒndS)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 ƒ||_ d|_ |j j dddddƒ|j j dddd d dd ƒ|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_WINDOWrZpadéZweightr ZminsizeédN)rr ZbindZdefault_commandrZprotocolZwm_titleÚtitleZ wm_iconnameÚiconr ÚrowZgrid_columnconfigureÚcreate_entriesÚcreate_option_buttonsÚcreate_other_buttonsÚcreate_command_buttons)rr rrrrEs  "   zSearchDialogBase.create_widgetscCsˆt|jd|ƒ}|jd|jddddƒt|jd|ddƒ}|jd|jdd dd ƒ|jd |_||fS) zŒReturn (entry, label), . entry - gridded labeled Entry for text entry. label - Label widget, returned for testing. rrÚcolumnrÚstickyÚnwZ textvariableZexportselectionr Únwe)rr Úgridrr)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)rrrrriszSearchDialogBase.create_entriesc Cs‘|r=t|jd|ƒ}|jd|jddddƒnd}t|jƒ}|jd|jddd ddd ƒ|jd|_||fS) z—Return (frame, label). frame - gridded labeled Frame for option or other buttons. label - Label widget, returned for testing. rrr"rr#r$Úr Z columnspanr%)rr r&rr)rZ labeltextr(ÚframerrrÚ make_framems"%zSearchDialogBase.make_framec CsÖ|jdƒd}|j}|jdf|jdf|jdfg}|jrh|j|jdfƒnxa|D]Y\}}t|ddd |d |ƒ}|j d d d dƒ|j ƒro|j ƒqoqoW||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ÚanchorÚwÚvariablerÚsideÚleftÚfillÚboth) r-r ZrevarZcasevarZwordvarÚneedwrapbuttonÚappendZwrapvarrÚpackÚgetÚselect)rr,r Zoptionsr'r(Úbtnrrrr}s     z&SearchDialogBase.create_option_buttonsc Cs¥|jdƒd}|jj}ddg}xm|D]e\}}t|ddd|d |d |ƒ}|jd d d dƒ|jƒ|kr2|jƒq2q2W||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ÚDownr.r/r0Úvaluerr1r2r3r4)r r;)rr<)r-r Zbackvarrr7r8r9)rr,r'ZothersÚvalr(r:rrrr ’s  z%SearchDialogBase.create_other_buttonsrc Cst|jd|d|d|r$dp'dƒ}|jjƒ\}}|jddd|d d d d ƒ|jjd |dƒ|S)z/Return command button gridded in command frame.rÚcommandÚdefaultZactiveZnormalÚpadyr rr"rr#ZewZrowspan)rÚ buttonframeZ grid_sizer&)rr(r?ZisdefÚbZcolsZrowsrrrÚ make_button£s  "zSearchDialogBase.make_buttonc Csgt|jƒ}|_|jddddddddddddƒ|jd |jƒ}|jƒd S) z9Place buttons in vertical command frame gridded on right.rrr"rZpadxrAZipadxZipadyrN)rr rBr&rDrÚlower)rÚfrCrrrr!­s.z'SearchDialogBase.create_command_buttons)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr5rrrrr*rr-rr rDr!rrrrr s       r Ú__main__Nz'idlelib.idle_test.test_searchdialogbaseÚ verbosityr) rJZtkinterrrrrrrrr rGZunittestÚmainrrrrÚs 4¯