Current File : //usr/local/apps/python3/lib/python3.11/idlelib/__pycache__/query.cpython-311.opt-1.pyc
�

�Ke�:���dZddlZddlZddlZddlZddlmZmZddl	m
Z
mZmZm
Z
mZmZddlmZmZmZmZmZddl	mZddlmZddlmZGd	�d
e
��ZGd�de��ZGd
�de��ZGd�de��ZGd�de��ZGd�de��Z e!dkr)ddl"m#Z#e#ddd���ddl$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 <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)�Font)�
_setup_dialogc�`��eZdZdZdiddd�d�Zdd�Zd�Zdd
�Zd�Zdd�Z	dd
�Z
�fd�Z�xZS)�QueryzoBase class for getting verified answer from a user.

    For this base class, accept any non-blank string.
    �F��text0�
used_names�_htest�_utestc��||_||_||_||_t	j||��|���|�|��|�|��|s|�	��t|��|jdkr|�d|j
��|�d|j
��|�d|j
��|�d|j��|�d|j��|���|���|�d|���|���dz|���dzz
z|���|s/|���dz|���dzz
nd	zfz��|�d
d
���|sC|���|j���|���dSdS)
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
        �aquaz<Command-.>z<Key-Escape>�WM_DELETE_WINDOWz<Key-Return>z
<KP_Enter>z+%d+%d��F)�height�widthN)�parent�messagerrr�__init__�withdraw�title�	transient�grab_setr�_windowingsystem�bind�cancel�protocol�ok�create_widgets�update_idletasks�geometry�winfo_rootx�winfo_width�winfo_reqwidth�winfo_rooty�winfo_height�winfo_reqheight�	resizable�	deiconify�entry�	focus_set�wait_window)�selfr"r&r#rrrrs        �7/usr/local/apps/python3/lib/python3.11/idlelib/query.pyr$zQuery.__init__&s;����������
�$�����$��'�'�'��
�
�����
�
�5�������v�����	��M�M�O�O�O��d����� �F�*�*��I�I�m�T�[�1�1�1��	�	�.�$�+�.�.�.��
�
�(�$�+�6�6�6��	�	�.�$�'�*�*�*��	�	�,���(�(�(��������������
�
���&�&�(�(��'�'�)�)�!�+�d�.A�.A�.C�.C�A�.E�E�G��&�&�(�(�!�+�f�)�)�+�+�A�-��0D�0D�0F�0F�q�0H�H�H�'*�,���	�	�	�	
���e�5��1�1�1��	��N�N�����J� � �"�"�"���������	�	��OKc	��t|d���x|_}|�ddd���|�dd���t	|dd	|j�
��}t
||j��|_t|d|j���|_
td
d|j���|_
t	|dd|j
���|_|�ddddt���|j
�ddddtt zddg���|j�ddddtt z���|���t%||d|j���|_t%|d|j���|_|j�ddd���|j�ddd���dS)z�Create entry (rows, extras, buttons.

        Entry stuff on rows 0-2, spanning cols 0-2.
        Buttons on row 99, cols 1, 2.
        �
)�paddingr�news)�column�row�sticky�)�weight�w�left��anchor�justify�text�)r!�textvariable�
TkCaptionFontT)�name�exists�root� �red�rN�
foreground�font���rDrE�
columnspan�padxrF�rDrEr]r^rF�padyr�active)rN�default�command�Cancel)rNrc�c)rDrEr^N)r�frame�grid�grid_columnconfigurerr#rr�entryvarr
r9rr"�
error_font�entry_errorrr	�create_extrarr-�	button_okr+�
button_cancel)r<�ok_textrf�
entrylabels    r=r.zQuery.create_widgetsYs���#�4��4�4�4�4��
�U�
�
�
�!��6�
�2�2�2�
�"�"�1�Q�"�/�/�/��5��f� $��.�.�.�
�!�$��
�3�3��
��5����G�G�G��
��O�&*���>�>�>��� ��S�U�&*�o�7�7�7���	���q�a�A�A�a��H�H�H��
���q�a�A�A�a��c� ��V�	�	%�	%�	%�����Q�A�!�!�%&�q�S�	�	*�	*�	*�	
��������G�X�t�w�H�H�H���#��H�d�k�;�;�;���	
����1�"�1��5�5�5�����q�b�q��9�9�9�9�9r>c��dS�N�)r<s r=rlzQuery.create_extra}s���r>Nc�$�d|z|p|jd<dS)NzERROR: rN)rk)r<r#�widgets   r=�	showerrorzQuery.showerrors��/8�7�/B��	#�4�#�V�,�,�,r>c��|j������}|s|�d��dS|S)zReturn non-blank entry or None.zblank line.N)r9�get�striprv)r<r9s  r=�entry_okzQuery.entry_ok�sC���
��� � �&�&�(�(���	��N�N�=�)�)�)��4��r>c��d|jd<|���}|�||_|���dS|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.
        rrNN)rkrz�result�destroyr9r:)r<�eventr9s   r=r-zQuery.ok�sX��
$&���� ��
�
�������D�K��L�L�N�N�N�N�N�
�J� � �"�"�"�"�"r>c�<�d|_|���dS)z0Set dialog result to None and destroy tk widget.N)r|r})r<r~s  r=r+zQuery.cancel�s������������r>c�p��|���t�����dSrr)�grab_release�superr})r<�	__class__s �r=r}z
Query.destroy�s/���������
���������r>)r?rr)
�__name__�
__module__�__qualname__�__doc__r$r.rlrvrzr-r+r}�
__classcell__�r�s@r=rr!s����������9;�r��e�1�1�1�1�1�f":�":�":�":�H!� � �C�C�C�C����#�#�#�#�����
��������r>rc�0��eZdZdZddd��fd�
Zd�Z�xZS)�SectionNamez*Get a name for a config file section name.F�rrc�V��t���||||||���dS)N)rrr�r�r$)r<r"r&r#rrrr�s       �r=r$zSectionName.__init__�s;���
��������J� &�v�	�	7�	7�	7�	7�	7r>c�"�|j������}|s|�d��dSt	|��dkr|�d��dS||jvr|�d��dS|S)z2Return sensible ConfigParser section name or None.�no name specified.NrOz"name is longer than 30 characters.zname is already in use.)r9rxryrv�lenr)r<rRs  r=rzzSectionName.entry_ok�s����z�~�~���%�%�'�'���	��N�N�/�0�0�0��4�
��Y�Y�r�\�\��N�N�?�@�@�@��4�
�T�_�
$�
$��N�N�4�5�5�5��4��r>�r�r�r�r�r$rzr�r�s@r=r�r��s^�������0�0�!��7�7�7�7�7�7�7�
������r>r�c�0��eZdZdZddd��fd�
Zd�Z�xZS)�
ModuleNamez-Get a module name for Open Module menu entry.Fr�c�V��t���||||||���dS)N�rrrr�)r<r"r&r#rrrr�s       �r=r$zModuleName.__init__�s;���
��������u�$�V�	�	5�	5�	5�	5�	5r>c��|j������}|s|�d��dS	tj�|��}nA#ttf$r-}|�t|����Yd}~dSd}~wwxYw|�|�d��dSt|jtjj
��s|�d��dS	|j�|��}ns#t$r|�d��YdSt$rE	|j���}n'#t $r|�d��YYdSwxYwYnwxYw|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.)r9rxryrv�	importlib�util�	find_spec�
ValueError�ImportError�str�
isinstance�loader�abc�SourceLoader�get_filename�AttributeError�	TypeError)r<rR�spec�msg�	file_paths     r=rzzModuleName.entry_ok�s����z�~�~���%�%�'�'���	��N�N�/�0�0�0��4�	��>�+�+�D�1�1�D�D���K�(�	�	�	��N�N�3�s�8�8�$�$�$��4�4�4�4�4�����	�����<��N�N�.�/�/�/��4��$�+�y�}�'A�B�B�	��N�N�7�8�8�8��4�	���0�0��6�6�I�I���	�	�	��N�N�B�C�C�C��4�4��	�	�	�
� �K�4�4�6�6�	�	���
�
�
����?�@�@�@��t�t�t�
�����	�	�����sT�A&�&B$�7"B�B$�<D�F�9	F�E�F�F�<F�F�F�Fr�r�s@r=r�r��s^�������3�3�!��5�5�5�5�5�5�5�
������r>r�c��eZdZdZd�ZdS)�Gotoz1Get a positive line number for editor Go To Line.c���	t|j�����}n&#t$r|�d��YdSwxYw|dkr|�d��dS|S)Nznot a base 10 integer.rznot a positive integer.)�intr9rxr�rv)r<�linenos  r=rzz
Goto.entry_ok�s��	������)�)�*�*�F�F���	�	�	��N�N�3�4�4�4��4�4�	�����Q�;�;��N�N�4�5�5�5��4��
s�&)�A�AN)r�r�r�r�rzrsr>r=r�r��s)������7�7�	�	�	�	�	r>r�c�\��eZdZdZddiddd��fd�
Zd�Zd�Zd�Zej	Z
d	�Zd
�Z	�xZS)�
HelpSourcez,Get menu name and help source for Help menu.rF)�menuitem�filepathrrrc	�j��||_d}t���|||||||���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:rN)r�r�r$)
r<r"r&r�r�rrrr#r�s
         �r=r$zHelpSource.__init__�sQ���!��
�/��
�������w�h�%�f�V�	�	E�	E�	E�	E�	Er>c	�V�|j}t|ddd���}t||j��|_t||jd���|_t|dd|j�	��}t|d
d|j	���|_
|�d
ddddd
gt���|j�d
dddttzdd
g���|�dddttz���|j
�d
dddttz���dS)zAdd path widjets to rows 10-12.rIrJz,Help File Path: Enter URL or browse for filerK�()rPr!�Browse�)rNr!rcrUrVrWrrArZr[)rDrEr]r^r`rF�rr_)rDrEr^rF�r\N)rfrrr��pathvarr
�pathr�browse_filerj�
path_errorrgrr	r
)r<rf�	pathlabel�browses    r=rlzHelpSource.create_extrasK���
���%��V�M�O�O�O�	� ��t�}�5�5����%�d�l�"�E�E�E��	���H�A� $� 0�2�2�2����C�E�%)�_�6�6�6���	���a�R�A�A�R��F��	�	!�	!�	!��	���a�R�A�A�a��c���F�	�	$�	$�	$����1�"�1�Q�q�S��9�9�9�����A�2�!�!�$%�a�C�	�	)�	)�	)�	)�	)r>c�X�tj||����||���S)N)r"�	filetypes)�
initialdir�initialfile)r�Open�show)r<r��initdir�initfiles    r=�askfilenamezHelpSource.askfilenames,����d�i�@�@�@����X��>�>�	?r>c�.�gd�}|j���}|r#tj�|��\}}n�d}t
dd�dkrutj�tj�t��d��}tj�	|��stj
��}ntj
��}|�|||��}|r|j�|��dSdS)N))z
HTML Filesz*.htm *.html�TEXT)z	PDF Filesz*.pdfr�)zWindows Help Filesz*.chm)z
Text Filesz*.txtr�)z	All Files�*rZ�win�Doc)
r�rx�osr��splitr�join�dirnamer�isdir�getcwdr��set)r<r�r��dir�base�files      r=r�zHelpSource.browse_file!s��� � � �	��|���!�!���		"���
�
�d�+�+�I�C����D�����|�u�$�$��g�l�l�2�7�?�?�:�#>�#>��F�F���w�}�}�S�)�)�&��)�+�+�C���i�k�k�����	�3��5�5���	#��L���T�"�"�"�"�"�	#�	#r>c��|j������}|s|�d|j��dS|�d��sd|dd�dkr
|dd�}tj�|��s|�d|j��dStdkrd|z}|S)	z(Simple validity check for menu file pathzno help file path specified.N)zwww.�httpr[zfile:zhelp file path does not exist.�darwinzfile://)	r�rxryrvr��
startswithr�rSr)r<r�s  r=�path_okzHelpSource.path_ok9s����y�}�}���$�$�&�&���	)��N�N�9�4�?�K�K�K��4����!1�2�2�	)��B�Q�B�x�7�"�"��A�B�B�x���7�>�>�$�'�'�
����?�#��0�0�0��t��8�#�#�!�D�(���r>c�z�d|jd<|���}|���}|�|�dn||fS)z,Return apparently valid (name, path) or NonerrNN)r��item_okr�)r<rRr�s   r=rzzHelpSource.entry_okJs>��"$������|�|�~�~���|�|�~�~���|�t�|�t�t�$���Er>)
r�r�r�r�r$rlr�r�r�rzr�r�r�r�s@r=r�r��s��������2�2�35�r��u�U�E�E�E�E�E�E�E�)�)�)�(?�?�?�#�#�#�,�"�G����"F�F�F�F�F�F�Fr>r�c�>��eZdZdZgddd��fd�
Zd�Zd�Zd�Z�xZS)�	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_argsrrc�Z��d}t���||||||���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:r�Nr�)r<r"r&r�rrr#r�s       �r=r$zCustomRun.__init__YsC���9��
�������w�h��f�	�	.�	.�	.�	.�	.r>c��|j}t|d���|_t||jddd���}t	|dd|j���|_|�d	d
ddd
���|j�d	dddd���dS)zAdd run mode on rows 10-12.T)�valueFz
Restart shell)�variable�onvalue�offvaluerNrUrVrWrrArZr[rIr\r��weN)rfr�
restartvarrrrj�
args_errorrg)r<rf�restarts   r=rlzCustomRun.create_extraes����
��$�T��6�6�6����e�d�o�t�',�?�D�D�D����C�E�%)�_�6�6�6���	���A�2�!�!�C��H�H�H�����A�2�!�!�$(�	�	*�	*�	*�	*�	*r>c��|j������}	tj|d���}n:#t
$r-}|�t|����Yd}~dSd}~wwxYw|S)z6Validity check and parsing for command line arguments.T)�posixN)r9rxry�shlexr�r�rvr�)r<�
cli_stringr��errs    r=�cli_args_okzCustomRun.cli_args_okrs����Z�^�^�%�%�+�+�-�-�
�	��{�:�T�:�:�:�H�H���	�	�	��N�N�3�s�8�8�$�$�$��4�4�4�4�4�����	�����s�A�
A;�"A6�6A;c�l�|���}|j���}|�dn||fS)z4Return apparently valid (cli_args, restart) or None.N)r�r�rx)r<r�r�s   r=rzzCustomRun.entry_ok|s:���#�#�%�%���/�%�%�'�'���'�t�t�h��-@�@r>)	r�r�r�r�r$rlr�rzr�r�s@r=r�r�Qs����������35��e�
.�
.�
.�
.�
.�
.�
.�*�*�*����A�A�A�A�A�A�Ar>r��__main__)�mainzidlelib.idle_test.test_queryrF)�	verbosity�exit)�run)&r��importlib.utilr��
importlib.abcr�r��sysrr�tkinterrrrrr	r
�tkinter.ttkrrr
rrr�tkinter.fontr�tkinter.simpledialogrrr�r�r�r�r�r��unittestr��idlelib.idle_test.htestr�rsr>r=�<module>r�sn��
�
�*%�$�$�$�$�$�$�$�	�	�	�	�����$�$�$�$�$�$�$�$�<�<�<�<�<�<�<�<�<�<�<�<�<�<�<�<�@�@�@�@�@�@�@�@�@�@�@�@�@�@�������������.�.�.�.�.�.������H����D�����%����0'�'�'�'�'��'�'�'�T
�
�
�
�
�5�
�
�
� ZF�ZF�ZF�ZF�ZF��ZF�ZF�ZF�x/A�/A�/A�/A�/A��/A�/A�/A�d�z����������D�	'�1�5�A�A�A�A�+�+�+�+�+�+��C��z�9�%�%�%�%�%��r>