Your IP : 216.73.216.12
B
� f2:�@s dZddlZddlZddlZddlmZmZddlmZm Z m
Z
mZmZm
Z
ddlmZmZmZmZmZddlmZddlmZGdd �d e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�Zedk�rddlmZedddd�ddl 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 <Return> 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)�
executable�platform)�Toplevel� StringVar�
BooleanVar�W�E�S)�Frame�Button�Entry�Label�Checkbutton)�
filedialog)�FontcsleZdZdZdiddd�dd�Zddd �Zd
d�Zdd
d�Zdd�Zddd�Z ddd�Z
�fdd�Z�ZS)�QueryzoBase class for getting verified answer from a user.
For this base class, accept any non-blank string.
�F)�text0�
used_names�_htest�_utestc CsX||_||_||_||_t�||�|��|�|�|�|�|� �|j
�dd�}|dkr�y|j
�dd|jdd�WnYnX|�
d|j�|�
d |j�|�d
|j�|�
d|j�|�
d|j�|��|��|�d
|��|��d|��d|��|�s$|��d|��dndf�|jddd�|�sT|��|��dS)a�Create 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
�tk�windowingsystemZaquaz!::tk::unsupported::MacWindowStyleZstyleZ
moveableModalrz<Command-.>z<Key-Escape>ZWM_DELETE_WINDOWz<Key-Return>z
<KP_Enter>z+%d+%d��F)Zheight�widthN)�parent�messagerrr�__init__Zwithdraw�titleZ transientZgrab_setrZcallZ_wZbind�cancelZprotocol�ok�create_widgetsZupdate_idletasksZgeometryZwinfo_rootxZwinfo_widthZwinfo_reqwidthZwinfo_rootyZwinfo_heightZwinfo_reqheightZ resizableZ deiconifyZwait_window) �selfrrrrrrrr�r$�2/opt/alt/python37/lib64/python3.7/idlelib/query.pyr%sB
*zQuery.__init__�OKcCs6t|dd�|_}|jdddd�|jddd�t|dd |jd
�}t||j�|_t |d|jd�|_
|j
��td
d|j
d�|_t|dd|jd�|_|jddddtd�|j
jddddttddgd�|jjddddttd�|��t||d|jd�|_t|d|jd�|_|jjdddd�|jjdddd�dS)z�Create entry (rows, extras, buttons.
Entry stuff on rows 0-2, spanning cols 0-2.
Buttons on row 99, cols 1, 2.
�
)ZpaddingrZnews)�column�row�sticky�)Zweight�w�left)�anchor�justify�text�)r�textvariableZ
TkCaptionFontT)�name�exists�root� �red)r0�
foreground�font��)r(r)�
columnspan�padxr*)r(r)r<r=r*�padyrZactive)r0�default�commandZCancel)r0r@�c)r(r)r=N)r
�frame�gridZgrid_columnconfigurer
rrrZentryvarr�entry� focus_setrr�
error_font�entry_errorrr�create_extrarr!Z button_okr Z
button_cancel)r#Zok_textrBZ
entrylabelr$r$r%r"[s0
zQuery.create_widgetscCsdS)Nr$)r#r$r$r%rH��zQuery.create_extraNcCsd||p|jd<dS)NzERROR: r0)rG)r#rZwidgetr$r$r%� showerror�szQuery.showerrorcCs$|j����}|s |�d�dS|S)zReturn non-blank entry or None.zblank line.N)rD�get�striprJ)r#rDr$r$r%�entry_ok�s
zQuery.entry_okcCs8d|jd<|��}|dk r*||_|��n
|j��dS)z�If entry is valid, bind it to 'result' and destroy tk widget.
Otherwise leave dialog open for user to correct entry or cancel.
rr0N)rGrM�result�destroyrDrE)r#�eventrDr$r$r%r!�s
zQuery.okcCsd|_|��dS)z0Set dialog result to None and destroy tk widget.N)rNrO)r#rPr$r$r%r �szQuery.cancelcs|��t���dS)N)Zgrab_release�superrO)r#)� __class__r$r%rO�sz
Query.destroy)r&)N)N)N)
�__name__�
__module__�__qualname__�__doc__rr"rHrJrMr!r rO�
__classcell__r$r$)rRr%r s5
%
rcs0eZdZdZddd��fdd�
Zdd�Z�ZS)�SectionNamez*Get a name for a config file section name.F)rrcst�j||||||d�dS)N)rrr)rQr)r#rrrrrr)rRr$r%r�szSectionName.__init__cCsV|j����}|s |�d�dSt|�dkr:|�d�dS||jkrR|�d�dS|S)z2Return sensible ConfigParser section name or None.zno name specified.Nr1z"name is longer than 30 characters.zname is already in use.)rDrKrLrJ�lenr)r#r3r$r$r%rM�s
zSectionName.entry_ok)rSrTrUrVrrMrWr$r$)rRr%rX�srXcs0eZdZdZddd��fdd�
Zdd�Z�ZS)�
ModuleNamez-Get a module name for Open Module menu entry.F)rrcst�j||||||d�dS)N)rrr)rQr)r#rrrrrr)rRr$r%r�szModuleName.__init__c
Cs�|j����}|s |�d�dSytj�|�}Wn4ttfk
rd}z|�t |��dSd}~XYnX|dkr||�d�dSt
|jtjj
�s�|�d�dSy|j�|�}Wn"tk
r�|jd|d�dSX|S)z0Return entered module name as file path or None.zno name specified.Nzmodule not foundznot a source-based modulez$loader does not support get_filename)r)rDrKrLrJ� importlib�util� find_spec�
ValueError�ImportError�str�
isinstance�loader�abc�SourceLoader�get_filename�AttributeError)r#r3�spec�msgZ file_pathr$r$r%rM�s,
zModuleName.entry_ok)rSrTrUrVrrMrWr$r$)rRr%rZ�srZc@seZdZdZdd�ZdS)�Gotoz1Get a positive line number for editor Go To Line.cCsLyt|j���}Wntk
r0|�d�dSX|dkrH|�d�dS|S)Nznot a base 10 integer.rznot a positive integer.)�intrDrKr^rJ)r#�linenor$r$r%rM�s
z
Goto.entry_okN)rSrTrUrVrMr$r$r$r%ri�srics\eZdZdZddiddd��fdd�
Zdd�Zd d
�Zdd�Zej Z
d
d�Zdd�Z �ZS)�
HelpSourcez,Get menu name and help source for Help menu.rF)�menuitem�filepathrrrc s(||_d}t�j|||||||d�dS)z�Get 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:)rrrrN)rnrQr) r#rrrmrnrrrr)rRr$r%r�s
zHelpSource.__init__cCs�|j}t|dddd�}t||j�|_t||jdd�|_t|dd|jd �}t|d
d|j d�|_
|jd
ddddd
gtd�|jjd
dddtt
dd
gd�|jdddttd�|j
jd
dddtt
d�dS)zAdd path widjets to rows 10-12.r,r-z,Help File Path: Enter URL or browse for file)r.r/r0�()r2rZBrowse�)r0rr@r6r7)r0r8r9rr'r:r;)r(r)r<r=r>r*�r)r(r)r<r=r*r>)r(r)r=r*�)r(r)r<r=r*N)rBr
rrn�pathvarr�pathr�browse_filerF�
path_errorrCrrr )r#rBZ pathlabelZbrowser$r$r%rHs
zHelpSource.create_extracCstj||d�j||d�S)N)r� filetypes)Z
initialdirZinitialfile)rZOpenZshow)r#rwZinitdirZinitfiler$r$r%�askfilenameszHelpSource.askfilenamecCs�dddddg}|j��}|r.tj�|�\}}nHd}tdd�dkrntj�tj�t�d�}tj� |�svt�
�}nt�
�}|�|||�}|r�|j�|�dS) N)z
HTML Filesz*.htm *.html�TEXT)z PDF Filesz*.pdfry)zWindows Help Filesz*.chm)z
Text Filesz*.txtry)z All Files�*r:�winZDoc)
rsrK�osrt�splitr�join�dirnamer�isdir�getcwdrx�set)r#rwrt�dir�base�filer$r$r%rus"
zHelpSource.browse_filecCs||j����}|s$|�d|j�dS|�d�sx|dd�dkrJ|dd�}tj�|�sh|�d|j�dStdkrxd|}|S) z(Simple validity check for menu file pathzno help file path specified.N)zwww.Zhttpr;zfile:zhelp file path does not exist.�darwinzfile://) rtrKrLrJrv�
startswithr|r4r)r#rtr$r$r%�path_ok6s
zHelpSource.path_okcCs6d|jd<|��}|��}|dks*|dkr.dS||fS)z,Return apparently valid (name, path) or Nonerr0N)rv�item_okr�)r#r3rtr$r$r%rMGs
zHelpSource.entry_ok)
rSrTrUrVrrHrxrurXrMr�r�rWr$r$)rRr%rl�srlcsBeZdZdZgddd��fdd�
Zdd�Zdd �Zd
d�Z�ZS)� CustomRunz�Get 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}t�j||||||d�dS)z�cli_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:)rrrN)rQr)r#rrr�rrr)rRr$r%rVszCustomRun.__init__cCsj|j}t|dd�|_t||jdddd�}t|dd|jd�|_|jd d
ddd
d�|jjd ddddd�dS)zAdd run mode on rows 10-12.T)�valueFz
Restart shell)ZvariableZonvalueZoffvaluer0r6r7)r0r8r9rr'r:r;r,)r(r)r<r=r*rrZweN)rBr�
restartvarrr
rFZ
args_errorrC)r#rB�restartr$r$r%rHbs
zCustomRun.create_extrac
CsV|j����}ytj|dd�}Wn0tk
rP}z|�t|��dSd}~XYnX|S)z6Validity check and parsing for command line arguments.T)�posixN)rDrKrL�shlexr}r^rJr`)r#Z
cli_stringr��errr$r$r%�cli_args_okoszCustomRun.cli_args_okcCs&|��}|j��}|dkrdS||fS)z3Return apparently valid (cli_args, restart) or NoneN)r�r�rK)r#r�r�r$r$r%rMys
zCustomRun.entry_ok) rSrTrUrVrrHr�rMrWr$r$)rRr%r�Ns
r��__main__)�mainzidlelib.idle_test.test_queryrF)� verbosity�exit)�run)"rVr[r|r��sysrrZtkinterrrrrrr Ztkinter.ttkr
rrr
rrZtkinter.fontrrrXrZrirlr�rSZunittestr�Zidlelib.idle_test.htestr�r$r$r$r%�<module>s( $\2
?>