o =?h:@s6dZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z m Z mZmZddlmZmZmZmZmZddl mZddlmZddlmZGd d d e ZGd d d eZGd ddeZGdddeZGdddeZGdddeZ e!dkrddl"m#Z#e#ddddddl$m%Z%e%eee dSdS)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_utestcCs:||_||_||_||_t||||||||s&| t ||j dkr6| d|j | d|j |d|j | d|j| d|j|||d||d|d||s}|d|dnd f|jd d d |s||j|d Sd 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&4/opt/alt/python310/lib64/python3.10/idlelib/query.pyr&sJ      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}szQuery.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#getstriprK)r%r#r&r&r'entry_oks  zQuery.entry_okcCs:d|jd<|}|dur||_|dS|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)rGrNresultdestroyr#r$)r%eventr#r&r&r'r!s  zQuery.okcCsd|_|dS)z0Set dialog result to None and destroy tk widget.N)rOrP)r%rQr&r&r'r s z Query.cancelcs|tdSrI)Z grab_releasesuperrPrJ __class__r&r'rPsz Query.destroy)r(rI) __name__ __module__ __qualname____doc__rr"rHrKrNr!r rP __classcell__r&r&rSr'r!s 3$   rc0eZdZdZdddfdd ZddZZS) SectionNamez*Get a name for a config file section name.Frrctj||||||ddS)N)rrrrRr)r%rrrrrrrSr&r'r zSectionName.__init__cCsV|j}|s|ddSt|dkr|ddS||jvr)|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#rLrMrKlenr)r%r4r&r&r'rNs     zSectionName.entry_okrUrVrWrXrrNrYr&r&rSr'r[ r[crZ) ModuleNamez-Get a module name for Open Module menu entry.Fr\cr])Nrrrr^)r%rrrrrrrSr&r'rr_zModuleName.__init__c Cs|j}|s|ddSztj|}Wnttfy4}z|t |WYd}~dSd}~ww|dur@|ddSt |j tj j sO|ddSz |j |}W|Styg|dYdStyz |j }WY|Sty|dYYdSww)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#rLrMrK importlibutil find_spec ValueError ImportErrorstr isinstanceloaderabc SourceLoader get_filenameAttributeError TypeError)r%r4specmsgZ file_pathr&r&r'rNs@      zModuleName.entry_okrbr&r&rSr'rdrcrdc@seZdZdZddZdS)Gotoz1Get a positive line number for editor Go To Line.cCsLz t|j}Wnty|dYdSw|dkr$|ddS|S)Nznot a base 10 integer.rznot a positive integer.)intr#rLrirK)r%linenor&r&r'rNs   z Goto.entry_okN)rUrVrWrXrNr&r&r&r'rus rucs\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)rzrRr) r%rrryrzrrrrrSr&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 rrzpathvarr 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' askfilenames zHelpSource.askfilenamecCsgd}|j}|rtj|\}}n$d}tdddkr4tjtjtd}tj |s3t }nt }| |||}|rI|j |dSdS)N))z HTML Filesz *.htm *.htmlTEXT)z PDF Filesz*.pdfr)zWindows Help Filesz*.chm)z Text Filesz*.txtr)z All Files*r:winZDoc) rrLosrsplitrjoindirnamerisdirgetcwdrset)r%rrdirbasefiler&r&r'r!s  zHelpSource.browse_filecCs||j}|s|d|jdS|ds<|dddkr%|dd}tj|s4|d|jdStdkrs.    *\2