
    Je^O                     4   d Z ddlmZ ddlmZ ddlmZmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ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# dd	l$m%Z% dd
l&m'Z'  ed      Z( ed      Z) ed      Z* ed      Z+ ed      Z,dZ-dZ.dZ/dZ0dZ1dZ2dZ3 ed      Z4dZ5 ed      Z6 ed      Z7 ed      Z8 ed      Z9 ed      Z: ed      Z; ed      Z< G d  d!e=      Z>d" Z?d# Z@d$ ZA G d% d&e      ZB G d' d(e      ZC G d) d*eC      ZD G d+ d,eC      ZEy)-z(Run dialogs and widgets and data models.    N)getexistingdirectory)QSizeQtSignalSlot)	QCheckBox	QComboBoxQDialogQDialogButtonBoxQFrameQGridLayout	QGroupBoxQHBoxLayoutQLabel	QLineEditQMessageBoxQPushButtonQRadioButtonQSizePolicyQScrollAreaQStackedWidgetQVBoxLayoutQWidget)_)CONF)ima)getcwd_or_home)create_toolbuttonz#Run file with default configurationz"Run file with custom configurationzExecute in current consolezExecute in a dedicated consolez&Execute in an external system terminalzdefault/interpreter/currentzdefault/interpreter/dedicatedzdefault/interpreter/systermz!default/wdir/use_script_directoryzdefault/wdir/use_cwd_directoryz default/wdir/use_fixed_directoryzdefault/wdir/fixed_directoryz"Always show %s on a first file runopen_on_firstrunz%Remove all variables before executionz2Run in console's namespace instead of an empty onez+Directly enter debugging when errors appearz0Interact with the Python console after executionz(The directory of the file being executedzThe current working directoryzThe following directory:c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
RunConfigurationRun configurationNc                 @   d | _         d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d | _        d | _        d | _        d | _        | j#                  t%        j&                  ddi              y )Nrundefaultconfiguration)default)r&   argsargs_enabledwdirwdir_enabledcurrentsysterminteractpost_mortempython_argspython_args_enabledclear_namespaceconsole_namespacefile_dircw_dir	fixed_dirdirsetr   getselffnames     </usr/lib/python3/dist-packages/spyder/plugins/run/widgets.py__init__zRunConfiguration.__init__<   s    	 	 #' #!%%!7DE    c                 X   |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  dt	        j                   dt
        d            | _        |j                  d	t	        j                   dt        d            | _        |j                  d
t	        j                   dd
d            | _	        |j                  dt	        j                   ddd            | _
        |j                  dd      | _        |j                  dd      | _        |j                  dt	        j                   ddd            | _        |j                  dt	        j                   ddd            | _        |j                  dt	        j                   dt        d            | _        |j                  dt	        j                   dt"        d            | _        |j                  dt	        j                   dt&        d            | _        |j                  dd      | _        y )Nr&   Tr'    args/enabledFr+   r$   r,   r-   r.   r/   python_args/enabledr1   r2   r3   r4   r5   r6   )r8   r&   r'   r(   r   CURRENT_INTERPRETER_OPTIONr+   SYSTERM_INTERPRETER_OPTIONr,   r-   r.   r/   r0   r1   r2   WDIR_USE_SCRIPT_DIR_OPTIONr3   WDIR_USE_CWD_DIR_OPTIONr4   WDIR_USE_FIXED_DIR_OPTIONr5   r6   r:   optionss     r<   r7   zRunConfiguration.setQ   s   {{9d3KK+	#KK>{{988E+EtLN{{988E+EuMOJ88E:u=?";;}88E=%@B";;}b9#*;;/De#L &{{+<$(HHU4Eu$M O!(-@#'88E3F#N"PJ88E+EtLNkk(88E+BEJL [88E+DeLN;;ub)r>   c                    i d| j                   d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                   S )Nr&   rA   r'   zworkdir/enabledworkdirr+   r,   r-   r.   rB   r/   r1   r2   r3   r4   r5   r6   )r&   r(   r'   r*   r)   r+   r,   r-   r.   r0   r/   r1   r2   r3   r4   r5   r6   r:   s    r<   r8   zRunConfiguration.getk   s&   4<< 1 1 		 "4#4#4	
 499 4<< 4<< DMM t// &t'?'? t// "4#7#7 $T%;%; DMM $++  T^^!" txx# 	r>   c                     | j                   S N)r6   rL   s    r<   get_working_directoryz&RunConfiguration.get_working_directory   s    hhr>   c                 4    | j                   r| j                  S yNr@   )r(   r'   rL   s    r<   get_argumentszRunConfiguration.get_arguments   s    99r>   c                 4    | j                   r| j                  S yrQ   )r0   r/   rL   s    r<   get_python_argumentsz%RunConfiguration.get_python_arguments   s    #####r>   rN   )
