a
    ze:                     @   s0  d dl Zd dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZmZmZmZ d dlmZmZmZmZmZ d dlmZ d dlmZ d dlmZ G dd	 d	e	ZG d
d deZG dd deZG dd deZG dd deZG dd deZe dkr,d dl!m"Z" e"dddd d dl#m$Z$ e$eee dS )    N)
executableplatform)Toplevel	StringVar
BooleanVarWES)FrameButtonEntryLabelCheckbutton)
filedialog)Font)_setup_dialogc                       sh   e Zd Zdi dddddZdddZd	d
 ZdddZdd ZdddZdddZ	 fddZ
  ZS )Query Ftext0
used_names_htest_utestc                C   s8  || _ || _|| _|| _t| | |   | | | | |sL| 	  t
|  | jdkrl| d| j | d| j | d| j | d| j | d| j |   |   | d| | d |  d   | |s| d |  d  nd	 f  | jd
d
d |s4|   | j  |   d S )NZaquaz<Command-.>z<Key-Escape>ZWM_DELETE_WINDOWz<Key-Return>z
<KP_Enter>z+%d+%d      F)Zheightwidth)parentmessager   r   r   __init__ZwithdrawtitleZ	transientZgrab_setr   Z_windowingsystembindcancelprotocolokcreate_widgetsZupdate_idletasksZgeometryZwinfo_rootxZwinfo_widthZwinfo_reqwidthZwinfo_rootyZwinfo_heightZwinfo_reqheightZ	resizableZ	deiconifyentry	focus_setZwait_window)selfr   r   r   r   r   r   r    r(   #/usr/lib/python3.9/idlelib/query.pyr   &   sH    



zQuery.__init__OKc                 C   s,  t | dd | _}|jdddd |jddd t|dd	| jd
}t| | j| _t	|d| jd| _
tdd| jd| _t|dd| jd| _|jddddtd | j
jddddtt ddgd | jjddddtt d |   t||d| jd| _t|d| jd| _| jjdddd | jjdddd d S )N
   )Zpaddingr   news)columnrowsticky   )ZweightwleftanchorZjustifytext   )r   textvariableZTkCaptionFontT)nameexistsroot redr5   Z
foregroundZfont      r-   r.   
columnspanpadxr/   r-   r.   rA   rB   r/   padyr   Zactive)r5   defaultcommandZCancel)r5   rF   c   )r-   r.   rB   )r
   framegridZgrid_columnconfigurer   r   r   r   Zentryvarr   r%   r   r   
error_fontentry_errorr   r   create_extrar   r#   Z	button_okr!   Zbutton_cancel)r'   Zok_textrH   Z
entrylabelr(   r(   r)   r$   Y   s<    
zQuery.create_widgetsc                 C   s   d S Nr(   r'   r(   r(   r)   rL   }       zQuery.create_extraNc                 C   s   d| |p| j d< d S )NzERROR: r5   )rK   )r'   r   Zwidgetr(   r(   r)   	showerror   s    zQuery.showerrorc                 C   s$   | j   }|s | d d S |S )Nzblank line.)r%   getstriprP   )r'   r%   r(   r(   r)   entry_ok   s
    
zQuery.entry_okc                 C   s8   d| j d< |  }|d ur*|| _|   n
| j  d S Nr   r5   )rK   rS   resultdestroyr%   r&   )r'   eventr%   r(   r(   r)   r#      s    

zQuery.okc                 C   s   d | _ |   d S rM   )rU   rV   )r'   rW   r(   r(   r)   r!      s    zQuery.cancelc                    s   |    t   d S rM   )Zgrab_releasesuperrV   rN   	__class__r(   r)   rV      s    zQuery.destroy)r*   )N)N)N)__name__
__module____qualname__r   r$   rL   rP   rS   r#   r!   rV   __classcell__r(   r(   rY   r)   r   !   s   3
$


