B
    ½ÞZX  ã               @   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  ¡ | _xÌtD ]Ä}yt |¡}W n   g }Y nX xž|D ]–}| d¡sXqHtj 	||¡}t
tttdœ}i }|  |||¡rH|d }|t
kr¶|d ƒ }| j | j j|Ž ¡ qH|tkrÒ| j |d ƒ ¡ qHtd| ƒ‚qHW qW | 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	plugindirZpluginsÚfilenameÚplugin_globalsÚplugin_localsr
   Zmodinfo© r   ú3lib/python3.7/site-packages/PyQt5/uic/objcreator.pyÚ__init__:   s6    




zQObjectCreator.__init__c             O   sŽ   |   |¡}|d krz| d¡}t|ƒdkrj|   |d ¡}|d k	rjx*|dd … D ]}t||d ƒ}|d krLP qLW |d krzt|ƒ‚| jj|f|ž|Ž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   ZrnameÚmethodr$   r   r   r   r*   x   s    zQObjectCreator.invokec             C   s*   x$| j D ]}| |¡}|d k	r|S qW d S )N)r   Úsearch)r   r#   ÚmoduleÚwr   r   r   r   {   s
    
zQObjectCreator.findQObjectTypec             C   s   | j  ||¡S )N)r   ÚgetSlot)r   ÚobjZslotnamer   r   r   r/   ‚   s    zQObjectCreator.getSlotc             C   s   | j  |¡S )N)r   ÚasString)r   Úsr   r   r   r1   …   s    zQObjectCreator.asStringc             C   sD   x.| j D ]$}||||ƒ\}}|r|\}}}P qW | j |||¡ d S )N)r   r   ÚaddCustomWidget)r   ZwidgetClassZ	baseClassr-   ZcwFilterÚmatchÚresultr   r   r   r3   ˆ   s    
zQObjectCreator.addCustomWidgetc          
   C   s~   t | dƒ}zdyt| ¡ ||ƒ W nJ tk
r4   dS  tk
rj } ztd|jt|ƒf ƒ‚W dd}~X Y nX W d| ¡  X 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.
        ZrUFz%s: %sNT)	ÚopenÚexecÚreadÚImportErrorÚ	Exceptionr   Ú	__class__ÚstrÚclose)r   r   r   ZpluginÚer   r   r   r   ‘   s    
,
zQObjectCreator.load_pluginN)r   )Ú__name__Ú
__module__Ú__qualname__r   r)   r*   r   r/   r1   r3   Ú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   