__name__
__module____qualname____doc__r=   r7   r8   rO   rR   rT    r>   r<   r!   r!   9   s$    F**4*r>   r!   c                     t        j                  ddd      } 	 t        j                  ddg       D cg c]  \  }}t        j                  |      r||f  c}}d |  S c c}}w # t        $ r t        j
                  ddg        g cY S w xY wNr$   history   configurations)r   r8   ospisfile
ValueErrorr7   )history_countfilenamerI   s      r<   _get_run_configurationsrd      s    HHUIr2M)-%9I2)N)%Hg::h' 7# ))7-9 	9 )  ("-	s"   A# #AA# A# #"BBc                 f    t        j                  ddd      }t        j                  dd| d |        y r[   )r   r8   r7   )r^   rb   s     r<   _set_run_configurationsrf      s,    HHUIr2MHHU$n^m&DEr>   c                 t    t               }|D ])  \  }}| |k(  st               }|j                  |       |c S  y)z'Return script *fname* run configurationN)rd   r!   r7   )r;   r^   rc   rI   runconfs        r<   get_run_configurationri      s?    ,.N+ 'H&(GKK N	r>   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
RunConfigOptionszRun configuration optionsNc                    t        j                  | |       d | _        t               | _        t        j                  dt        d      }t        t              | _
        t        t              | _        t        t        d            }|j                  d       | j                  j                   j#                  |j$                         t'        |      }t        t(              | _        |j-                  | j*                         t        t.              | _        |j-                  | j0                         t        t2              | _        |j-                  | j4                         t               }|j                  d       | j4                  j                   j#                  |j$                         t7               }|j9                  |       t;        t<              | _        |j-                  | j>                  dddd       t;        t        d            | _         |j-                  | j@                  d	d       tC               | _"        | j@                  j                   j#                  | jD                  j$                         | jD                  j%                  d       | jD                  jG                  t        d
             |j-                  | jD                  d	d       |j-                  |       t        t        d            }|j                  d       | j                  j                   j#                  |j$                         t7        |      }t;        tH              | _%        |j-                  | jJ                  dd       t;        tL              | _'        |j-                  | jN                  dd       t;        tP              | _)        |j-                  | jR                  dd       t;        t        d            | _*        |j-                  | jT                  d	d       tC               | _+        | jT                  j                   j#                  | jV                  j$                         | jV                  j%                  d       |j-                  | jV                  d	d       t        t        d            }	|	j                  d       | j                  j                   j#                  |	j$                         t'        |	      }
