B
    ½ÞZG  ã               @   s`   d dl Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ G d	d
„ d
eƒZdS )é    Né   )Ú
Properties)ÚUIParseré   )Ú	qtproxies)ÚcreateCodeIndenterÚgetIndenterÚ
write_code)ÚCompilerCreatorPolicyc               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )Ú
UICompilerc             C   s   t  | tjtjtjtƒ ¡ d S )N)r   Ú__init__r   ZQtCoreZQtGuiZ	QtWidgetsr
   )Úself© r   ú:lib/python3.7/site-packages/PyQt5/uic/Compiler/compiler.pyr   3   s    zUICompiler.__init__c             C   s   g t _t | ¡ d S )N)r   Úi18n_stringsr   Úreset)r   r   r   r   r   7   s    zUICompiler.resetc             C   s
   |t _d S )N)r   Zi18n_context)r   Úcontextr   r   r   Ú
setContext;   s    zUICompiler.setContextc             C   sz   t ƒ }d|_| d¡ | d¡ | d| j ¡ | ¡  | d| ¡ | ¡  | jj||dddd	}||_d
| j |_|S )Nr   z*from PyQt5 import QtCore, QtGui, QtWidgetsÚ zclass Ui_%s(object):zdef setupUi(self, %s):r   FT)Zis_attributeZno_instantiationzUi_%s)	r   ÚlevelÚwriteZuinameÚindentÚfactoryZcreateQObjectÚ	baseclassÚuiclass)r   Z	classnameÚ
widgetnameÚindenterÚwr   r   r   ÚcreateToplevelWidget>   s    

zUICompiler.createToplevelWidgetc             C   s$   t dƒ t d| j ƒ t | ¡ d S )Nr   zself.retranslateUi(%s))r	   ÚtoplevelWidgetr   ÚsetDelayedProps)r   r   r   r   r    P   s    zUICompiler.setDelayedPropsc             C   sŠ   t ƒ }d|_| d¡ | d| j ¡ | ¡  tjrZ| d¡ x$tjD ]}| |¡ qFW n
| d¡ | ¡  | ¡  | j| _	| j	 
¡  d S )Nr   r   zdef retranslateUi(self, %s):z._translate = QtCore.QCoreApplication.translateÚpass)r   r   r   r   r   r   r   ÚdedentZ	resourcesÚ
_resourcesÚsort)r   r   Úsr   r   r   ÚfinalizeU   s    


zUICompiler.finalizec       	      C   sv   t |ƒ |  ||¡}tƒ }| d¡ | jj ¡  x0| jD ]&}|rRtd||f ƒ q8td| ƒ q8W t	|ƒ|j
|jdœS )Nr   zfrom %s import %sz	import %s)r   r   r   )r   Úparser   r   r   Z_cpolicyZ_writeOutImportsr#   r	   Ústrr   r   )	r   Zinput_streamZoutput_streamZfrom_importsZresource_suffixZimport_fromr   r   Zresr   r   r   Ú	compileUil   s    
zUICompiler.compileUiN)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r    r&   r)   r   r   r   r   r   2   s   r   )ÚsysZ
propertiesr   Zuiparserr   r   r   r   r   r   r	   Zqobjectcreatorr
   r   r   r   r   r   Ú<module>)   s   