a XC?h:@s4dZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z m Z mZmZddlmZmZmZmZmZddl mZddlmZddlmZGd d d e ZGd d d eZGd ddeZGdddeZGdddeZGdddeZ e!dkr0ddl"m#Z#e#ddddddl$m%Z%e%eee dS)a| Dialogs that query users and verify the answer before accepting. Query is the generic base class for a popup dialog. The user must either enter a valid answer or close the dialog. Entries are validated when is entered or [Ok] is clicked. Entries are ignored when [Cancel] or [X] are clicked. The 'return value' is .result set to either a valid answer or None. Subclass SectionName gets a name for a new config file section. Configdialog uses it for new highlight theme and keybinding set names. Subclass ModuleName gets a name for File => Open Module. Subclass HelpSource gets menu item and path for additions to Help menu. N) executableplatform)Toplevel StringVar BooleanVarWES)FrameButtonEntryLabel Checkbutton) filedialog)Font) _setup_dialogcsleZdZdZdidddddZddd Zd d Zdd dZddZdddZ dddZ fddZ Z S)QueryzoBase class for getting verified answer from a user. For this base class, accept any non-blank string. Ftext0 used_names_htest_utestcCs8||_||_||_||_t||||||||sL| t ||j dkrl| d|j | d|j |d|j | d|j| d|j|||d||d|d||s|d|dnd f|jd d d |s4||j|d S) aCreate modal popup, return when destroyed. Additional subclass init must be done before this unless _utest=True is passed to suppress wait_window(). title - string, title of popup dialog message - string, informational message to display text0 - initial value for entry used_names - names already in use _htest - bool, change box location when running htest _utest - bool, leave window hidden and not modal Zaquaz z ZWM_DELETE_WINDOWz z z+%d+%dF)ZheightwidthN)parentmessagerrr__init__ZwithdrawtitleZ transientZgrab_setrZ_windowingsystemZbindcancelZprotocolokcreate_widgetsZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ resizableZ deiconifyentry focus_setZ wait_window)selfrrrrrrrr&2/opt/alt/python39/lib64/python3.9/idlelib/query.pyr&sH     zQuery.__init__OKcCs,t|dd|_}|jdddd|jdddt|dd |jd }t||j|_t |d |jd |_ t d d|j d|_ t|dd|j d|_|jddddtd|j jddddttddgd|jjddddttd|t||d|jd|_t|d|jd|_|jjdddd|jjdddddS)zCreate entry (rows, extras, buttons. Entry stuff on rows 0-2, spanning cols 0-2. Buttons on row 99, cols 1, 2. )ZpaddingrZnews)columnrowsticky)ZweightwleftZanchorZjustifytext)r textvariableZ TkCaptionFontT)nameexistsroot redr1Z foregroundZfontr*r+ columnspanpadxr,r*r+r=r>r,padyrZactive)r1defaultcommandZCancel)r1rBc)r*r+r>N)r framegridZgrid_columnconfigurer rrrZentryvarr r#rr error_font entry_errorrr create_extrar r!Z button_okr Z button_cancel)r%Zok_textrDZ entrylabelr&r&r'r"Ys< zQuery.create_widgetscCsdSNr&r%r&r&r'rH}zQuery.create_extraNcCsd||p|jd<dS)NzERROR: r1)rG)r%rZwidgetr&r&r' showerrorszQuery.showerrorcCs$|j}|s |ddS|S)zReturn non-blank entry or None.z blank line.N)r#getstriprL)r%r#r&r&r'entry_oks  zQuery.entry_okcCs8d|jd<|}|dur*||_|n |jdS)zIf entry is valid, bind it to 'result' and destroy tk widget. Otherwise leave dialog open for user to correct entry or cancel. rr1N)rGrOresultdestroyr#r$)r%eventr#r&r&r'r!s   zQuery.okcCsd|_|dS)z0Set dialog result to None and destroy tk widget.N)rPrQ)r%rRr&r&r'r sz Query.cancelcs|tdSrI)Z grab_releasesuperrQrJ __class__r&r'rQsz Query.destroy)r()N)N)N) __name__ __module__ __qualname____doc__rr"rHrLrOr!r rQ __classcell__r&r&rTr'r!s 3 $   rcs0eZdZdZdddfdd ZddZZS) SectionNamez*Get a name for a config file section name.Frrcstj||||||ddS)N)rrrrSr)r%rrrrrrrTr&r'rszSectionName.__init__cCsV|j}|s |ddSt|dkr:|ddS||jvrR|ddS|S)z2Return sensible ConfigParser section name or None.no name specified.Nr2z"name is longer than 30 characters.zname is already in use.)r#rMrNrLlenr)r%r4r&r&r'rOs     zSectionName.entry_okrVrWrXrYrrOrZr&r&rTr'r[sr[cs0eZdZdZdddfdd ZddZZS) ModuleNamez-Get a module name for Open Module menu entry.Fr\cstj||||||ddS)Nrrrr])r%rrrrrrrTr&r'rszModuleName.__init__c Cs|j}|s |ddSztj|}Wn8ttfyh}z|t |WYd}~dSd}~00|dur|ddSt |j tj j s|ddSz|j |}Wnbty|dYdStyz|j }Wn"ty |dYYdS0Yn0|S)z0Return entered module name as file path or None.r^Nzmodule not found.znot a source-based module.z%loader does not support get_filename.zloader failed to get filename.)r#rMrNrL importlibutil find_spec ValueError ImportErrorstr isinstanceloaderabc SourceLoader get_filenameAttributeError TypeError)r%r4specmsgZ file_pathr&r&r'rOs6      zModuleName.entry_okr`r&r&rTr'rasrac@seZdZdZddZdS)Gotoz1Get a positive line number for editor Go To Line.cCsLzt|j}Wnty0|dYdS0|dkrH|ddS|S)Nznot a base 10 integer.rznot a positive integer.)intr#rMrfrL)r%linenor&r&r'rOs   z Goto.entry_okN)rVrWrXrYrOr&r&r&r'rrsrrcs\eZdZdZddidddfdd ZddZd d Zd d Zej Z d dZ ddZ Z S) HelpSourcez,Get menu name and help source for Help menu.rF)menuitemfilepathrrrc s(||_d}tj|||||||ddS)zGet menu entry and url/local file for Additional Help. User enters a name for the Help resource and a web url or file name. The user can browse for the file. zName for item on Help menu:rN)rwrSr) r%rrrvrwrrrrrTr&r'rs zHelpSource.__init__cCs|j}t|dddd}t||j|_t||jdd|_t|dd|jd }t|d d |j d |_ |j d ddddd gt d|jj d dddt t dd gd|j dddt td|j j d dddt t ddS)zAdd path widjets to rows 10-12.r.r/z,Help File Path: Enter URL or browse for filer0()r3rZBrowse)r1rrBr7r8r9rr)r:r;)r*r+r=r>r@r, rr?)r*r+r>r, r<N)rDr rrwpathvarr pathr browse_filerF path_errorrErrr )r%rDZ pathlabelZbrowser&r&r'rHs,zHelpSource.create_extracCstj||dj||dS)N)r filetypes)Z initialdirZ initialfile)rZOpenZshow)r%rZinitdirZinitfiler&r&r' askfilenameszHelpSource.askfilenamecCsgd}|j}|r(tj|\}}nHd}tdddkrhtjtjtd}tj |spt }nt }| |||}|r|j |dS)N))z HTML Filesz *.htm *.htmlTEXT)z PDF Filesz*.pdfr)zWindows Help Filesz*.chm)z Text Filesz*.txtr)z All Files*r:winZDoc) r|rMosr}splitrjoindirnamerisdirgetcwdrset)r%rr}dirbasefiler&r&r'r~!s   zHelpSource.browse_filecCs||j}|s$|d|jdS|dsx|dddkrJ|dd}tj|sh|d|jdStdkrxd|}|S) z(Simple validity check for menu file pathzno help file path specified.N)zwww.Zhttpr;zfile:zhelp file path does not exist.darwinzfile://) r}rMrNrLr startswithrr5r)r%r}r&r&r'path_ok9s   zHelpSource.path_okcCs6d|jd<|}|}|dus*|dur.dS||fS)z,Return apparently valid (name, path) or Nonerr1N)ritem_okr)r%r4r}r&r&r'rOJs zHelpSource.entry_ok) rVrWrXrYrrHrr~r[rOrrrZr&r&rTr'rus rucsBeZdZdZgdddfdd ZddZdd Zd d ZZS) CustomRunzGet settings for custom run of module. 1. Command line arguments to extend sys.argv. 2. Whether to restart Shell or not. F)cli_argsrrcs d}tj||||||ddS)zcli_args is a list of strings. The list is assigned to the default Entry StringVar. The strings are displayed joined by ' ' for display. z$Command Line Arguments for sys.argv:rbNr])r%rrrrrrrTr&r'rYs zCustomRun.__init__cCsj|j}t|dd|_t||jdddd}t|dd|jd|_|jd d d d d d|jjd dd d dddS)zAdd run mode on rows 10-12.T)valueFz Restart shell)ZvariableZonvalueZoffvaluer1r7r8r9rr)r:r;r.r<r{ZweN)rDr restartvarrr rFZ args_errorrE)r%rDrestartr&r&r'rHes zCustomRun.create_extrac CsZ|j}ztj|dd}Wn4tyT}z|t|WYd}~dSd}~00|S)z6Validity check and parsing for command line arguments.T)posixN)r#rMrNshlexrrfrLrh)r%Z cli_stringrerrr&r&r' cli_args_okrszCustomRun.cli_args_okcCs&|}|j}|durdS||fS)z4Return apparently valid (cli_args, restart) or None.N)rrrM)r%rrr&r&r'rO|s zCustomRun.entry_ok) rVrWrXrYrrHrrOrZr&r&rTr'rQs   r__main__)mainzidlelib.idle_test.test_queryrF) verbosityexit)run)&rYimportlib.utilrc importlib.abcrrsysrrZtkinterrrrrrr Z tkinter.ttkr r r r rrZ tkinter.fontrZtkinter.simpledialogrrr[rarrrurrVZunittestrZidlelib.idle_test.htestrr&r&r&r's*    *\2