t        tX              | _-        |
j-                  | jZ                         t        t\              | _/        |
j-                  | j^                         ta               }t        tb              | _2        |j-                  | jd                         tC               | _3        | jd                  j                   j#                  | jf                  j$                         | jf                  j%                  d       |j-                  | jf                         ti        | | jj                  tm        jn                  d      t        d            }|j-                  |       |
jq                  |       t;        tr        t        d      z        | _:        | jt                  jv                  j#                  | jx                         | jt                  j{                  |       t'        |       }|j-                  | j                         |j-                  | j                         |j-                  |       |j-                  |       |j-                  |	       |j-                  | jt                         |j}                  d       y )Nr$   FConsoleT   r   zCommand line options:   z4<b>-u</b> is added to the other options you set herezGeneral settings   zWorking directory settingsDirOpenIconSelect directory)	triggeredicontipzthis dialogd   )?r   r=   r6   r!   rh   r   r8   ALWAYS_OPEN_FIRST_RUN_OPTIONr   RUN_DEFAULT_CONFIGrun_default_config_radioRUN_CUSTOM_CONFIGrun_custom_config_radior   r   setDisabledtoggledconnect
setEnabledr   CURRENT_INTERPRETERcurrent_radio	addWidgetDEDICATED_INTERPRETERdedicated_radioSYSTERM_INTERPRETERsysterm_radior   	setLayoutr   INTERACTinteract_cbpclo_cbr   	pclo_edit
setToolTipCLEAR_ALL_VARIABLESclear_var_cbCONSOLE_NAMESPACEconsole_ns_cbPOST_MORTEMpost_mortem_cbclo_cbclo_editFILE_DIRfile_dir_radioCW_DIR	cwd_radior   	FIXED_DIRfixed_dir_radiowd_editr   select_directoryr   ru   	addLayoutALWAYS_OPEN_FIRST_RUNfirstrun_cbclickedset_firstrun_o
setChecked
addStretch)r:   parent
firstrun_ointerpreter_groupinterpreter_layoutexternal_groupexternal_layoutcommon_groupcommon_layout
wdir_groupwdir_layoutfixed_dir_layout
browse_btnlayouts                 r<   r=   zRunConfigOptions.__init__   sy   v&')XXe%A5I
 )55G(H%'34E'F$ &a	l3%%d+$$,,44((	* )):;)*=>$$T%7%78+,AB$$T%9%9:)*=>$$T%7%78 !""4(""**>+D+DE%-  1$X.!!$"2"2Aq!R@ #:!;<!!$,,15"$$T^^%>%>?!!%(!!! %A #B 	C!!$..!Q7$$^4 !#5!67  &$$,,44\5L5LM#L1%&9: 1 11a8&'89 2 2Aq9'4 3 3Q:"9 :;Q2!##DMM$<$<=  'q!4 q!=>?
t$$$,,44Z5J5JK!*-*84d112%f-dnn-&=+I6""4#7#78 {$$,,T\\-D-DE&""4<<0&++-($%	
 	"":../ %%:Q}=M%MN  (()<)<=##J/T"667556*+&$))*#r>   c                     t        | j                  j                               }t        j                  |      s
t               }t        | t        d       |      }|r#| j                  j                  |       || _	        yy)rs   N)
strr   textr_   isdirr   r   r   setTextr6   )r:   basedir	directorys      r<   r   z!RunConfigOptions.select_directory#  sb    dll'')*yy!$&G(q1C/DgN	LL  + DH r>   c                 \   | j                   j                  |       | j                   j                  r| j                  j	                  d       n| j
                  j	                  d       | j                  j	                  | j                   j                         | j                  j                  | j                   j                         | j                   j                  r| j                  j	                  d       nM| j                   j                  r| j                  j	                  d       n| j                  j	                  d       | j                   j	                  | j                   j"                         | j$                  j	                  | j                   j&                         | j(                  j	                  | j                   j*                         | j,                  j                  | j                   j.                         | j0                  j	                  | j                   j2                         | j4                  j	                  | j                   j6                         | j8                  j	                  | j                   j:                         | j<                  j	                  | j                   j>                         | j@                  j	                  | j                   jB                         | j                   jD                  | _"        | jF                  j                  | jD                         y )NT)$rh   r7   r&   rz   r   r|   r   r(   r   r   r'   r+   r   r,   r   r   r   r-   r   r.   r   r0   r   r/   r   r1   r   r2   r   r3   r   r4   r   r5   r6   r   rH   s     r<   r7   zRunConfigOptions.set-  s   !<<))44T:((33D9t||889dll//0<<))$/\\!!))$/  ++D1##DLL$9$9:&&t||'?'?@ @ @At||778$$T\\%A%AB%%dll&D&DE&&t||'<'<=!!$,,"5"56''(>(>?<<##TXX&r>   c                 (   | j                   j                         | j                  _        | j                  j                         | j                  _        t        | j                  j                               | j                  _	        | j                  j                         | j                  _        | j                  j                         | j                  _        | j                  j                         | j                  _        | j                   j                         | j                  _        | j$                  j                         | j                  _        t        | j(                  j                               | j                  _        | j,                  j                         | j                  _        | j0                  j                         | j                  _        | j4                  j                         | j                  _        | j8                  j                         | j                  _        | j<                  j                         | j                  _        | j@                  j                         | j                  _!        | j                  jE                         S rN   )#rz   	isCheckedrh   r&   r   r(   r   r   r   r'   r   r+   r   r,   r   r-   r   r.   r   r0   r   r/   r   r1   r   r2   r   r3   r   r4   r   r5   r   r6   r8   rL   s    r<   r8   zRunConfigOptions.getG  s   #<<FFH$(KK$9$9$;! 2 2 45#11;;=#11;;= $ 0 0 : : <#'#6#6#@#@#B +/<<+A+A+C(#&t~~':':'<#= '+'8'8'B'B'D$)-););)E)E)G& $ 3 3 = = ?"nn668!%!5!5!?!?!A<<,,.||!!r>   c                    t        | j                  j                               }| j                  j	                         rt        j                  |      ryt        j                  | t        d      t        d      |z         y)NTr"   z:The following working directory is not valid:<br><b>%s</b>F)
r   r   r   r   r   r_   r   r   criticalr   )r:   r)   s     r<   is_validzRunConfigOptions.is_validY  sl    4<<$$&'##--/399T?  q)<'=!" $= ">@D"EF r>   c                 j    t        j                  dt        | j                  j	                                y )Nr$   )r   r7   rx   r   r   rL   s    r<   r   zRunConfigOptions.set_firstrun_oc  s%    4!!++-	/r>   rN   )
rU   rV   rW   rX   r=   r   r7   r8   r   r   rY   r>   r<   rk   rk      s%    #un!'4"$/r>   rk   c                   F    e Zd ZdZ ee      Zd	dZd Zd Z	d Z
d Zd Zy)
BaseRunConfigDialogz)Run configuration dialog box, base widgetNc                 N   t        j                  | |       | j                  | j                         t        j
                   z         | j                  t        j                         | j                  t        j                  d             t               }| j                  |       y )Nrun_settings)r
   r=   setWindowFlagswindowFlagsr   WindowContextHelpButtonHintsetAttributeWA_DeleteOnClosesetWindowIconr   ru   r   r   )r:   r   r   s      r<   r=   zBaseRunConfigDialog.__init__l  s{    v&""@"@!@@	B 	"--.388N34vr>   c                     | j                         }|D ]5  }t        |t              r|j                  |       %|j	                  |       7 |S )z-Add widgets/spacing to dialog vertical layout)r   
