a
    ¢–BeR  ã                   @   sT   d dl ZddlmZmZ ej ej e¡d¡gZ	dZ
dZd ZdZG dd„ deƒZdS )	é    Né   )ÚNoSuchWidgetErrorÚWidgetPluginErrorzwidget-pluginsTFc                   @   sR   e Zd Zdd„ Zdd„ Zddd„Zdd	„ Zd
d„ Zdd„ Zdd„ Z	e
dd„ ƒZdS )ÚQObjectCreatorc           	      C   sü   || _ g | _| j  ¡ | _tD ]À}zt |¡}W n   g }Y n0 |D ]–}| d¡sTqDtj 	||¡}t
tttdœ}i }|  |||¡rD|d }|t
kr²|d ƒ }| j | j j|Ž ¡ qD|tkrÎ| j |d ƒ ¡ qDtd| ƒ‚qDq| j  ¡ | _| j | j¡ d S )Nz.py)ÚMODULEÚ	CW_FILTERÚMATCHÚNO_MATCHÚ
pluginTypeZmoduleInformationZ	getFilterzUnknown plugin type of %s)Ú_cpolicyÚ
_cwFiltersZcreateQtGuiWidgetsWrappersÚ_modulesÚwidgetPluginPathÚosÚlistdirÚendswithÚpathÚjoinr   r   r   r	   Úload_pluginÚappendZcreateModuleWrapperr   ZcreateCustomWidgetLoaderÚ_customWidgets)	ÚselfZcreatorPolicyZ	plugindirÚpluginsÚfilenameÚplugin_globalsÚplugin_localsr
   Zmodinfo© r   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/PyQt5/uic/objcreator.pyÚ__init__:   s8    

ü
zQObjectCreator.__init__c                 O   s’   |   |¡}|d u rx| d¡}t|ƒdkrh|   |d ¡}|d urh|dd … D ]}t||d ƒ}|d u rJ qhqJ|d u rxt|ƒ‚| jj|g|¢R i |¤ŽS )NÚ.r   r   )ÚfindQObjectTypeÚsplitÚlenÚgetattrr   r   Zinstantiate)r   Ú	classnameÚargsÚkwargsÚfactoryÚpartsÚpartr   r   r   ÚcreateQObjectb   s    

zQObjectCreator.createQObjectr   c                 C   s   | j  |||¡S ©N)r   Úinvoke)r   ÚrnameÚmethodr%   r   r   r   r,   x   s    zQObjectCreator.invokec                 C   s*   | j D ]}| |¡}|d ur|  S qd S r+   )r   Úsearch)r   r$   ÚmoduleÚwr   r   r   r    {   s
    


zQObjectCreator.findQObjectTypec                 C   s   | j  ||¡S r+   )r   ÚgetSlot)r   ÚobjZslotnamer   r   r   r2   ‚   s    zQObjectCreator.getSlotc                 C   s   | j  |¡S r+   )r   ÚasString)r   Úsr   r   r   r4   …   s    zQObjectCreator.asStringc                 C   sB   | j D ]&}||||ƒ\}}|r|\}}} q.q| j |||¡ d S r+   )r   r   ÚaddCustomWidget)r   ZwidgetClassZ	baseClassr0   ZcwFilterÚmatchÚresultr   r   r   r6   ˆ   s    

zQObjectCreator.addCustomWidgetc              
   C   s�   t | ƒ}zxzt| ¡ ||ƒ W nV ty<   Y W | ¡  dS  tyt } z"td|jt|ƒf ƒ‚W Y d}~n
d}~0 0 W | ¡  n
| ¡  0 dS )zµ Load the plugin from the given file.  Return True if the plugin was
        loaded, or False if it wanted to be ignored.  Raise an exception if
        there was an error.
        Fz%s: %sNT)	ÚopenÚexecÚreadÚImportErrorÚcloseÚ	Exceptionr   Ú	__class__Ústr)r   r   r   ÚpluginÚer   r   r   r   ‘   s    ü.zQObjectCreator.load_pluginN)r   )Ú__name__Ú
__module__Ú__qualname__r   r*   r,   r    r2   r4   r6   Ústaticmethodr   r   r   r   r   r   9   s   (
	r   )Úos.pathr   Ú
exceptionsr   r   r   r   ÚdirnameÚ__file__r   r   r	   r   r   Úobjectr   r   r   r   r   Ú<module>)   s   