
    d:                        d Z 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
e
          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z e!dk    r)ddl"m#Z#  e#ddd           ddl$m%Z%  e%eee            dS dS )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                   `     e Zd ZdZdi ddddZddZd Zdd
Zd ZddZ	ddZ
 fdZ xZ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          |            | j        dk    r|                     d| j                   |                     d| j                   |                     d| j                   |                     d| j                   |                     d| j                   |                                  |                                  |                     d|                                |                                dz  |                                 dz  z
  z   |                                |s/|                                dz  |                                 dz  z
  nd	z   fz             |                     d
d
           |sC|                                  | j                                         |                                  dS d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messager   r   r   __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#   r   r   r   r   s             /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/idlelib/query.pyr$   zQuery.__init__&   s;    
$$'''

5v 	MMOOOd F**IImT[111		.$+...($+666		.$'***		,(((&&((''))!+d.A.A.C.CA.EEG&&((!+f))++A-0D0D0F0Fq0HHH'*, 	 	 	 	e5111 	NNJ  """	 	    OKc           	         t          | d          x| _        }|                    ddd           |                    dd           t	          |dd	| j        
          }t          | | j                  | _        t          |d| j                  | _
        t          dd| j                  | _        t	          |dd| j                  | _        |                    ddddt                     | j
                            ddddt          t           z   ddg           | j                            ddddt          t           z              |                                  t%          ||d| j                  | _        t%          |d| j                  | _        | j                            ddd           | j                            ddd           dS )zCreate 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      rD   rE   
columnspanpadxrF   rD   rE   r]   r^   rF   padyr   active)rN   defaultcommandCancel)rN   rc   c   )rD   rE   r^   N)r   framegridgrid_columnconfigurer   r#   r   r   entryvarr   r9   r   r"   
error_fontentry_errorr   r	   create_extrar   r-   	button_okr+   button_cancel)r<   ok_textrf   
entrylabels       r=   r.   zQuery.create_widgetsY   s    #44444
U

!6
222""1Q"///5f $. . .
!$
335GGG
O&*> > > SU&*o7 7 7 	qaAAaHHH
qaAAac V 	 	% 	% 	%QA!!%&qS 	 	* 	* 	* 	GXtwH H H#Hdk; ; ; 	1"1555qbq99999r>   c                     d S N )r<   s    r=   rl   zQuery.create_extra}   s      r>   Nc                 $    d|z   |p| j         d<   d S )NzERROR: rN   )rk   )r<   r#   widgets      r=   	showerrorzQuery.showerror   s    /87/B	#4#V,,,r>   c                     | j                                                                         }|s|                     d           dS |S )zReturn non-blank entry or None.zblank line.N)r9   getstriprv   )r<   r9   s     r=   entry_okzQuery.entry_ok   sC    
  &&(( 	NN=)))4r>   c                     d| j         d<   |                                 }||| _        |                                  dS | j                                         dS )zIf entry is valid, bind it to 'result' and destroy tk widget.

        Otherwise leave dialog open for user to correct entry or cancel.
        r   rN   N)rk   rz   resultdestroyr9   r:   )r<   eventr9   s      r=   r-   zQuery.ok   sX    
 $& DKLLNNNNN J  """""r>   c                 <    d| _         |                                  dS )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                                                       d S rr   )grab_releasesuperr}   )r<   	__class__s    r=   r}   zQuery.destroy   s/    r>   )r?   rr   )__name__
__module____qualname____doc__r$   r.   rl   rv   rz   r-   r+   r}   __classcell__r   s   @r=   r   r   !   s          9;re1 1 1 1 1f": ": ": ":H !  C C C C  # # # #   
        r>   r   c                   0     e Zd ZdZddd fd
Zd Z xZS )SectionNamez*Get a name for a config file section name.Fr   r   c                V    t                                          ||||||           d S )N)r   r   r   r   r$   )r<   r"   r&   r#   r   r   r   r   s          r=   r$   zSectionName.__init__   s;    J &v 	 	7 	7 	7 	7 	7r>   c                 "   | j                                                                         }|s|                     d           dS t	          |          dk    r|                     d           dS || j        v r|                     d           dS |S )z2Return sensible ConfigParser section name or None.no name specified.NrO   z"name is longer than 30 characters.zname is already in use.)r9   rx   ry   rv   lenr   )r<   rR   s     r=   rz   zSectionName.entry_ok   s    z~~%%'' 	NN/0004YYr\\NN?@@@4T_$$NN45554r>   r   r   r   r   r$   rz   r   r   s   @r=   r   r      s^        00 !7 7 7 7 7 7 7
      r>   r   c                   0     e Zd ZdZddd fd
Zd Z xZS )
ModuleNamez-Get a module name for Open Module menu entry.Fr   c                V    t                                          ||||||           d S )Nr   r   r   r   )r<   r"   r&   r#   r   r   r   r   s          r=   r$   zModuleName.__init__   s;    u$V 	 	5 	5 	5 	5 	5r>   c                    | j                                                                         }|s|                     d           dS 	 t          j                            |          }nA# t          t          f$ r-}|                     t          |                     Y d}~dS d}~ww xY w||                     d           dS t          |j        t          j        j                  s|                     d           dS 	 |j                            |          }ns# t          $ r |                     d           Y dS t          $ rE 	 |j                                        }n'# t           $ r |                     d           Y Y dS w xY wY nw xY w|S )z0Return entered module name as file path or None.r   Nzmodule not found.znot a source-based module.z%loader does not support get_filename.zloader failed to get filename.)r9   rx   ry   rv   	importlibutil	find_spec
ValueErrorImportErrorstr
isinstanceloaderabcSourceLoaderget_filenameAttributeError	TypeError)r<   rR   specmsg	file_paths        r=   rz   zModuleName.entry_ok   s   z~~%%'' 	NN/0004	>++D11DDK( 	 	 	NN3s88$$$44444	 <NN.///4$+y}'ABB 	NN78884	0066II 	 	 	NNBCCC44 	 	 	 K4466		   ?@@@ttt 		 sT   A& &B$7"BB$<D F9	FEFF<F FFFr   r   s   @r=   r   r      s^        33 !5 5 5 5 5 5 5
      r>   r   c                       e Zd ZdZd ZdS )Gotoz1Get a positive line number for editor Go To Line.c                     	 t          | j                                                  }n&# t          $ r |                     d           Y d S w xY w|dk    r|                     d           d S |S )Nznot a base 10 integer.r   znot a positive integer.)intr9   rx   r   rv   )r<   linenos     r=   rz   zGoto.entry_ok   s    	))**FF 	 	 	NN344444	 Q;;NN45554s   &) AAN)r   r   r   r   rz   rs   r>   r=   r   r      s)        77	 	 	 	 	r>   r   c                   \     e Zd ZdZddi ddd fd
Zd Zd Zd Zej	        Z
d	 Zd
 Z	 xZS )
HelpSourcez,Get menu name and help source for Help menu.r   F)menuitemfilepathr   r   r   c          	      j    || _         d}t                                          |||||||           dS )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.
        zName for item on Help menu:r   N)r   r   r$   )
r<   r"   r&   r   r   r   r   r   r#   r   s
            r=   r$   zHelpSource.__init__   sQ     !/wh%fV 	 	E 	E 	E 	E 	Er>   c           	      V   | j         }t          |ddd          }t          | | j                  | _        t          || j        d          | _        t          |dd| j        	          }t          |d
d| j	                  | _
        |                    ddddddgt                     | j                            ddddt          t          z   ddg           |                    dddt          t          z              | j
                            ddddt          t          z              dS )zAdd path widjets to rows 10-12.rI   rJ   z,Help File Path: Enter URL or browse for filerK   (   )rP   r!   Browse   )rN   r!   rc   rU   rV   rW   r   rA   rZ   r[   )rD   rE   r]   r^   r`   rF      r   r_   )rD   rE   r^   rF      r\   N)rf   r   r   r   pathvarr   pathr   browse_filerj   
path_errorrg   r   r	   r
   )r<   rf   	pathlabelbrowses       r=   rl   zHelpSource.create_extra  sK   
%VMO O O	 t}55%dl"EEE	HA $ 02 2 2CE%)_6 6 6 	aRAARF 	 	! 	! 	!	aRAAacF 	 	$ 	$ 	$1"1QqS999A2!!$%aC 	 	) 	) 	) 	) 	)r>   c                 X    t          j        | |                              ||          S )N)r"   	filetypes)
initialdirinitialfile)r   Openshow)r<   r   initdirinitfiles       r=   askfilenamezHelpSource.askfilename  s,     di@@@X>>	?r>   c                 .   g d}| j                                         }|r#t          j                            |          \  }}nd }t
          d d         dk    rut          j                            t          j                            t                    d          }t          j        	                    |          st          j
                    }nt          j
                    }|                     |||          }|r| j                             |           d S 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*rZ   winDoc)r   rx   osr   splitr   joindirnamer   isdirgetcwdr   set)r<   r   r   dirbasefiles         r=   r   zHelpSource.browse_file!  s         	 |!! 		"d++ICD|u$$gll27??:#>#>FFw}}S)) &)++Cikk	355 	#LT"""""	# 	#r>   c                    | j                                                                         }|s|                     d| j                   dS |                    d          sd|dd         dk    r
|dd         }t          j                             |          s|                     d| j                   dS t          dk    rd|z   }|S )	z(Simple validity check for menu file pathzno help file path specified.N)zwww.httpr[   zfile:zhelp file path does not exist.darwinzfile://)	r   rx   ry   rv   r   
startswithr   rS   r   )r<   r   s     r=   path_okzHelpSource.path_ok9  s    y}}$$&& 	)NN94?KKK4!122 	)BQBx7""ABBx7>>$'' ?#0 0 0t8##!D(r>   c                 z    d| j         d<   |                                 }|                                 }||dn||fS )z,Return apparently valid (name, path) or Noner   rN   N)r   item_okr   )r<   rR   r   s      r=   rz   zHelpSource.entry_okJ  s>    "$||~~||~~|t|tt$Er>   )r   r   r   r   r$   rl   r   r   r   rz   r   r   r   r   s   @r=   r   r      s        22 35ruUE E E E E E E) ) )(? ? ?# # #, "G  "F F F F F F Fr>   r   c                   >     e Zd ZdZg ddd fd
Zd Zd Zd Z xZS )	CustomRunzGet settings for custom run of module.

    1. Command line arguments to extend sys.argv.
    2. Whether to restart Shell or not.
    F)cli_argsr   r   c                Z    d}t                                          ||||||           dS )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:r   Nr   )r<   r"   r&   r   r   r   r#   r   s          r=   r$   zCustomRun.__init__Y  sC     9whf 	 	. 	. 	. 	. 	.r>   c                    | j         }t          | d          | _        t          || j        ddd          }t	          |dd| j                  | _        |                    d	d
ddd           | j                            d	dddd           dS )zAdd run mode on rows 10-12.T)valueFzRestart shell)variableonvalueoffvaluerN   rU   rV   rW   r   rA   rZ   r[   rI   r\   r   weN)rf   r   
restartvarr   r   rj   
args_errorrg   )r<   rf   restarts      r=   rl   zCustomRun.create_extrae  s    
$T666edot',?D D DCE%)_6 6 6 	A2!!CHHHA2!!$( 	 	* 	* 	* 	* 	*r>   c                     | j                                                                         }	 t          j        |d          }n:# t
          $ r-}|                     t          |                     Y d}~dS d}~ww xY w|S )z6Validity check and parsing for command line arguments.T)posixN)r9   rx   ry   shlexr   r   rv   r   )r<   
cli_stringr   errs       r=   cli_args_okzCustomRun.cli_args_okr  s    Z^^%%++--
	{:T:::HH 	 	 	NN3s88$$$44444	 s   A 
A;"A66A;c                 l    |                                  }| j                                        }|dn||fS )z4Return apparently valid (cli_args, restart) or None.N)r   r   rx   )r<   r   r   s      r=   rz   zCustomRun.entry_ok|  s:    ##%%/%%'''tth-@@r>   )	r   r   r   r   r$   rl   r   rz   r   r   s   @r=   r   r   Q  s          35e
. 
. 
. 
. 
. 
. 
.* * *  A A A A A A Ar>   r   __main__)mainzidlelib.idle_test.test_queryr   F)	verbosityexit)run)&r   importlib.utilr   importlib.abcr   r   sysr   r   tkinterr   r   r   r   r	   r
   tkinter.ttkr   r   r   r   r   r   tkinter.fontr   tkinter.simpledialogr   r   r   r   r   r   r   r   unittestr   idlelib.idle_test.htestr   rs   r>   r=   <module>r      sn   * % $ $ $ $ $ $ $ 				  $ $ $ $ $ $ $ $ < < < < < < < < < < < < < < < < @ @ @ @ @ @ @ @ @ @ @ @ @ @             . . . . . .    H   D    %   0' ' ' ' ' ' ' 'T    5    ZF ZF ZF ZF ZF ZF ZF ZFx/A /A /A /A /A /A /A /Ad zD	'15AAAA++++++Cz9%%%%% r>   