isinstanceint
addSpacingr   )r:   widgets_or_spacingsr   widget_or_spacings       r<   add_widgetszBaseRunConfigDialog.add_widgets{  sM    !4 	4+S1!!"34  !23		4
 r>   c                    t        |      }|j                  t        d      t         j                        }|j                  j                  | j                         |j                  j                  | j                         |j                  j                  | j                         t               }|j                  d       |j                  |       | j                         j                  |       y)z8Create dialog button box and add it to the dialog layoutRunrn   N)r   	addButtonr   
AcceptRoler   r   run_btn_clickedacceptedacceptrejectedrejectr   r   r   r   r   )r:   stdbtnsbboxrun_btn	btnlayouts        r<   add_button_boxz"BaseRunConfigDialog.add_button_box  s    (..5+;+F+FG 4 45dkk*dkk*M	QD!	*r>   c                     t        j                  | |       | j                  j                  | j	                                y)zn
        Reimplement Qt method to be able to save the widget's size from the
        main application
        N)r
   resizeEventsize_changeemitsize)r:   events     r<   r   zBaseRunConfigDialog.resizeEvent  s.    
 	D%(diik*r>   c                      yzRun button was just clickedNrY   rL   s    r<   r   z#BaseRunConfigDialog.run_btn_clicked  s    r>   c                     t         )4Setup Run Configuration dialog with filename *fname*)NotImplementedErrorr9   s     r<   setupzBaseRunConfigDialog.setup  s    !!r>   rN   )rU   rV   rW   rX   r   r   r   r=   r   r   r   r   r   rY   r>   r<   r   r   h  s,    3-K
++"r>   r   c                   >    e Zd ZdZddZd Z e       d        Zd Zy)RunConfigOneDialogz1Run configuration dialog box: single file versionNc                 L    t         j                  | |       d | _        d | _        y rN   )r   r=   rc   runconfigoptionsr:   r   s     r<   r=   zRunConfigOneDialog.__init__  s!    $$T62 $r>   c                    || _         t        |       | _        | j                  j                  t	        |      j                                t        |       }|j                  | j                         |j                  d       |j                  d       | j                  |       | j                  t        j                         | j                  t        d      t!        j"                  |      z         y)r   i0  TzRun settings for %sN)rc   rk   r   r7   r!   r8   r   	setWidgetsetMinimumWidthsetWidgetResizabler   r   r   CancelsetWindowTitler   r_   basename)r:   r;   
scrollareas      r<   r   zRunConfigOneDialog.setup  s     0 6!!"25"9"="="?@ &
T223""3'%%d+$,334A34s||E7JJKr>   c                     | j                   j                         syt               }|j                  d| j                  | j                   j                         f       t        |       t        j                  |        y)Reimplement Qt methodNr   )	r   r   rd   insertrc   r8   rf   r
   r   )r:   r^   s     r<   r   zRunConfigOneDialog.accept  s]     $$--/02a$--1F1F1J1J1L!MN/tr>   c                 .    | j                   j                  S rN   )r   rh   rL   s    r<   get_configurationz$RunConfigOneDialog.get_configuration  s     $$,,,r>   rN   )	rU   rV   rW   rX   r=   r   r   r   r   rY   r>   r<   r   r     s+    ;%
