ó
Ò:\c           @   sÿ  d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z m Z d d l	 m
 Z
 d d l m Z m Z m Z m Z m Z m Z m Z m Z 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 m Z m  Z  m! Z! m" Z" m# Z# d d l$ m% Z% d Z& d „  Z' d e f d „  ƒ  YZ( d e% f d „  ƒ  YZ) d e% f d „  ƒ  YZ* d e! f d „  ƒ  YZ+ d e% f d „  ƒ  YZ, d e% f d „  ƒ  YZ- d e% f d „  ƒ  YZ. d e% f d „  ƒ  YZ/ d „  Z0 d „  Z1 e2 d  k rûe1 ƒ  n  d S(!   s/   Environment creation, import, deletion dialogs.iÿÿÿÿN(   t   getexistingdirectoryt   getopenfilename(   t   QRegExpt   Qt(   t   QRegExpValidator(	   t   QFramet   QGridLayoutt   QHBoxLayoutt   QLabelt	   QLineEditt   QListWidgett   QListWidgetItemt   QRadioButtont   QVBoxLayout(   t   DEFAULT_PROJECTS_PATHt	   HOME_PATHt   WIN(   t   path_is_writable(   t   load_style_sheet(   t   ButtonDangert   ButtonNormalt   ButtonPrimaryt	   LabelBaset   SpacerHorizontalt   SpacerVertical(   t
   DialogBases   [A-Za-z0-9-_]{0,100}c          C   s   t  t ƒ }  t |  ƒ S(   s&   Helper that creates a regex validator.(   R   t   RE_PROJECT_NAMER   (   t   regex(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt   get_regex_validator'   s    t   ListWidgetProblemsc           B   s   e  Z d  Z RS(   s&   Anaconda Project problems list widget.(   t   __name__t
   __module__t   __doc__(    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR   -   s   t   CustomToolTipc           B   s   e  Z d  Z d d „ Z RS(   s   Dialog a custom tool tip.c         C   s®   t  t |  ƒ j d | ƒ | |  _ | |  _ d |  _ t | ƒ |  _ |  j	 j
 t ƒ |  j t j t j Bƒ |  j d ƒ |  j t ƒ t ƒ  } | j |  j ƒ |  j | ƒ d S(   s   Dialog a custom tool tip.t   parentg¸…ëQ¸î?N(   t   superR!   t   __init__t   _parentt   _tooltipt   Nonet   style_sheetR   t
   _label_tipt   frame_title_bart
   setVisiblet   Falset   setWindowFlagsR   t   FramelessWindowHintt   WindowStaysOnTopHintt   setWindowOpacityt   setModalR   t	   addWidgett	   setLayout(   t   selft   tooltipR"   t   layout(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   4   s    				N(   R   R   R    R'   R$   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR!   1   s   t   DialogProblemsc           B   s5   e  Z d  Z d d d „ Z d d „ Z d d „ Z RS(   s,   Dialog to display anaconda project problems.c         C   sf  t  t |  ƒ j d | ƒ | |  _ | |  _ d |  _ t d |  ƒ |  _ t	 d ƒ |  _
 |  j j t ƒ |  j j t j ƒ |  j j t j ƒ |  j j t ƒ |  j t j t j Bƒ |  j d ƒ |  j t ƒ t ƒ  } | j ƒ  | j |  j
 ƒ t ƒ  } | j |  j ƒ | j t ƒ  ƒ | j t ƒ  ƒ | j | ƒ |  j  | ƒ |  j
 j! j" |  j# ƒ |  j$ ƒ  d S(   s,   Dialog to display anaconda project problems.R"   t   Okg¸…ëQ¸î?N(%   R#   R7   R$   R%   t	   _problemsR'   R(   R   t   listR   t	   button_okR*   R+   R,   t   setFrameStyleR   t   NoFramet   setFrameShapet   setWordWrapt   TrueR-   R   t   PopupR.   R0   R1   R   t
   addStretchR2   R   R   t	   addLayoutR3   t   clickedt   connectt   acceptt   setup(   R4   R"   t   problemst	   layout_okR6   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   M   s0    				
	c         C   s6   | d k r t ƒ  } n  |  j d ƒ |  j | ƒ d S(   s   Update custom css style sheets.i  N(   R'   R   t   setMinimumWidtht   setStyleSheet(   R4   R(   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt   update_style_sheetu   s    c         C   s   |  j  p | } | |  _  |  j j ƒ  xG t | ƒ D]9 \ } } t d j | d ƒ | ƒ } |  j j | ƒ q2 W|  j ƒ  |  j j |  j	 ƒ d S(   s   Setup the channels widget.s   {}. i   N(
   R9   R:   t   cleart	   enumerateR   t   formatt   addItemRL   RK   R(   (   R4   RH   t   it   problemt   item(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRG   |   s    	
N(   R   R   R    R'   R$   RL   RG   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR7   J   s   (t   LabelSpecInfoc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Custom label spec info.c         O   s,   t  t |  ƒ j | | Ž  t d ƒ |  _ d  S(   Nse   Files of type:<ul><li>anaconda-project.yml</li><li>environment.yml</li><li>requirements.txt</li></ul>(   R#   RT   R$   R!   t   dlg(   R4   t   argst   kwargs(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   Œ   s    c         C   sm   |  j  ƒ  j ƒ  } |  j ƒ  j | ƒ } | j ƒ  |  j j ƒ  } | j ƒ  |  j ƒ  } |  j j	 | | ƒ d  S(   N(
   t   geometryt   topRightt   parentWidgett   mapToGlobalt   xRU   t   widtht   yt   heightt   move(   R4   t   geo_tlt   tlR\   R^   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt   _pos–   s
    c         C   sP   |  j  j ƒ  s6 |  j  j ƒ  |  j ƒ  |  j  j ƒ  n  t t |  ƒ j | ƒ d S(   s   Override Qt method.N(   RU   t	   isVisiblet   showRc   t   raise_R#   RT   t
   enterEvent(   R4   t   event(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRg      s
    
c         C   s'   |  j  j ƒ  t t |  ƒ j | ƒ d S(   s   Override Qt method.N(   RU   t   hideR#   RT   t
   leaveEvent(   R4   Rh   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRj   ¥   s    (   R   R   R    R$   Rc   Rg   Rj   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRT   ‰   s
   	
		t   CreateDialogc           B   s8   e  Z d  Z d d d „ Z d d „ Z e d „  ƒ Z RS(   s   Create new project dialog.c         C   sÜ  t  t |  ƒ j d | ƒ | |  _ t d ƒ |  _ t ƒ  |  _ t d ƒ |  _	 t
 d ƒ |  _ |  j j d ƒ |  j d ƒ |  j d ƒ |  j j t ƒ  ƒ t ƒ  } | j |  j d d ƒ | j t ƒ  d d	 ƒ | j |  j d d
 ƒ | j t ƒ  d	 d ƒ t ƒ  } | j ƒ  | j |  j ƒ | j t ƒ  ƒ | j |  j	 ƒ t ƒ  } | j | ƒ | j t ƒ  ƒ | j t ƒ  ƒ | j | ƒ |  j | ƒ |  j	 j j |  j ƒ |  j j j |  j ƒ |  j j j |  j ƒ |  j ƒ  d S(   s   Create new environment dialog.R"   s   Project namet   Createt   Cancels   New project namei|  s   Create new projecti    i   i   N(    R#   Rk   R$   t   projectsR   t
   label_nameR	   t	   text_nameR   R;   R   t   button_cancelt   setPlaceholderTextRJ   t   setWindowTitlet   setValidatorR   R   R2   R   R   R   RB   R   RC   R3   RD   RE   RF   t   rejectt   textChangedt   refresh(   R4   R"   Rn   t   gridt   layout_buttonst   main_layout(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   ®   s<    			
	t    c         C   sp   |  j  j t ƒ |  j j ƒ  j ƒ  } |  j d k	 rl t | |  j ƒ rY |  j  j t	 ƒ ql |  j  j t ƒ n  d S(   s5   Update status of buttons based on combobox selection.N(
   R;   t   setDisabledR@   Rp   t   textt   stripRn   R'   t   is_valid_project_nameR,   (   R4   R}   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRw   Ý   s    c         C   s   |  j  j ƒ  j ƒ  S(   s   Return the project name.(   Rp   R}   R~   (   R4   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt   nameç   s    N(   R   R   R    R'   R$   Rw   t   propertyR€   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRk   «   s   /
t   ImportDialogc           B   sb   e  Z d  Z d Z d Z d Z d
 d
 d „ Z d d „ Z d „  Z	 e
 d „  ƒ Z e
 d	 „  ƒ Z RS(   s2   Import project from folder or specification files.s&   Conda environment files (*.yaml *.yml)s*   Conda explicit specification files (*.txt)s   Pip requirement files (*.txt)c         C   sÖ  t  t |  ƒ j d | ƒ | r% | n i  |  _ d |  _ d |  _ t d d |  ƒ|  _ t	 d ƒ |  _
 t	 d ƒ |  _ t ƒ  |  _ t ƒ  |  _ t d ƒ |  _ t d ƒ |  _ t d ƒ |  _ t d ƒ |  _ t d ƒ |  _ |  j j d	 ƒ |  j j t ƒ |  j j d
 ƒ |  j j d ƒ |  j d ƒ |  j d ƒ |  j j t ƒ  ƒ t ƒ  } | j  |  j ƒ | j  t! ƒ  ƒ | j  |  j ƒ t ƒ  } | j  |  j ƒ | j  t! ƒ  ƒ | j  |  j ƒ t" ƒ  } | j  |  j
 d d d d ƒ | j  t! ƒ  d d ƒ | j  |  j d d ƒ | j  t# ƒ  d d ƒ | j  |  j d d ƒ | j  |  j d d ƒ | j  t! ƒ  d d ƒ | j$ | d d ƒ t ƒ  } | j% ƒ  | j  |  j ƒ | j  t! ƒ  ƒ | j  |  j ƒ t& ƒ  } | j$ | ƒ | j  t# ƒ  ƒ | j$ | ƒ | j  t# ƒ  ƒ | j  t# ƒ  ƒ | j$ | ƒ |  j' | ƒ |  j j( j) |  j* ƒ |  j j( j) |  j+ ƒ |  j j( j) |  j, ƒ |  j j- j) |  j. ƒ |  j j- j) |  j. ƒ |  j j/ j) |  j. ƒ |  j j/ j) |  j. ƒ |  j j0 ƒ  |  j. ƒ  d S(   s0   Import project from folder or environment files.R"   R{   s   Project names   Specification Files   From folders   From specification fileRm   t   Importt   imports   File to import froms   New project namei|  s   Import new projecti    i   i   i   N(1   R#   R‚   R$   Rn   R'   t   selected_file_filtert   _pathRT   t
   label_infoR   Ro   t
   label_pathR	   Rp   t	   text_pathR   t   button_pathR   t   radio_foldert
   radio_specRq   R   R;   t   setObjectNamet
   setDefaultR@   Rr   RJ   Rs   Rt   R   R   R2   R   R   R   RC   RB   R   R3   RD   RE   RF   Ru   t   chooseRv   Rw   t   toggledt   toggle(   R4   R"   Rn   t   layout_radiot   layout_infilet   layout_gridRy   R6   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   ô   sx    						
	R{   c         C   s  |  j  j ƒ  rB |  j j d ƒ |  j j d ƒ |  j j t ƒ n0 |  j j t	 ƒ |  j j d ƒ |  j j d ƒ |  j
 j ƒ  } |  j j ƒ  } | rã | rã t j j | ƒ rã t | |  j ƒ rã |  j j t ƒ |  j j t	 ƒ n  |  j j t	 ƒ |  j j t	 ƒ d S(   s6   Update the status of buttons based on radio selection.s   Folder to import fromt   Folders   File s   File to import fromN(   R‹   t	   isCheckedR‰   Rr   Rˆ   t   setTextR‡   R+   R,   R@   Rp   R}   t   ost   patht   existsR   Rn   R;   R|   RŽ   Rq   (   R4   R}   R™   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRw   C  s    c         C   sÄ   d } |  j j ƒ  rW t d d d t d d d d j |  j |  j |  j ƒ ƒ \ } } n t	 d d d t d d ƒ } | rÀ |  j
 j ƒ  } | |  _ |  j j | ƒ |  j | ƒ |  j
 j | ƒ n  d S(   s8   Display file dialog to select environment specification.t   captions   Import Projectt   basedirR"   t   filterss   {0};;{1};;{2}N(   R'   RŒ   R–   R   R   RO   t   CONDA_ENV_FILESt   CONDA_SPEC_FILESt   PIP_REQUIREMENT_FILESR    Rp   R}   R…   R‰   R—   Rw   (   R4   t   selected_filterR™   R€   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR   Y  s&    		c         C   s   |  j  j ƒ  j ƒ  S(   s   Return the project name.(   Rp   R}   R~   (   R4   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR€   t  s    c         C   s   |  j  j ƒ  S(   s3   Return the project path to import (file or folder).(   R‰   R}   (   R4   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR™   y  s    N(   R   R   R    Rž   RŸ   R    R'   R$   Rw   R   R   R€   R™   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR‚   í   s   O	t   RemoveDialogc           B   s   e  Z d  Z d d d „ Z RS(   s   Remove existing project dialog.c         C   s/  t  t |  ƒ j d | ƒ t d ƒ |  _ t d ƒ |  _ t d j | ƒ ƒ |  _	 |  j
 d ƒ |  j d ƒ t ƒ  } | j ƒ  | j |  j ƒ | j t ƒ  ƒ | j |  j ƒ t ƒ  } | j |  j	 ƒ | j t ƒ  ƒ | j t ƒ  ƒ | j | ƒ |  j | ƒ |  j j j |  j ƒ |  j j j |  j ƒ d S(   s   Remove existing project dialog.R"   Rm   t   RemovesD   Do you want to remove project <b>"{0}"</b> and delete all its files?s   Remove projecti|  N(   R#   R¢   R$   R   Rq   R   t   button_removeR   RO   t   label_projectRs   RJ   R   RB   R2   R   R   R   RC   R3   RD   RE   RF   Ru   (   R4   R"   t   projectRy   R6   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   ‚  s*    	
	N(   R   R   R    R'   R$   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR¢     s   t   ProjectsPathDialogc           B   sY   e  Z d  Z d e d „ Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(	   s   Select project path.c         C   s“  t  t |  ƒ j d | ƒ t d ƒ |  _ t d ƒ |  _ t d ƒ |  _ t d ƒ |  _ t ƒ  |  _	 t
 d ƒ |  _ t
 d ƒ |  _ t d ƒ |  _ |  j j d ƒ | |  _ |  j	 j d	 ƒ |  j	 j t ƒ |  j d
 ƒ |  j d ƒ t ƒ  } | j |  j d d ƒ | j t ƒ  d d ƒ | j |  j	 d d ƒ | j t ƒ  d d ƒ | j |  j d d ƒ | j t ƒ  d d d d ƒ | j |  j d d d d ƒ t ƒ  } | j ƒ  | j |  j ƒ | j t ƒ  ƒ | j |  j ƒ t ƒ  } | j |  j ƒ | j t ƒ  ƒ | j | ƒ | j t ƒ  ƒ | j t ƒ  ƒ | j | ƒ |  j | ƒ |  j j j  |  j! ƒ |  j j j  |  j" ƒ |  j j j  |  j# ƒ |  j$ ƒ  d S(   s   Select project folder.R"   s5   If no path is selected, the default one will be used.s!   Select the projects folder to uses   Projects pathR{   s   Use defaultt   SelectR„   s   projects folder pathiD  s   Select Projects Pathi    i   i   i   i   N(%   R#   R§   R$   R   t   label_descriptionRo   Rˆ   R‡   R	   R‰   R   RŠ   t   button_defaultR   R;   R   t   defaultRr   t   setReadOnlyR@   RJ   Rs   R   R2   R   R   R   RB   R   RC   R3   RD   RE   RF   t   use_defaultR   Rw   (   R4   R"   R«   R”   Ry   R6   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR$   ¨  sR    			
	c         C   s   |  j  j ƒ  j ƒ  p |  j S(   s   Return the folder project path.(   R‰   R}   R~   R«   (   R4   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR™   â  s    c         C   s   |  j  j d ƒ |  j ƒ  d S(   s8   Set the default projects path as the folder path to use.R{   N(   R‰   R—   RF   (   R4   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR­   ç  s    c         C   sr   t  d d d |  j d |  ƒ } t r9 | j d d ƒ } n | j d d ƒ } | rd |  j j | ƒ n  |  j ƒ  | S(   s2   Display directory dialog to select project folder.R›   s   Select Projects FolderRœ   R"   t   /s   \(   R    R«   R   t   replaceR‰   R—   Rw   (   R4   R™   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR   ì  s    		
c         C   s¯   t  } d } |  j j ƒ  j ƒ  } t | ƒ r¥ t j j | ƒ r¥ d | k rT d } n* | t k ri d } n t	 | ƒ s~ d } n  d | k oŸ | t k oŸ t	 | ƒ } n  | | f S(   s!   Check that entered path is valid.R{   t    s*   <b>Please select a path without spaces</b>s<   <b>Please select a path different to the home directory.</b>s2   <b>Please select a path that has write access.</b>(
   R,   R‰   R}   R~   t   boolR˜   R™   t   isdirR   R   (   R4   t   checkt   errorR™   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt   is_valid_pathÿ  s    			c         C   sq   |  j  ƒ  \ } } |  j j | ƒ | s> t |  j j ƒ  ƒ r] |  j j d j |  j	 ƒ ƒ n |  j j | ƒ d S(   s$   Refresh button status based on path.s   <i>Default: {0}</i>N(
   Rµ   R;   t
   setEnabledR±   R‰   R}   R‡   R—   RO   R«   (   R4   R³   R´   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRw     s
    c         C   s   |  j  ƒ  d S(   s   Override Qt method.N(   R­   (   R4   (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyRu     s    N(   R   R   R    R'   R   R$   R   R™   R­   R   Rµ   Rw   Ru   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR§   ¥  s   :					c         C   se   d g } | j  ƒ  } t rI |  j ƒ  }  g  | D] } | j ƒ  ^ q. } n  |  od |  | k od |  | k S(   sT   
    Check that a project has a valid name.

    Windows is not case sensitive.
    t   new(   t   valuesR   t   lower(   R¦   Rn   t   RESERVED_PROJECT_NAMESt   project_namest   p(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyR   "  s    	"c          C   sI   d d l  m }  |  ƒ  } t d d ƒ } | j ƒ  t j | j ƒ  ƒ d S(   s   Run local tests.iÿÿÿÿ(   t   qapplicationR"   N(   t"   anaconda_navigator.utils.qthelpersR½   R§   R'   Re   t   syst   exitt   exec_(   R½   t   appt   widget_projects_folder(    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt
   local_test7  s
    	
t   __main__(3   R    R˜   R¿   t   qtpy.compatR    R   t   qtpy.QtCoreR   R   t
   qtpy.QtGuiR   t   qtpy.QtWidgetsR   R   R   R   R	   R
   R   R   R   t   anaconda_navigator.configR   R   R   t   anaconda_navigator.utils.miscR   t   anaconda_navigator.utils.stylesR   t   anaconda_navigator.widgetsR   R   R   R   R   R   t"   anaconda_navigator.widgets.dialogsR   R   R   R   R!   R7   RT   Rk   R‚   R¢   R§   R   RÄ   R   (    (    (    sJ   lib/python2.7/site-packages/anaconda_navigator/widgets/dialogs/projects.pyt   <module>   s2   @.	?"B’&}		