3
ÌœŸWJ"  ã               @   sè   d Z ddlZddlZddl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 ddlmZ ddlmZ dd	lmZ ejƒ Zd
ejfdd„Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ deƒZddd„Ze dkräeej!dd… ƒ dS )z!The Mayavi Envisage application.
é    N)ÚLogFileHandlerÚ	FORMATTER)Ú	ETSConfig)Ú	HasTraitsÚInstanceÚIntÚon_trait_changeÚBoolé   )ÚMayaviWorkbenchApplication)Úpreference_manager)Úget_custom_pluginsTc       	      C   sæ   t jj|ƒst jjtj|ƒ}n|}| j}t|ƒdkr^|d }t|t	ƒr^|j
|kr^| jdƒ dS | jtjƒ t	|ƒ}|jtjƒ | j|ƒ |r²tjƒ }|jtƒ |j|ƒ | j|ƒ | jdd ƒ | jdt jj|ƒƒ | jdd ƒ dS )aá  Setup a log file and the logger.  If the given file name is not
    absolute, put the log file in `ETSConfig.application_home`, if not
    it will create it where desired.

    Parameters:
    -----------

    fname -- file name the logger should use.  If this is an absolute
    path it will create the log file as specified, if not it will put it
    in `ETSConfig.application_home`.

    stream -- Add a stream handler.

    mode -- the logging mode of the stream handler.

    r
   r   z/Logging handlers already set!  Not duplicating.NÚ*éP   zlogfile is: '%s')ÚosÚpathÚisabsÚjoinr   Úapplication_homeÚhandlersÚlenÚ
isinstancer   ÚbaseFilenameÚinfoÚsetLevelÚloggingÚDEBUGÚ
addHandlerÚStreamHandlerÚsetFormatterr   Úabspath)	ÚloggerÚfnameÚstreamÚmoder   r   ÚhÚhandlerÚs© r(   úU/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/plugins/app.pyÚsetup_logger   s*    




r*   c              C   s@   ddl m}  ddlm} ddlm} ddlm} | |||g}|S )zQGet list of basic mayavi plugin classes that do not add any views or
    actions.r   )Ú
CorePlugin)ÚWorkbenchPlugin)ÚScenePlugin)ÚMayaviPlugin)Zenvisage.core_pluginr+   Z&envisage.ui.workbench.workbench_pluginr,   Ztvtk.plugins.scene.scene_pluginr-   Zmayavi.plugins.mayavi_pluginr.   )r+   r,   r-   r.   Úpluginsr(   r(   r)   Úget_non_gui_plugin_classesI   s    r0   c               C   s   dd„ t ƒ D ƒS )zJGet list of basic mayavi plugins that do not add any views or
    actions.c             S   s   g | ]
}|ƒ ‘qS r(   r(   )Ú.0Úclsr(   r(   r)   ú
<listcomp>Z   s    z'get_non_gui_plugins.<locals>.<listcomp>)r0   r(   r(   r(   r)   Úget_non_gui_pluginsW   s    r4   c              C   sÊ   ddl m}  | ƒ  ddlm} tjj}d}|jdkrZ|rZyddlm} d}W n   Y nX |rpddl	m
} |}ndd	lm} dd
lm} ddlm} ddlm}	 ddlm}
 tƒ }|j||