L 
V -r>   r   c                   *    e Zd ZdZddZd Zd Zd Zy)RunConfigDialogz3Run configuration dialog box: multiple file versionNc                 Z    t         j                  | |       d | _        d | _        d | _        y rN   )r   r=   file_to_runcombostackr   s     r<   r=   zRunConfigDialog.__init__  s(    $$T62

r>   c                 T    t        | j                  j                               | _        yr   )r   r  currentTextr   rL   s    r<   r   zRunConfigDialog.run_btn_clicked  s    tzz5578r>   c                    t        t        d            }t               | _        | j                  j	                  d       t               | _        t               }t        |      D ]  \  }\  }}||k(  s n. |j                  d|t        |      j                         f       d}|D ]y  \  }}t        |       }|j                  |       |j                         j                  dddd       | j                  j!                  |       | j                  j#                  |       { | j                  j$                  j'                  | j                  j(                         | j                  j)                  |       | j+                  || j                  d| j                        }t-               }	|	j/                  |       t1        |       }
|
j3                  |	       |
j5                  d       |
j7                  d       t9        |       }|j#                  |
       | j;                  t<        j>                  t<        j@                  z         | jC                  t        d             y)	r   zSelect a run configuration:r]   r   
   iX  TzRun configuration per fileN)"r   r   r	   r  setMaxVisibleItemsr   r  rd   	enumerater   r!   r8   rk   r7   r   setContentsMarginsaddItemr   currentIndexChangedr   setCurrentIndexr   r   r   r   r   r   r   r   r   r   Okr   r   )r:   r;   combo_labelr^   indexrc   rI   widgetr   widget_dialogr   scroll_layouts               r<   r   zRunConfigDialog.setup  s   Q<=>[


%%b)#%
02*3N*C 	&E&Hg 	 !!!e-=e-D-H-H-J%KLE!/ 	)Hg%d+FJJwMMO..q!Q:JJx(JJ  (	) 	

&&..tzz/I/IJ

""5)!!+tzz2tzzJ	' &
]+""3'%%d+#D)
+,//2B2I2IIJA:;<r>   c                    g }t        | j                  j                               D ]  }t        | j                  j                  |            }| j                  j                  |      }|| j                  j                         k(  r|j                         s y|j                         }|j                  ||f        t        |       t        j                  |        y)r   N)ranger  countr   r  itemTextr  currentIndexr   r8   appendrf   r
   r   )r:   r^   r  rc   r   rI   s         r<   r   zRunConfigDialog.accept  s    4::++-. 	9E4::..u56H#zz007

//11#,,.&**,G!!Hg#68	9 	 /tr>   rN   )rU   rV   rW   rX   r=   r   r   r   rY   r>   r<   r   r     s    =9&=Pr>   r   )FrX   os.pathpathr_   qtpy.compatr   qtpy.QtCorer   r   r   r   qtpy.QtWidgetsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   spyder.api.translationsr   spyder.config.managerr   spyder.utils.icon_managerr   spyder.utils.miscr   spyder.utils.qthelpersr   ry   r{   r   r   r   rC   DEDICATED_INTERPRETER_OPTIONrD   rE   rF   rG   WDIR_FIXED_DIR_OPTIONr   rx   r   r   r   r   r   r   r   objectr!   rd   rf   ri   rk   r   r   r   rY   r>   r<   <module>r&     sj   /  - / /B B B B B & & ) , 4 <= :; 45 :; @A : > : @ : > 6 >? 1 ?@ JK =>?@78	
*	+()	Tv TnF
{/w {/|7"' 7"t"-, "-JA) Ar>   