ó
Ò:\c           @   s/  d  Z  d d l Z d d l m Z m Z m Z d d l m Z m Z d d l	 m
 Z
 m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z m Z d d l m Z m Z d d	 l m Z m Z m Z m Z d d
 l m Z d d l  m! Z! d e f d „  ƒ  YZ" d „  Z# e$ d k r+e# ƒ  n  d S(   s   Preferences dialog.iÿÿÿÿN(   t   QPointt   Qtt   Signal(   t   QCursort   QPixmap(   t	   QCheckBoxt   QGridLayoutt   QHBoxLayoutt   QLabelt	   QLineEditt   QVBoxLayoutt   QWidget(   t   AnacondaAPI(   t   CONFt   WIN7(   t	   INFO_ICONt   WARNING_ICON(   t   ButtonNormalt   ButtonPrimaryt   SpacerHorizontalt   SpacerVertical(   t
   DialogBase(   t   DialogOfflineModet   PreferencesDialogc           B   s.  e  Z d  Z e e e ƒ Z e ƒ  Z e ƒ  Z e d „ Z	 d „  Z
 d „  Z d „  Z d „  Z d d d d d d d „ Z d d d d „ Z d d d d „ Z d d d	 „ Z d
 „  Z d „  Z d „  Z d d „ Z e d „  ƒ Z e d d „ ƒ Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z  RS(   s   Application preferences dialog.c            sû  t  t ˆ  ƒ j |   t ƒ  ˆ  _ t ƒ  ˆ  _ g  ˆ  _ i  ˆ  _ | ˆ  _	 t
 d ƒ ˆ  _ t d ƒ ˆ  _ t d ƒ ˆ  _ d ˆ  _ ˆ  j d ƒ t ƒ  ˆ  _ t ƒ  } | j ˆ  j ƒ | j ƒ  | j ˆ  j ƒ | j t ƒ  ƒ | j ˆ  j ƒ t ƒ  } | j ˆ  j ƒ | j t ƒ  ƒ | j t ƒ  ƒ | j | ƒ ˆ  j | ƒ ˆ  j j j ˆ  j ƒ ˆ  j j j ˆ  j ƒ ˆ  j j j ˆ  j ƒ ˆ  j j j ‡  f d †  ƒ ˆ  j j  d ƒ ˆ  j! ƒ  ˆ  j j" t# ƒ ˆ  j d j$ ƒ  ˆ  j j% t# ƒ ˆ  j j& t# ƒ d S(   s   Application preferences dialog.t   Applyt   Cancels   Reset to defaultsi    t   Preferencesc              s   ˆ  j  j t ƒ S(   N(   t	   button_okt
   setEnabledt   True(    (   t   self(    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   <lambda>R   t    N('   t   superR   t   __init__R   t   apit   sett   widgets_changedt   widgetst   widgets_dict   configR   R   R   t   button_cancelt   button_resett   rowt   setWindowTitleR   t   grid_layoutR   t	   addWidgett
   addStretchR   R
   t	   addLayoutR   t	   setLayoutt   clickedt   connectt   acceptt   rejectt   reset_to_defaultst
   setSpacingt   setupt   setDisabledR   t   setFocust
   setDefaultt   setAutoDefault(   R   R(   t   kwargst   buttons_layoutt   main_layout(    (   R   sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR"   )   sF    					
	
c         C   s   |  j  j d | d ƒ S(   s-   Get configuration option from `main` section.t   mainN(   R(   t   gett   None(   R   t   option(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt
   get_option_   s    c         C   s   |  j  j d | | ƒ d S(   s+   Set configuration option in `main` section.R@   N(   R(   R$   (   R   RC   t   value(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt
   set_optionc   s    c         C   s   |  j  j d | ƒ S(   s9   Get configuration option default value in `main` section.R@   (   R(   t   get_default(   R   RC   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   get_option_defaultg   s    c         C   s   |  j  | |  j | ƒ ƒ d S(   s9   Set configuration option default value in `main` section.N(   RF   RH   (   R   RC   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   set_option_defaultk   s    c   
         s½  |  j  | ƒ } | | _ t | ƒ | _ | | _ | j | ƒ t ƒ  | _ | j j d ƒ | j j d ƒ t	 ƒ  } t
 ƒ  }	 |	 j d ƒ |	 j | j d t j ƒ |	 j | d t j ƒ |	 j t | pÉ d ƒ d t j ƒ | j |	 ƒ ˆ  r‡  f d †  | _ n d „  | _ | r>| j } t j | t ƒ } | j | ƒ n  |  j j | ƒ | |  j | <|  j j | j |  j d t j t j Bƒ |  j j | |  j d t j t j Bƒ |  j d 7_ d S(	   s2   Create preference option widget and add to layout.i   i   i    R    c            s
   ˆ  |  ƒ S(   N(    (   RE   (   t   check(    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ‹   R    c         S   s
   t  d f S(   NR    (   R   (   RE   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR      R    i   N(   RD   t   _textR   t   labelRC   t	   set_valuet   label_informationt   setMinimumWidtht   setMaximumWidthR   R   t
   addSpacingR.   R   t
   AlignRightt	   AlignLeftR1   t   check_valueR   t   update_iconR   t
   setToolTipR&   t   appendR'   R-   R+   t   AlignCenter(
   R   t   widgetRL   RC   t   hintRJ   t   infot   config_valuet   form_widgett   h_layout(    (   RJ   sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   create_widgeto   s:    
				"		 	c            s§   t  ƒ  } | j t j t ƒ | j d ƒ | d „ | _ | d „ | _ | d „ | _ | j	 j
 d | ‡  f d † ƒ ˆ  j d | d | d | d	 | d
 | d | ƒ d S(   s-   Create textbox (QLineEdit) preference option.iú   c         S   s
   |  j  ƒ  S(   N(   t   text(   t   w(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ¤   R    c         S   s   | j  |  ƒ S(   N(   t   setText(   RE   Ra   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ¥   R    c         S   s   |  j  d d ƒ S(   Ni    iè  (   t   setSelection(   Ra   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ¦   R    c            s   ˆ  j  d | ƒ S(   NRY   (   t   options_changed(   t   vRa   (   R   (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ¨   R    RY   RC   RL   RZ   RJ   R[   N(   R	   t   setAttributeR   t   WA_MacShowFocusRectt   FalseRO   t	   get_valueRM   t   set_warningt   textChangedR3   RB   R_   (   R   RL   RC   RZ   RJ   R[   RY   (    (   R   sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   create_textboxž   s    			c            sš   t  ƒ  } | d „ | _ | d „ | _ ˆ j d ‰  | ‡  f d † | _ | j j d | ‡ f d † ƒ ˆ j d | d | d | d	 | d
 | d | ƒ d S(   s"   Create checkbox preference option.c         S   s   t  |  j ƒ  ƒ S(   N(   t   boolt
   checkState(   Ra   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ·   R    c         S   s%   t  | j |  r t j n t j ƒ ƒ S(   N(   Rm   t   setCheckStateR   t   Checkedt	   Unchecked(   RE   Ra   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ¸   s   t   anaconda_api_urlc            s   ˆ  S(   N(    (   Ra   (   t
   api_widget(    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ½   R    c            s   ˆ  j  d | ƒ S(   NRY   (   Rd   (   Re   Ra   (   R   (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   ¿   R    RY   RC   RL   RZ   RJ   R[   N(	   R   Ri   RM   R'   Rj   t   stateChangedR3   RB   R_   (   R   RL   RC   RJ   RZ   R[   RY   (    (   Rs   R   sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   create_checkbox´   s    			c         C   s}   |  j  | j ƒ } | | j ƒ  k r7 |  j j | ƒ n" | |  j k rY |  j j | ƒ n  |  j j t t	 |  j ƒ ƒ ƒ d S(   s5   Callback helper triggered on preference value change.N(
   RD   RC   Ri   R%   t   addt   removeR   R9   Rm   t   len(   R   RE   RY   R\   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyRd   Ê   s    c         C   s   |  j  | S(   s'   Return the widget for the given option.(   R'   (   R   RC   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   widget_for_optionÖ   s    c         C   sœ   |  j  j d d |  j j ƒ  ƒ |  j j ƒ  } t | t ƒ rl |  j  j d d | ƒ |  j  j d d d ƒ n, |  j  j d d t ƒ |  j  j d d | ƒ d S(   s°   
        Set configuration values found in other config files.

        Some options of configuration are found in condarc or in
        anaconda-client configuration.
        R@   Rr   t   ssl_verificationt   ssl_certificateN(	   R(   R$   R#   t   client_get_api_urlt   client_get_sslt
   isinstanceRm   RB   R   (   R   t
   ssl_verify(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   set_initial_valuesÜ   s    	c   	         s‚  ‡  f d †  } ‡  f d †  } ‡  f d †  } ˆ  j  ƒ  ˆ  j d d d | ƒˆ  j d d d | d	 d
 ƒˆ  j d d d | ƒd } ˆ  j d d d | ƒt j } t r° d n d } ˆ  j d d d | | ƒˆ  j d d ƒ ˆ  j d d ƒ ˆ  j d d ƒ ˆ  j d d ƒ ˆ  j d d ƒ ˆ  j d d  ƒ ˆ  j j d ƒ } | j j	 ˆ  j
 ƒ ˆ  j j d ƒ } | j d! ƒ ˆ  j
 ƒ  d" S(#   s   Setup the preferences dialog.c            s²   ˆ  j  j d ƒ } | r$ | j ƒ  n t } ˆ  j  j d ƒ } | rQ | j ƒ  } n  ˆ  j  j d ƒ } | so | r~ | j ƒ  } n t } | r™ t d f } n ˆ  j |  d | ƒ} | S(   sP  
            Custom checker to use selected ssl option instead of stored one.

            This allows to set an unsafe api url directly on the preferences
            dialog. Without this, one would have to first disable, click
            accept, then open preferences again and change api url for it to
            work.
            Rz   R{   t   offline_modesF   API Domain cannot be modified when working in <b>offline mode</b>.<br>t   verify(   R'   RA   Ri   R   Rh   t   is_valid_api(   RE   t
   ssl_widgetR‚   t   ssl_cert_widgett   offline_widgetR   t   basic_check(   R   (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   api_url_checkerõ   s    
c            s1   ˆ  j  j d ƒ } | j ƒ  } ˆ  j | d |  ƒS(   s   Counterpart to api_url_checker.Rr   R‚   (   R'   RA   Ri   Rƒ   (   RE   t   api_url_widgett   api_url(   R   (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   ssl_checker  s    c            sX   ˆ  j  j d ƒ } | r$ | j ƒ  n t } ˆ  j  j d ƒ } | j ƒ  } ˆ  j | | ƒ S(   s*   Check if certificate path is valid/exists.Rz   R{   (   R'   RA   Ri   R   t   is_valid_cert_file(   RE   R„   R‚   R…   t   path(   R   (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   ssl_certificate_checker  s
    s   Anaconda API domainRr   RJ   s   Enable SSL verificationRz   RZ   sH   <i>Disabling this option is not <br>recommended for security reasons</i>s   SSL certificate path (Optional)R{   s¹   To help us improve Anaconda Navigator, fix bugs,
and make it even easier for everyone to use Python,
we gather anonymized usage information, just like
most web browsers and mobile apps.s   Quality improvement reportingt   provide_analyticsR[   s   <br><br>R    s   Enable offline modeR   s   Hide offline mode dialogt   hide_offline_dialogs   Hide quit dialogt   hide_quit_dialogs   Hide update dialog on startupt   hide_update_dialogs    Hide running applications dialogt   hide_running_apps_dialogs   Enable high DPI scalingt   enable_high_dpi_scalings'   Show application startup error messagest   show_application_launch_errorss%   Certificate to verify SSL connectionsN(   R€   Rl   Ru   R   t   MESSAGE_PREFERENCESR   R'   RA   Rt   R3   t   enable_disable_certt   setPlaceholderText(	   R   Rˆ   R‹   RŽ   R[   t   info_offlinet   extrat   ssl_ver_widgetR…   (    (   R   sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR8   ò   sX    $
	



c         C   s\   |  j  j d ƒ } | r' t | ƒ } n$ |  j  j d ƒ } t | j ƒ  ƒ } | j | ƒ d S(   s7   Refresh enabled/disabled status of certificate textbox.R{   Rz   N(   R'   RA   Rm   Rn   R   (   R   RE   R…   R›   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR—   d  s    c         C   sB   t  | ƒ } |  j t ƒ |  j | j d d t j t j ƒ ƒ |  S(   s'   Update icon for information or warning.i   (   R   t   setScaledContentsR   t	   setPixmapt   scaledR   t   KeepAspectRatiot   SmoothTransformation(   RL   t   icont   pixmap(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyRU   n  s
    c         C   s¦   |  j  } | r… t j | t ƒ } | j t | ƒ ƒ |  j  j ƒ  d } |  j  j ƒ  d } |  j  j t	 | | ƒ ƒ } t
 j | ƒ n | j t ƒ  ƒ | j d ƒ d S(   s*   Display warning for widget in preferences.i   R    N(   RN   R   RU   R   RV   t   strt   widtht   heightt   mapToGlobalR    R   t   setPosR   R   (   RY   R`   RL   Ra   t   ht   position(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   warnx  s    	c         C   s7   |  j  j | d t ƒ} d } | s- d } n  | | f S(   s(   Check if a given URL returns a 200 code.t   non_blockingR    s   Invalid api url.(   R#   t   download_is_valid_urlRh   (   R   t   urlt   outputt   error(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   is_valid_url‰  s
    	c         C   sL   t  } d } | j ƒ  rB | rB t j j | ƒ } | sB d } qB n  | | f S(   s4   "Check if ssl certificate file in given path exists.R    s   File not found.(   R   t   stript   osR   t   isfile(   R   R   R‚   R®   R¯   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyRŒ   ‘  s    c         C   sÇ   |  j  j | d t d | ƒ} d } | s½ d } d } d | k r´ |  j | ƒ d r´ | j d d ƒ } | j d d	 ƒ } | j d
 ƒ r• | d } n
 | d } d j | | ƒ } q½ d } n  | | f S(   s6   Check if a given URL is a valid anaconda api endpoint.R«   R‚   R    s   /apii    s   https://s   https://api.s   http://s   http://api.t   /R#   sL   Invalid Anaconda API url. <br><br>Try using:<br><b>{0}</b> or <br><b>{1}</b>s\   Invalid Anaconda API url.<br><br>Check the url is valid and corresponds to the api endpoint.(   R#   t   download_is_valid_api_urlRh   R°   t   replacet   endswitht   format(   R   R­   R‚   R®   R¯   t	   url_api_1t	   url_api_2(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyRƒ     s$    		
	c         C   sš   g  } x€ |  j  D]u } | j ƒ  } | j | ƒ \ } } | j | ƒ | rZ |  j | ƒ q |  j j t ƒ | j ƒ  |  j | | ƒ Pq W|  j	 j
 ƒ  | S(   sŒ   
        Run all check functions on configuration options.

        This method checks and warns but it does not change/set values.
        (   R%   Ri   RT   RW   Rª   R   R9   R   Rj   t   sig_check_readyt   emit(   R   t   checksRY   RE   RJ   R¯   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt
   run_checks¿  s    
c         C   s`   xL |  j  D]A } | j } |  j | ƒ } | j | ƒ |  j d | d | ƒ q
 W|  j j ƒ  d S(   s,   Reset the preferences to the default values.RY   RE   N(   R&   RC   RH   RM   Rd   t   sig_reset_readyR¼   (   R   RY   RC   t   default(    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR6   ×  s    	c            sd  t  } d ‰  ˆ j ƒ  } | r`t | ƒ r`xÝ ˆ j D]Ò } | j ƒ  } ˆ j | j | ƒ | j d k r‡ | ‰  ˆ j j	 | ƒ t
 } n  | j d k r4 ˆ j j d ƒ } ˆ j j d ƒ } | j ƒ  } | j ƒ  } | j ƒ  rí | rí | } n | } ˆ j j | ƒ q4 q4 W| rJˆ  rJ‡  ‡ f d †  }	 ˆ j j ƒ  }
 |
 j j |	 ƒ n  t t ˆ ƒ j ƒ  n  d S(   s   Override Qt method.Rr   R{   Rz   c            sQ   | j  d ƒ } y* ˆ j j ˆ  | ƒ t t ˆ ƒ j ƒ  Wn t k
 rL n Xd  S(   Nt	   conda_url(   RA   t   sig_urls_updatedR¼   R!   R   R4   t   RuntimeError(   t   workerR®   R¯   RÁ   (   Rr   R   (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt	   _api_info  s    N(   R{   Rz   (   Rh   RB   R¾   t   allR%   Ri   RF   RC   R#   t   client_set_api_urlR   R'   RA   R±   t   client_set_sslt   api_urlst   sig_chain_finishedR3   R!   R   R4   (   R   t   sig_updatedR½   RY   RE   t   ssl_verit   ssl_certR‚   R   RÅ   RÄ   (    (   Rr   R   sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR4   â  s2    			N(!   t   __name__t
   __module__t   __doc__R   R£   RÂ   R»   R¿   R   R"   RD   RF   RH   RI   RB   R_   Rl   Ru   Rd   Ry   R€   R8   R—   t   staticmethodRU   Rª   R°   RŒ   R   Rƒ   R¾   R6   R4   (    (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyR   "   s>   		6				(			r

		"		c          C   s@   d d l  m }  |  ƒ  } t d d ƒ } | j ƒ  | j ƒ  d S(   s   Main local testing.iÿÿÿÿ(   t   qapplicationt   parentN(   t"   anaconda_navigator.utils.qthelpersRÒ   R   RB   t   showt   exec_(   RÒ   t   appRY   (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt
   local_test  s
    	
t   __main__(%   RÐ   R²   t   qtpy.QtCoreR    R   R   t
   qtpy.QtGuiR   R   t   qtpy.QtWidgetsR   R   R   R   R	   R
   R   t#   anaconda_navigator.api.anaconda_apiR   t   anaconda_navigator.configR   R   t    anaconda_navigator.static.imagesR   R   t   anaconda_navigator.widgetsR   R   R   R   t"   anaconda_navigator.widgets.dialogsR   t*   anaconda_navigator.widgets.dialogs.offlineR   R   RØ   RÎ   (    (    (    sM   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/preferences.pyt   <module>   s   4"ÿ ö		