3  f@sdZddlmZmZddlmZmZmZmZm Z GdddZ Gddde Z e dkrdd l mZed d d d ddlmZee dS)zBDefine SearchDialogBase used by Search, Replace, and Grep dialogs.)ToplevelFrame)EntryLabelButton Checkbutton Radiobuttonc@s|eZdZdZdZdZdZddZddd Zdd d Z d d Z ddZ ddZ dddZ ddZddZd ddZddZdS)!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 DialogZSearchcCs||_||_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)rootenginetop)selfr r r7/opt/alt/python36/lib64/python3.6/idlelib/searchbase.py__init__ s zSearchDialogBase.__init__NcCs|||_|js|jn|jj|jj|rJ|jjdd|jjd||jj|jj dd|jj d|jj dS)z6Make dialog visible on top of others and ready to use.rendN) textr create_widgetsZ deiconifyZtkraiseentdeleteinsertZ focus_setZselection_rangeZicursorZgrab_set)rrZ searchphraserrropen0s     zSearchDialogBase.opencCs|jr|jj|jjdS)zPut dialog away for later use.N)r Z grab_releaseZwithdraw)rZeventrrrclose@s zSearchDialogBase.closecCst|j}|jd|j|jd|j|jd|j|j|j|j|j ||_ |j |_ d|_ |j j dddd|j j ddddd |j|j|j|jd S) 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. zzZWM_DELETE_WINDOWr)padweightr d)rZminsizerN)rr Zbinddefault_commandrZprotocolZwm_titletitleZ wm_iconnameiconr ZbellrowZgrid_columnconfigurecreate_entriescreate_option_buttonscreate_other_buttonscreate_command_buttons)rr rrrrFs   zSearchDialogBase.create_widgetscCsVt|j|d}|j|jdddt|j|dd}|j|jddd|jd|_||fS)zReturn (entry, label), . entry - gridded labeled Entry for text entry. label - Label widget, returned for testing. )rrnw)r!columnsticky)Z textvariableZexportselectionr nwe)rr gridr!r)rZ label_textvarlabelentryrrr make_entry^s  zSearchDialogBase.make_entrycCs|jd|jjd|_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|jdddnd}t|j}|j|jdddd|jd|_||fS) zReturn (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||jdd}|j}|jdf|jdf|jdfg}|jrF|j|jdfx,|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)variablerleftboth)sidefill) r1r ZrevarZcasevarZwordvarneedwrapbuttonappendZwrapvarrpack)rr0r Zoptionsr+r,btnrrrr#s z&SearchDialogBase.create_option_buttonscCsV|jdd}|jj}d d g}x.|D]&\}}t||||d}|jddd q$W||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. Z Directionrr UpDown)r2valuerr3r4)r5r6)r r;)rr<)r1r Zbackvarrr9)rr0r+Zothersvalr,r:rrrr$sz%SearchDialogBase.create_other_buttonsrcCsPt|j|||rdpdd}|jj\}}|jd|ddd|jj|dd|S) z/Return command button gridded in command frame.ZactiveZnormal)rcommanddefaultr rZew)padyr!r'r()Zrowspan)r buttonframeZ grid_sizer*)rr,r?ZisdefbZcolsZrowsrrr make_buttonszSearchDialogBase.make_buttoncCs@t|j}|_|jddddddd|jd|j}|jdS)z9Place buttons in vertical command frame gridded on right.rr)r!r'ZpadxrAZipadxZipadyrN)rr rBr*rDrlower)rfrCrrrr%sz'SearchDialogBase.create_command_buttons)N)N)N)r)__name__ __module__ __qualname____doc__rr r7rrrrr.r"r1r#r$rDr%rrrrr s     r c@s eZdZdZddZddZdS) _searchbasez3Create auto-opening dialog with no text connection.cCs|ddl}ddlm}||_|j||_|jt|jt t t |j d|j\}}}}|j jd|d|dfdS)Nr) searchenginez[x+]z+%d+%d()reZidlelibrLr getr rprintZgeometrylistmapintsplitr )rparentrOrLwidthZheightxyrrrrs   "z_searchbase.__init__cCsdS)Nr)rZdummyrrrrsz_searchbase.default_commandN)rGrHrIrJrrrrrrrKs rK__main__)mainz!idlelib.idle_test.test_searchbaserF) verbosityexit)runN)rJZtkinterrrZ tkinter.ttkrrrrrr rKrGZunittestr[Zidlelib.idle_test.htestr^rrrrs-