|	||gƒ |S )z5Get list of default plugin classes to use for Mayavi.r   )Útoolkit)r   FÚwx)ÚIPythonShellViewT)ÚIPythonShellPlugin)ÚPythonShellPlugin)ÚTextEditorPlugin)ÚLoggerPlugin)ÚSceneUIPlugin)ÚMayaviUIPlugin)Útraitsui.apir5   Útraits.etsconfig.apir   r   ÚrootÚuse_ipythonZ6envisage.plugins.ipython_shell.view.ipython_shell_viewr7   Z3envisage.plugins.ipython_shell.ipython_shell_pluginr8   Z1envisage.plugins.python_shell.python_shell_pluginr9   Z/envisage.plugins.text_editor.text_editor_pluginr:   Z$apptools.logger.plugin.logger_pluginr;   Z%tvtk.plugins.scene.ui.scene_ui_pluginr<   Zmayavi.plugins.mayavi_ui_pluginr=   r0   Úextend)r5   r   Ztry_use_ipythonrA   r7   r8   r9   r:   r;   r<   r=   r/   r(   r(   r)   Úget_plugin_classes\   s6     rC   c               C   s   dd„ t ƒ D ƒS )z.Get list of default plugins to use for Mayavi.c             S   s   g | ]
}|ƒ ‘qS r(   r(   )r1   r2   r(   r(   r)   r3   „   s    zget_plugins.<locals>.<listcomp>)rC   r(   r(   r(   r)   Úget_plugins‚   s    rD   c               @   sl   e Zd ZdZedƒZeddd�ZedƒZe	e
jdd�Zdd	d
„Zdd„ Zdd„ Zdd„ Zedƒdd„ ƒZdS )ÚMayavizðThe Mayavi application class.

    This class may be easily subclassed to do something different.
    For example, one way to script MayaVi (as a standalone application
    and not interactively) is to subclass this and do the needful.
    z.envisage.ui.workbench.api.WorkbenchApplicationTzstart a GUI event loop)Údesczmayavi.plugins.script.Scriptzthe logging mode to useNc             C   s^   |dkrg }| j |ƒ |dkr$tƒ }|tƒ 7 }tj}t||| jd�}|| _| jƒ  |j	ƒ  dS )a  The main application is created and launched here.

        Parameters
        ----------
        argv : list of strings
            The list of command line arguments.  The default is `None`
            where no command line arguments are parsed.  To support
            command line arguments you can pass `sys.argv[1:]`.
        plugins : list of Plugin objects
            List of plugins to start.  If none is provided it defaults to
            something meaningful.
        log_mode :
            The logging mode to use.

        N)r/   ÚpreferencesÚstart_gui_event_loop)
Úparse_command_linerD   r   r   rG   r   rH   Úapplicationr*   Úrun)ÚselfÚargvr/   ÚprefsÚappr(   r(   r)   Úmainž   s    


zMayavi.mainc             C   s   t td| jd� dS )z"Setup logging for the application.z
mayavi.log)r$   N)r*   r!   Úlog_mode)rL   r(   r(   r)   r*   Å   s    zMayavi.setup_loggerc             C   s*   ddl m} d}||ƒ}|j|ƒ\}}dS )z Parse command line options.

        Parameters
        ----------

        - argv : `list` of `strings`

          The list of command line arguments.
        r   )ÚOptionParserzusage: %prog [options]N)ÚoptparserR   Ú
parse_args)rL   rM   rR   ÚusageÚparserÚoptionsÚargsr(   r(   r)   rI   É   s    
zMayavi.parse_command_linec             C   s   dS )a°  This function is called after the GUI has started.
        Override this to do whatever you want to do as a MayaVi
        script.  If this is not overridden then an empty MayaVi
        application will be started.

        *Make sure all other MayaVi specific imports are made here!*
        If you import MayaVi related code earlier you will run into
        difficulties.  Use 'self.script' to script the mayavi engine.
        Nr(   )rL   r(   r(   r)   rK   Ù   s    
z
Mayavi.runzapplication.gui:startedc             C   sJ   |dks| rdS | j }ddlm} |jj}|j|ƒ| _|jj| j	ƒ dS )zƒThis is called as soon as  the Envisage GUI starts up.  The
        method is responsible for setting our script instance.
        ÚstartedNr   )ÚScript)
rJ   Zmayavi.plugins.scriptrZ   Ú	workbenchÚactive_windowÚget_serviceÚscriptÚguiZinvoke_laterrK   )rL   ÚobjÚ
trait_nameÚoldÚnewrO   rZ   Úwindowr(   r(   r)   Ú_on_application_gui_startedè   s    z"Mayavi._on_application_gui_started)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rJ   r	   rH   r^   r   r   ÚERRORrQ   rP   r*   rI   rK   r   re   r(   r(   r(   r)   rE   ‰   s   
'rE   c             C   s   t ƒ }|j| ƒ |S )z\Simple helper to start up the mayavi application.  This returns
    the running application.)rE   rP   )rM   Úmr(   r(   r)   rP   ø   s    
rP   Ú__main__)N)"ri   ÚsysÚos.pathr   r   Zapptools.logger.apir   r   r?   r   Ú
traits.apir   r   r   r   r	   Zmayavi_workbench_applicationr   Úmayavi.preferences.apir   Zmayavi.core.customizer   Ú	getLoggerr!   rj   r*   r0   r4   rC   rD   rE   rP   rf   rM   r(   r(   r(   r)   Ú<module>   s&   ,&o
