3
5Ad]J"  ã               @   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   Zapplication_homeÚhandlersÚlenÚ
isinstancer   ÚbaseFilenameÚinfoÚsetLevelÚloggingÚDEBUGÚ
addHandlerÚStreamHandlerÚsetFormatterr   Úabspath)	ÚloggerÚfnameÚstreamÚmoder   r   ÚhÚhandlerÚs© r'   úy/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/mayavi-4.7.1-py3.6-linux-x86_64.egg/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    r/   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>)r/   r'   r'   r'   r(   Úget_non_gui_pluginsW   s    r3   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)Ztraitsui.apir4   Útraits.etsconfig.apir   r   ÚrootÚuse_ipythonZ6envisage.plugins.ipython_shell.view.ipython_shell_viewr6   Z3envisage.plugins.ipython_shell.ipython_shell_pluginr7   Z1envisage.plugins.python_shell.python_shell_pluginr8   Z/envisage.plugins.text_editor.text_editor_pluginr9   Z$apptools.logger.plugin.logger_pluginr:   Z%tvtk.plugins.scene.ui.scene_ui_pluginr;   Zmayavi.plugins.mayavi_ui_pluginr<   r/   Úextend)r4   r   Ztry_use_ipythonr?   r6   r7   r8   r9   r:   r;   r<   r.   r'   r'   r(   Úget_plugin_classes\   s6     rA   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'   )r0   r1   r'   r'   r(   r2   „   s    zget_plugins.<locals>.<listcomp>)rA   r'   r'   r'   r(   Úget_plugins‚   s    rB   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_linerB   r   r   rE   r   rF   Úapplicationr)   Úrun)ÚselfÚargvr.   Z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)rJ   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)ÚoptparserO   Ú
parse_args)rJ   rK   rO   ÚusageÚparserÚoptionsÚargsr'   r'   r(   rG   É   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'   )rJ   r'   r'   r(   rI   Ù   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)
rH   Zmayavi.plugins.scriptrW   Z	workbenchZactive_windowZget_serviceÚscriptÚguiZinvoke_laterrI   )rJ   ÚobjZ
trait_nameÚoldÚnewrL   rW   Úwindowr'   r'   r(   Ú_on_application_gui_startedè   s    z"Mayavi._on_application_gui_started)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rH   r	   rF   rX   r   r   ÚERRORrN   rM   r)   rG   rI   r   r^   r'   r'   r'   r(   rC   ‰   s   
'rC   c             C   s   t ƒ }|j| ƒ |S )z\Simple helper to start up the mayavi application.  This returns
    the running application.)rC   rM   )rK   Úmr'   r'   r(   rM   ø   s    
rM   Ú__main__)N)"rb   ÚsysÚos.pathr   r   Zapptools.logger.apir   r   r=   r   Z
traits.apir   r   r   r   r	   Zmayavi_workbench_applicationr   Zmayavi.preferences.apir   Zmayavi.core.customizer   Ú	getLoggerr    rc   r)   r/   r3   rA   rB   rC   rM   r_   rK   r'   r'   r'   r(   Ú<module>   s&   ,&o
