a
    «ˆc–"  ã                   @   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 ¡ 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 |¡st j tj|¡}n|}| j}t|ƒdkr^|d }t|t	ƒr^|j
|kr^|  d¡ dS |  tj¡ t j |¡}t j|dd� t	|ƒ}| tj¡ |  |¡ |rÌt ¡ }	|	 t¡ |	 |¡ |  |	¡ |  d¡ |  dt j |¡¡ |  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.NT)Úexist_okzP********************************************************************************zlogfile is: '%s')ÚosÚpathÚisabsÚjoinr   Zapplication_homeÚhandlersÚlenÚ
isinstancer   ÚbaseFilenameÚinfoÚsetLevelÚloggingÚDEBUGÚdirnameÚmakedirsÚ
addHandlerÚStreamHandlerÚsetFormatterr   Úabspath)
ÚloggerÚfnameÚstreamÚmoder   r   ÚhZbasedirÚhandlerÚs© r)   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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_classesK   s    ýr1   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'get_non_gui_plugins.<locals>.<listcomp>)r1   r)   r)   r)   r*   Úget_non_gui_pluginsY   s    r7   c                  C   sÊ   ddl m}  | ƒ  ddlm} tjj}d}|jdkrZ|rZzddlm} d}W n   Y n0 |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ƒ }| ||
|	||g¡ |S )z5Get list of default plugin classes to use for Mayavi.r   )Útoolkitr   FZwx)ÚIPythonShellViewT)ÚIPythonShellPlugin)ÚPythonShellPlugin)ÚTextEditorPlugin)ÚLoggerPlugin)ÚSceneUIPlugin)ÚMayaviUIPlugin)Ztraitsui.apir8   Útraits.etsconfig.apir   r   ÚrootÚuse_ipythonZ6envisage.plugins.ipython_shell.view.ipython_shell_viewr9   Z3envisage.plugins.ipython_shell.ipython_shell_pluginr:   Z1envisage.plugins.python_shell.python_shell_pluginr;   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?   r1   Úextend)r8   r   Ztry_use_ipythonrB   r9   r:   r;   r<   r=   r>   r?   r0   r)   r)   r*   Úget_plugin_classes^   s6    ûrD   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)   r2   r)   r)   r*   r5   †   r6   zget_plugins.<locals>.<listcomp>)rD   r)   r)   r)   r*   Úget_plugins„   s    rE   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u rg }|   |¡ |du r$tƒ }|tƒ 7 }tj}t||| jd�}|| _|  ¡  | 	¡  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)r0   ÚpreferencesÚstart_gui_event_loop)
Úparse_command_linerE   r   r   rH   r   rI   Úapplicationr+   Úrun)ÚselfÚargvr0   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©rM   r)   r)   r*   r+   Ç   s    zMayavi.setup_loggerc                 C   s*   ddl m} d}||ƒ}| |¡\}}dS )z Parse command line options.

        Parameters
        ----------

        - argv : `list` of `strings`

          The list of command line arguments.
        r   )ÚOptionParserzusage: %prog [options]N)ÚoptparserS   Ú
parse_args)rM   rN   rS   ÚusageÚparserÚoptionsÚargsr)   r)   r*   rJ   Ë   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)   rR   r)   r)   r*   rL   Û   s    
z
Mayavi.runzapplication.gui:startedc                 C   sH   |dks|sdS | j }ddlm} |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)
rK   Zmayavi.plugins.scriptr[   Z	workbenchZactive_windowZget_serviceÚscriptÚguiZinvoke_laterrL   )rM   ÚobjZ
trait_nameÚoldÚnewrO   r[   Zwindowr)   r)   r*   Ú_on_application_gui_startedê   s    z"Mayavi._on_application_gui_started)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rK   r
   rI   r\   r   r   ÚERRORrQ   rP   r+   rJ   rL   r	   ra   r)   r)   r)   r*   rF   ‹   s   
'rF   c                 C   s   t ƒ }| | ¡ |S )z\Simple helper to start up the mayavi application.  This returns
    the running application.)rF   rP   )rN   Úmr)   r)   r*   rP   ú   s    
rP   Ú__main__)N)"re   Ú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"   rf   r+   r1   r7   rD   rE   rF   rP   rb   rN   r)   r)   r)   r*   Ú<module>   s&   .&o
