ó
‹²,]c           @  sý   d  Z  d d l m Z d d l Z d d l j Z d d l Z d d l 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 m Z m Z d d l m Z d d	 l m Z d d
 l m Z d e f d „  ƒ  YZ d S(   s   Shortcut managementiÿÿÿÿ(   t   print_functionN(   t   QButtonGroupt	   QGroupBoxt   QInputDialogt   QLabelt	   QLineEditt   QMessageBoxt   QPushButtont   QVBoxLayout(   t   _(   t   GeneralConfigPage(   t   PY2t   is_text_stringt   to_text_string(   t   icon_manager(   t   get_python_executable(   t   programst   MainInterpreterConfigPagec           B  sz   e  Z d  Z e d ƒ Z e j d ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   t   main_interpreters   Python interpretert   pythonc         C  s   t  j |  | | ƒ d  |  _ d  |  _ d  |  _ |  j d t ƒ  ƒ } |  j d ƒ r^ t ƒ  } n  t j	 | ƒ sƒ |  j
 d t ƒ  ƒ n. | j d ƒ r± |  j
 d | j d d ƒ ƒ n  |  j d ƒ sü |  j d ƒ sâ |  j
 d d ƒ n  |  j | ƒ |  j ƒ  n  d  S(   Nt
   executablet   defaults   pythonw.exes
   python.exet   custom_interpretert    (   R
   t   __init__t   Nonet   cus_exec_radiot   pyexec_editt   cus_exec_combot
   get_optionR   t   ospt   isfilet
   set_optiont   endswitht   replacet   set_custom_interpreters_listt!   validate_custom_interpreters_list(   t   selft   parentt   mainR   (    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyR   "   s"    				c         C  s   t  j |  ƒ d  S(   N(   R
   t
   initialize(   R%   (    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyR(   @   s    c      
   C  s©  |  j  } t t d ƒ ƒ } t | ƒ } t t d ƒ ƒ } |  j t d ƒ d d | ƒ|  _ |  j t d ƒ d d | ƒ|  _ t j	 d k r t d	 ƒ d
 } n d  } t ƒ  } | j | ƒ | j |  j ƒ | j |  j ƒ |  j ƒ  |  j t d ƒ |  j d ƒ d d | d t d t ƒ|  _ |  j j j |  j j ƒ |  j j j |  j j ƒ | j |  j ƒ | j | ƒ |  j j j ƒ  |  _ t t d ƒ ƒ } t t d ƒ ƒ } | j t ƒ | t d ƒ d d t d t d ƒ ƒ}	 | t d ƒ d d t d ƒ ƒ}
 t t d ƒ ƒ } | j j |  j ƒ t ƒ  } | j | ƒ | j |	 ƒ | j |
 ƒ | j | ƒ | j | ƒ t ƒ  } | j | ƒ | j | ƒ | j d ƒ |  j | ƒ d  S(   Ns   Python interpreters5   Select the Python interpreter for all Spyder consoless#   Default (i.e. the same as Spyder's)R   t   button_groups%   Use the following Python interpreter:t   customt   ntt   Executabless    (*.exe)s   Recent custom interpreterst   custom_interpreters_listR   t   filterst   default_line_editt   adjust_to_contentss   User Module Reloader (UMR)sŽ   UMR forces Python to reload modules which were imported when executing a file in a Python or IPython console with the <i>runfile</i> function.s
   Enable UMRs   umr/enabledt   msg_if_enabledt   msg_warnings{  This option will enable the User Module Reloader (UMR) in Python/IPython consoles. UMR forces Python to reload deeply modules during import when running a Python script using the Spyder's builtin function <b>runfile</b>.<br><br><b>1.</b> UMR may require to restart the console in which it will be called (otherwise only newly imported modules will be reloaded when executing files).<br><br><b>2.</b> If errors occur when re-running a PyQt-based program, please check that the Qt objects are properly destroyed (e.g. you may have to use the attribute <b>Qt.WA_DeleteOnClose</b> on your main window, using the <b>setAttribute</b> method)s   Show reloaded modules lists   umr/verboset   msg_infosC   Please note that these changes will be applied only to new consoless'   Set UMR excluded (not reloaded) modulesi   (   t   create_checkboxR   R	   R   R   t   create_radiobuttont   def_exec_radioR   t   ost   nameR   R   t	   addWidgetR$   t   create_file_comboboxR   t   TrueR   t   toggledt   connectt   setDisabledt
   setEnabledt	   setLayoutt   comboboxt   lineEditR   t   setWordWrapR   t   clickedt   set_umr_namelistt
   addStretch(   R%   t   newcbt   pyexec_groupt	   pyexec_bgt   pyexec_labelR.   t   pyexec_layoutt	   umr_groupt	   umr_labelt   umr_enabled_boxt   umr_verbose_boxt   umr_namelist_btnt
   umr_layoutt   vlayout(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyt
   setup_pageC   sj    				
					c         C  s­   |  j  j ƒ  s t St ƒ  } t | ƒ s@ t | j ƒ  d ƒ } n  | | k rP t St j | ƒ sp |  j	 | ƒ r© t
 j |  t d ƒ t d ƒ t
 j ƒ |  j j t ƒ t St S(   s/   Custom Python executable value has been changeds   utf-8t   Warnings‰   You selected an invalid Python interpreter for the console so the previous interpreter will stay. Please make sure to select a valid one.(   R   t	   isCheckedt   FalseR   R   R   t   toUtf8R   t   is_python_interpretert   warn_python_compatibilityR   t   warningR	   t   OkR6   t
   setCheckedR;   (   R%   t   pyexect
   def_pyexec(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyt   python_executable_changed—   s    		
c         C  sÅ   t  j | ƒ s d  St j d } y8 d d g } t j | | ƒ } t | j ƒ  d ƒ } Wn( t k
 rq | } n t	 k
 r‚ t
 SX| | k rÁ t j |  t d ƒ t d ƒ | | f t j ƒ n  t S(   Ni    s   -cs&   import sys; print(sys.version_info[0])RT   sI  You selected a <b>Python %d</b> interpreter for the console but Spyder is running on <b>Python %d</b>!.<br><br>Although this is possible, we recommend you to install and run Spyder directly with your selected interpreter, to avoid seeing false warnings and errors due to the incompatible syntax between these two Python versions.(   R   R   t   syst   version_infoR   t   run_programt   intt   communicatet   IOErrort
   ValueErrorRV   R   RZ   R	   R[   R;   (   R%   R]   t   spyder_versiont   argst   proct   console_version(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyRY   ª   s     		c         C  sÄ  t  j |  t d ƒ t d ƒ t j d j |  j d ƒ ƒ ƒ \ } } | rÀt | ƒ } | r§| j d d ƒ j	 d ƒ } g  } g  } x  | D]˜ } t
 rt d „  | Dƒ ƒ rÌ t j | ƒ rþ | j | ƒ qþ q t j |  t d	 ƒ t d
 ƒ t j ƒ | j | ƒ qˆ t j | ƒ rˆ | j | ƒ qˆ qˆ Wd j t | ƒ t | ƒ t | ƒ ƒ } | rt j |  t d ƒ t d ƒ | t j ƒ n  t j |  t d ƒ t d ƒ t j ƒ n g  } |  j d | ƒ n  d S(   s"   Set UMR excluded modules name listt   UMRs=   Set the list of excluded modules as this: <i>numpy, scipy</i>s   , s   umr/namelistR   t    t   ,c         s  s!   |  ] } t  | ƒ d  k  Vq d S(   i€   N(   t   ord(   t   .0t   c(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pys	   <genexpr>Ð   s    RT   sn   You are working with Python 2, this means that you can not import a module that contains non-ascii characters.s;   The following modules are not installed on your machine:
%ssR   Please note that these changes will be applied only to new Python/IPython consolesN(   R   t   getTextR	   R   t   Normalt   joinR   R   R"   t   splitR   t   allR   t   is_module_installedt   appendR   RZ   R[   t   sett   informationR    (   R%   t	   argumentst   validt   namelistt   fixed_namelistt   non_ascii_namelistt   module_namet   invalid(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyRE   Á   s@    	!	
		c         C  sN   |  j  d ƒ } | | k rJ | t ƒ  k rJ | j | ƒ |  j d | ƒ n  d S(   s9   Update the list of interpreters used and the current one.R-   N(   R   R   Rw   R    (   R%   t   valuet   custom_list(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyR#   ê   s    c         C  sw   |  j  d ƒ } g  } xK | D]C } t j | ƒ r t j | ƒ r | t ƒ  k r | j | ƒ q q W|  j d | ƒ d S(   s8   Check that the used custom interpreters are still valid.R-   N(   R   R   R   R   RX   R   Rw   R    (   R%   R‚   t   valid_custom_listR   (    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyR$   ñ   s    c         C  sÌ   |  j  j ƒ  s™ |  j j ƒ  } t j | ƒ } | j d ƒ rQ | j d d ƒ } n  |  j | ƒ } | r™ |  j	 | ƒ |  j
 d | ƒ |  j
 d | ƒ q™ n  |  j j ƒ  s» |  j
 d d ƒ n  |  j j ƒ  d  S(   Ns   pythonw.exes
   python.exeR   R   Rl   (   R6   RU   R   t   textR   t   normpathR!   R"   R_   R#   R    R'   t   apply_settings(   R%   t   optionsR   t   change(    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyR†   û   s    (   t   __name__t
   __module__t   CONF_SECTIONR	   t   NAMEt   imat   icont   ICONR   R(   RS   R_   RY   RE   R#   R$   R†   (    (    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyR      s   			T			)		
(    t   __doc__t
   __future__R    R7   t   os.patht   pathR   R`   t   qtpy.QtWidgetsR   R   R   R   R   R   R   R   t   spyder.config.baseR	   t   spyder.plugins.configdialogR
   t   spyder.py3compatR   R   R   t   spyder.utilsR   R   t   spyder.utils.miscR   R   R   (    (    (    s=   lib/python2.7/site-packages/spyder/plugins/maininterpreter.pyt   <module>   s   :