r   c                       s,   e Zd Zddd fdd
Zdd Z  ZS )SectionNameFr   r   c                   s   t  j||||||d d S )N)r   r   r   rX   r   )r'   r   r   r   r   r   r   rY   r(   r)   r      s    zSectionName.__init__c                 C   sV   | j   }|s | d d S t|dkr:| d d S || jv rR| d d S |S )Nno name specified.r6   z"name is longer than 30 characters.zname is already in use.)r%   rQ   rR   rP   lenr   )r'   r8   r(   r(   r)   rS      s    



zSectionName.entry_okr[   r\   r]   r   rS   r^   r(   r(   rY   r)   r_      s   r_   c                       s,   e Zd Zddd fdd
Zdd Z  ZS )
ModuleNameFr`   c                   s   t  j||||||d d S )Nr   r   r   ra   )r'   r   r   r   r   r   r   rY   r(   r)   r      s    zModuleName.__init__c                 C   s  | j   }|s | d d S ztj|}W n8 ttfyh } z| t	| W Y d }~d S d }~0 0 |d u r| d d S t
|jtjjs| d d S z|j|}W nb ty   | d Y d S  ty   z|j }W n" ty
   | d Y Y d S 0 Y n0 |S )Nrb   zmodule not found.znot a source-based module.z%loader does not support get_filename.zloader failed to get filename.)r%   rQ   rR   rP   	importlibutil	find_spec
ValueErrorImportErrorstr
isinstanceloaderabcSourceLoaderget_filenameAttributeError	TypeError)r'   r8   specmsgZ	file_pathr(   r(   r)   rS      s6    




zModuleName.entry_okrd   r(   r(   rY   r)   re      s   re   c                   @   s   e Zd Zdd ZdS )Gotoc                 C   sL   zt | j }W n ty0   | d Y d S 0 |dkrH| d d S |S )Nznot a base 10 integer.r   znot a positive integer.)intr%   rQ   rj   rP   )r'   linenor(   r(   r)   rS      s    

zGoto.entry_okN)r[   r\   r]   rS   r(   r(   r(   r)   rv      s   rv   c                       sX   e Zd Zddi ddd fdd
Zdd Zdd	 Zd
d ZejZ	dd Z
dd Z  ZS )
HelpSourcer   F)menuitemfilepathr   r   r   c          	   	      s(   || _ d}t j|||||||d d S )NzName for item on Help menu:r   )r{   rX   r   )	r'   r   r   rz   r{   r   r   r   r   rY   r(   r)   r      s    zHelpSource.__init__c                 C   s   | j }t|dddd}t| | j| _t|| jdd| _t|dd| jd	}t|d
d| j	d| _
|jddddddgtd | jjddddtt ddgd |jdddtt d | j
jddddtt d d S )Nr1   r2   z,Help File Path: Enter URL or browse for filer3   (   )r7   r   ZBrowse   )r5   r   rF   r;   r<   r=   r   r+   r>   r?   )r-   r.   rA   rB   rD   r/      r   rC   )r-   r.   rB   r/      r@   )rH   r   r   r{   pathvarr   pathr   browse_filerJ   
path_errorrI   r   r   r	   )r'   rH   Z	pathlabelZbrowser(   r(   r)   rL     s,    zHelpSource.create_extrac                 C   s   t j| |dj||dS )N)r   	filetypes)Z
initialdirZinitialfile)r   ZOpenZshow)r'   r   ZinitdirZinitfiler(   r(   r)   askfilename  s    zHelpSource.askfilenamec                 C   s   g d}| j  }|r(tj|\}}nHd }td d dkrhtjtjtd}tj	|spt
 }nt
 }| |||}|r| j | d S )N))z
HTML Filesz*.htm *.htmlTEXT)z	PDF Filesz*.pdfr   )zWindows Help Filesz*.chm)z
Text Filesz*.txtr   )z	All Files*r>   winZDoc)r   rQ   osr   splitr   joindirnamer   isdirgetcwdr   set)r'   r   r   dirbasefiler(   r(   r)   r   !  s    

zHelpSource.browse_filec                 C   s|   | j   }|s$| d| j d S |dsx|d d dkrJ|dd  }tj |sh| d| j d S tdkrxd| }|S )Nzno help file path specified.)zwww.httpr?   zfile:zhelp file path does not exist.darwinzfile://)	r   rQ   rR   rP   r   
startswithr   r9   r   )r'   r   r(   r(   r)   path_ok9  s    
zHelpSource.path_okc                 C   s6   d| j d< |  }|  }|d u s*|d u r.d S ||fS rT   )r   item_okr   )r'   r8   r   r(   r(   r)   rS   J  s    
zHelpSource.entry_ok)r[   r\   r]   r   rL   r   r   r_   rS   r   r   r^   r(   r(   rY   r)   ry      s   ry   c                       s>   e Zd Zg ddd fdd
Zdd Zdd Zd	d
 Z  ZS )	CustomRunF)cli_argsr   r   c                   s    d}t  j||||||d d S )Nz$Command Line Arguments for sys.argv:rf   ra   )r'   r   r   r   r   r   r   rY   r(   r)   r   Y  s
    zCustomRun.__init__c                 C   sj   | j }t| dd| _t|| jdddd}t|dd| jd| _|jd	d
dddd | jjd	ddddd d S )NT)valueFzRestart shell)variableZonvalueZoffvaluer5   r;   r<   r=   r   r+   r>   r?   r1   r@   r   Zwe)rH   r   
restartvarr   r   rJ   Z
args_errorrI   )r'   rH   restartr(   r(   r)   rL   e  s    
zCustomRun.create_extrac              
   C   sZ   | j   }ztj|dd}W n4 tyT } z| t| W Y d }~d S d }~0 0 |S )NT)posix)r%   rQ   rR   shlexr   rj   rP   rl   )r'   Z
cli_stringr   errr(   r(   r)   cli_args_okr  s    zCustomRun.cli_args_okc                 C   s&   |   }| j }|d u rd S ||fS rM   )r   r   rQ   )r'   r   r   r(   r(   r)   rS   |  s    
zCustomRun.entry_ok)r[   r\   r]   r   rL   r   rS   r^   r(   r(   rY   r)   r   Q  s   
r   __main__)mainzidlelib.idle_test.test_queryr   F)	verbosityexit)run)%importlib.utilrg   importlib.abcr   r   sysr   r   tkinterr   r   r   r   r   r	   Ztkinter.ttkr
   r   r   r   r   r   Ztkinter.fontr   Ztkinter.simpledialogr   r   r_   re   rv   ry   r   r[   Zunittestr   Zidlelib.idle_test.htestr   r(   r(   r(   r)   <module>   s(     *\2
