ó
‹²,]c           @   s   d  Z  d d l j 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 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 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 e e f d „  ƒ  YZ# d S(   sŽ   
Projects Plugin

It handles closing, opening and switching among projetcs and also
updating the file tree explorer associated with a project
iÿÿÿÿN(   t   getexistingdirectory(   t   Signalt   Slot(   t   QMenut   QMessageBox(   t   _t   get_home_dir(   t   SpyderPluginMixin(   t   is_text_string(   t   encoding(   t   icon_manager(   t   add_actionst   create_actiont   MENU_SEPARATOR(   t   getcwd_or_home(   t   ProjectExplorerWidget(   t   ProjectDialog(   t   EmptyProjectt   Projectsc           B   s   e  Z d  Z d Z e e ƒ Z e ƒ  Z e e ƒ Z e e ƒ Z	 e e ƒ Z
 e e ƒ Z e e e ƒ Z e e e ƒ Z e e ƒ Z e e ƒ Z e e e e ƒ Z e e ƒ Z e e ƒ Z e e ƒ Z d" d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d	 „  Z d
 „  Z  d „  Z! d „  Z" e# ƒ  d „  ƒ Z$ d „  Z% d" e& e& d „ Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ e d „ Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 d „  Z5 d „  Z6 d „  Z7 d  „  Z8 d! „  Z9 RS(#   s   Projects plugint   project_explorerc         C   s›   t  j |  d | d |  j d ƒ d |  j d ƒ d |  j d ƒ ƒt j |  | ƒ |  j d d g  ƒ|  _ d  |  _ d  |  _ |  j ƒ  |  j	 |  j
 ƒ  ƒ d  S(   Nt   parentt   name_filterst   show_allt   show_hscrollbart   recent_projectst   default(   R   t   __init__t
   get_optionR   R   t   Nonet   current_active_projectt   latest_projectt   initialize_plugint   setup_projectt   get_active_project_path(   t   selfR   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR   ;   s    		
c         C   s
   t  d ƒ S(   s   Return widget titles   Project explorer(   R   (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   get_plugin_titleK   s    c         C   s   |  j  S(   sq   
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        (   t
   treewidget(   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   get_focus_widgetO   s    c      
      sF  t  ˆ  t d ƒ d ˆ  j ƒˆ  _ t  ˆ  t d ƒ d ‡  f d †  ƒˆ  _ t  ˆ  t d ƒ d ˆ  j ƒˆ  _ t  ˆ  t d ƒ d ˆ  j ƒˆ  _ t  ˆ  t d ƒ d ˆ  j	 ƒˆ  _
 t  ˆ  t d ƒ d ˆ  j ƒˆ  _ t t d	 ƒ ˆ  ƒ ˆ  _ ˆ  j } ˆ  j d
 k	 r8ˆ  j j ˆ  j t ˆ  j ˆ  j ˆ  j t ˆ  j | g 7_ n  ˆ  j ƒ  g  S(   s*   Return a list of actions related to plugins   New Project...t	   triggereds   Open Project...c            s
   ˆ  j  ƒ  S(   N(   t   open_project(   t   v(   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   <lambda>]   t    s   Close Projects   Delete Projects   Clear this lists   Project Preferencess   Recent ProjectsN(   R   R   t   create_new_projectt   new_project_actiont   open_project_actiont   close_projectt   close_project_actiont   _delete_projectt   delete_project_actiont   clear_recent_projectst   clear_recent_projects_actiont   edit_project_preferencest   edit_project_preferences_actionR   t   recent_project_menut   toggle_view_actiont   mainR   t   projects_menu_actionsR   t   setup_menu_actions(   R"   t   explorer_action(    (   R"   s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   get_plugin_actionsV   s:    	
c            sè  ˆ  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 j ˆ  j  j j ƒ ˆ  j j ˆ  j  j j ƒ ˆ  j  j j ˆ  ƒ ˆ  j  j ˆ  ƒ ˆ  j j ˆ  j  j ƒ ˆ  j j ‡  f d †  ƒ ˆ  j j ‡  f d †  ƒ ˆ  j j ‡  f d †  ƒ ˆ  j j ‡  f d †  ƒ ˆ  j j ˆ  j ƒ ˆ  j t j ‡  f d †  ƒ ˆ  j j ‡  f d †  ƒ ˆ  j j ‡  f d †  ƒ ˆ  j j j ˆ  j ƒ d S(	   s'   Register plugin in Spyder's main windowc            s   ˆ  j  j j d |  ƒ S(   Nt   text(   R8   t   editort   new(   t   x(   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   ‹   R*   c            s   ˆ  j  j j |  ƒ S(   N(   R8   t   workingdirectoryt   chdir(   R(   (   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)      R*   c            s   ˆ  j  j ƒ  S(   N(   R8   t   set_window_title(   R(   (   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   ‘   R*   c            s   ˆ  j  j j ƒ  S(   N(   R8   R>   t   setup_open_files(   R(   (   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   “   R*   c            s   ˆ  j  j j ˆ  j ƒ  ƒ S(   N(   R8   RA   RB   t   get_last_working_dir(   R(   (   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   –   s   c            s   ˆ  j  j ƒ  S(   N(   R8   RC   (   R(   (   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   ™   R*   c            s   ˆ  j  j j ƒ  S(   N(   R8   R>   RD   (   R(   (   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   ›   R*   N(   R8   t   pythonpath_changedt   restore_scrollbar_positiont   connectt   sig_pythonpath_changedt   create_moduleR>   R?   t   editt   loadt   removedt   removed_treet   renamedt   renamed_treet   set_projectst   add_dockwidgett   sig_open_filet	   open_filet   sig_new_filet   sig_project_loadedt   update_explorert   sig_project_closedt   objectR6   t   aboutToShowR:   (   R"   (    (   R"   s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   register_pluginz   s8    
					c         C   s   d S(   s   Refresh project explorer widgetN(    (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   refresh_pluginž   s    c         C   s   |  j  ƒ  |  j ƒ  t S(   s3   Perform actions before parent main window is closed(   t   save_configt   closing_widgett   True(   R"   t
   cancelable(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   closing_plugin¢   s    

c         C   sˆ   |  j  j d k	 rC |  j  j j rC |  j  j |  k	 rC |  j  j ƒ  n  |  j d ƒ r„ |  j j ƒ  st |  j j t	 ƒ n  |  j
 t	 ƒ n  d S(   s   Switch to plugin.t   visible_if_project_openN(   R8   t   last_pluginR   t   ismaximizedt   maximize_dockwidgetR   R7   t	   isCheckedt
   setCheckedR_   t   visibility_changed(   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   switch_to_plugin¨   s    c      
      sõ   ˆ  j  j ƒ  g  ˆ  _ ˆ  j rÅ xˆ ˆ  j D]} } ˆ  j | ƒ r– | j t ƒ  d ƒ } t ˆ  | d t j	 d ƒ d | ‡  f d † ƒ} ˆ  j j
 | ƒ q) ˆ  j j | ƒ q) Wˆ  j d ˆ  j g 7_ n ˆ  j g ˆ  _ t ˆ  j  ˆ  j ƒ ˆ  j ƒ  d S(   s"   Setup and update the menu actions.t   ~t   icont   projectR&   c            s   ˆ  j  d | ƒ S(   Nt   path(   R'   (   R   t   p(   R"   (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR)   Ä   R*   N(   R6   t   cleart   recent_projects_actionsR   t   is_valid_projectt   replaceR   R   t   imaRk   t   appendt   removeR   R3   R   t   update_project_actions(   R"   Rl   t   namet   action(    (   R"   s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR:   ·   s$    		
c         C   sr   |  j  r |  j j t ƒ n |  j j t ƒ t |  j ƒ  ƒ } |  j j | ƒ |  j j | ƒ |  j	 j | ƒ d S(   s#   Update actions of the Projects menuN(
   R   R3   t
   setEnabledR_   t   Falset   boolR!   R/   R1   R5   (   R"   t   active(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRv   Ð   s    	c         C   sP   d d l  m } |  j rL |  j d } | |  | ƒ } | j ƒ  | j ƒ  n  d S(   s&   Edit Spyder active project preferencesiÿÿÿÿ(   t   ProjectPreferencesi    N(   t$   spyder.widgets.projects.configdialogR}   t   project_activet   project_listt   showt   exec_(   R"   R}   t   active_projectt   dlg(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR4   Ü   s    	
c         C   s—   |  j  ƒ  |  j } t |  ƒ } | j j |  j ƒ | j j |  j ƒ | j ƒ  r“ | d k ry |  j	 d ƒ ry |  j
 ƒ  n  |  j j ƒ  |  j ƒ  n  d S(   s   Create new projectRb   N(   Ri   R   R   t   sig_project_creation_requestedRH   t   _create_projectt   sig_project_createdR‚   R   R   t   show_explorerRI   t   emitt   restart_consoles(   R"   Rƒ   R„   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR+   ê   s    
	c         C   s+   |  j  d | ƒ |  j ƒ  |  j | ƒ d S(   s   Create a new project.Rm   N(   R'   R:   t   add_to_recent(   R"   Rm   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR†   ù   s    
c         C   sÔ  |  j  ƒ  | d k r‘ t ƒ  } t d |  d t d ƒ d | ƒ } t j | ƒ } |  j | ƒ s  | rŠ t j	 |  t d ƒ t d ƒ | ƒ n  d Sn t j | ƒ } |  j
 | ƒ |  j d k r4| rç |  j j d k	 rç |  j j j ƒ  n  |  j j d k	 r|  j j j d t ƒ  ƒ n  |  j d	 ƒ rb|  j ƒ  qbn. |  j j d k	 rb|  j |  j j j ƒ  ƒ n  t | ƒ |  _ t | ƒ |  _ |  j d
 |  j ƒ  ƒ |  j ƒ  |  j j | ƒ |  j j ƒ  | rÐ|  j ƒ  n  d S(   s"   Open the project located in `path`R   t   captions   Open projectt   basedirt   Errors"   <b>%s</b> is not a Spyder project!Nt   last_working_dirRb   t   current_project_path(   Ri   R   R   R    R   R	   t   to_unicode_from_fsRq   R   t   criticalR‹   R   R8   R>   t   save_open_filest
   set_optionR   R   Rˆ   t   set_project_filenamest   get_open_filenamesR   R   R!   R:   RV   R‰   RI   RŠ   (   R"   Rm   RŠ   t   save_previous_filesR   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR'   ÿ   sB    
		
c         C   sà   |  j  rÜ |  j ƒ  |  j  j } d |  _  |  j d d ƒ |  j ƒ  |  j j | ƒ |  j j ƒ  |  j	 d k	 r— |  j d |  j	 j
 ƒ  ƒ |  j	 j ƒ  n  |  j ƒ  |  j ƒ  |  j j d k	 rÜ |  j |  j j j ƒ  ƒ qÜ n  d S(   s`   
        Close current project and return to a window without an active
        project
        R   Rb   N(   R   Ri   t	   root_pathR   R”   R:   RX   R‰   RI   t
   dockwidgett	   isVisiblet   closeRo   RŠ   R8   R>   R•   R–   (   R"   Rm   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR.   -  s"    	
	
	

c         C   s$   |  j  r  |  j ƒ  |  j ƒ  n  d S(   s   Delete current project.N(   R   Ri   t   delete_project(   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR0   H  s    	
c         C   s   g  |  _  |  j ƒ  d S(   s!   Clear the list of recent projectsN(   R   R:   (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR2   N  s    	c         C   s   |  j  S(   s   Get the active project(   R   (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   get_active_projectS  s    c         C   sW   |  j  d d d ƒ} | rS |  j | ƒ rS |  j d | d t d t ƒ |  j ƒ  n  d S(   sT   
        Reopen the active project when Spyder was closed last time, if any
        R   R   Rm   RŠ   R—   N(   R   R   Rq   R'   Rz   t   load_config(   R"   R   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   reopen_last_projectW  s    	c         C   s@   g  } |  j  r! |  j  j ƒ  } n |  j r< |  j j ƒ  } n  | S(   s-   Get the list of recent filenames of a project(   R   t   get_recent_filesR   (   R"   t   recent_files(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   get_project_filenamesf  s    		c         C   s5   |  j  r1 |  j |  j  j ƒ r1 |  j  j | ƒ n  d S(   s,   Set the list of open file names in a projectN(   R   Rq   R˜   t   set_recent_files(   R"   R¡   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR•   o  s    	c         C   s"   d } |  j r |  j j } n  | S(   s   Get path of the active projectN(   R   R   R˜   (   R"   t   active_project_path(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR!   v  s    	c         C   sE   | r |  j  d d d ƒ} n |  j ƒ  } | d k r: g  S| g Sd S(   s4   Get project path as a list to be added to PYTHONPATHR   R   N(   R   R   R!   (   R"   t   at_startt   current_path(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   get_pythonpath}  s    c         C   s   |  j  j j d d t ƒ  ƒS(   s*   Get the path of the last working directoryR   R   (   R8   R>   R   R   (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRE   ‰  s    c         C   sw   |  j  d |  j ƒ |  j  d |  j j ƒ  ƒ |  j  d |  j j ƒ  ƒ |  j rs |  j rs |  j  d |  j j ƒ  ƒ n  d S(   s’   
        Save configuration: opened projects & tree widget state.

        Also save whether dock widget is visible if a project is open.
        R   t   expanded_statet   scrollbar_positionRb   N(   R”   R   R$   t   get_expanded_statet   get_scrollbar_positionR   R™   Rš   (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR]   Ž  s    		c         C   sJ   |  j  d d ƒ } t | ƒ r' d } n  | d k	 rF |  j j | ƒ n  d S(   s7   Load configuration: opened projects & tree widget stateR¨   N(   R   R   R   R$   t   set_expanded_state(   R"   R¨   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRž   œ  s
    	c         C   s5   |  j  d d ƒ } | d k	 r1 |  j j | ƒ n  d S(   s9   Restoring scrollbar position after main window is visibleR©   N(   R   R   R$   t   set_scrollbar_position(   R"   t   scrollbar_pos(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRG   §  s    c         C   s   |  j  |  j ƒ  ƒ d S(   s   Update explorer treeN(   R    R!   (   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRW   ­  s    c         C   sO   |  j  d k	 rK |  j  j ƒ  r. |  j  j ƒ  n  |  j  j ƒ  |  j  j ƒ  n  d S(   s   Show the explorerN(   R™   R   t   isHiddenR   t   raise_t   update(   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRˆ   ±  s
    c         C   s)   |  j  j d k	 r% |  j  j j ƒ  n  d S(   s=   Restart consoles when closing, opening and switching projectsN(   R8   t
   ipyconsoleR   t   restart(   R"   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRŠ   ¹  s    c         C   s<   t  j | d ƒ } t  j | ƒ r4 t  j | ƒ r4 t St Sd S(   s.   Check if a directory is a valid Spyder projects   .spyprojectN(   t   ospt   joint   isdirR_   Rz   (   R"   Rm   t   spy_project_dir(    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyRq   ¾  s    c         C   s9   | |  j  k r5 |  j  j d | ƒ |  j  d  |  _  n  d S(   ss   
        Add an entry to recent projetcs

        We only maintain the list of the 10 most recent projects
        i    i
   N(   R   t   insert(   R"   Rl   (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR‹   Æ  s    N(:   t   __name__t
   __module__t   __doc__t   CONF_SECTIONR   t   strt   open_interpreterRI   RJ   RK   RM   RN   RO   RP   R{   t   redirect_stdiot   runRY   R‡   RV   RX   RU   R   R   R#   R%   R<   R[   R\   Rz   Ra   Ri   R:   Rv   R4   R   R+   R†   R_   R'   R.   R0   R2   R   RŸ   R¢   R•   R!   R§   RE   R]   Rž   RG   RW   Rˆ   RŠ   Rq   R‹   (    (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyR   #   sb   				$	$						-																	($   R»   t   os.pathRm   R´   t   qtpy.compatR    t   qtpy.QtCoreR   R   t   qtpy.QtWidgetsR   R   t   spyder.config.baseR   R   t   spyder.pluginsR   t   spyder.py3compatR   t   spyder.utilsR	   R
   Rs   t   spyder.utils.qthelpersR   R   R   t   spyder.utils.miscR   t    spyder.widgets.projects.explorerR   t%   spyder.widgets.projects.projectdialogR   t   spyder.widgets.projectsR   R   (    (    (    s6   lib/python2.7/site-packages/spyder/plugins/projects.pyt   <module>   s   