a
    ¢–Be(  ã                   @   s4   d dl Z d dlZddlmZmZ G dd„ deƒZdS )é    Né   )Ú	compileUiÚloadUic                   @   s\   e Zd Zd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d„ Zdd„ ZdS )ÚDriverz} This encapsulates access to the pyuic functionality so that it can be
    called by code that is Python v2/v3 specific.
    z	PyQt5.uicc                 C   sP   |j r@t | j¡}t ¡ }| t d¡¡ | |¡ | tj	¡ || _
|| _dS )zk Initialise the object.  opts is the parsed options.  ui_file is the
        name of the .ui file.
        z%(name)s: %(message)sN)ÚdebugÚloggingÚ	getLoggerÚLOGGER_NAMEÚStreamHandlerÚsetFormatterÚ	FormatterÚ
addHandlerÚsetLevelÚDEBUGÚ_optsÚ_ui_file)ÚselfÚoptsZui_fileÚloggerÚhandler© r   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/PyQt5/uic/driver.pyÚ__init__$   s    
zDriver.__init__c                 C   s   | j jr|  ¡ S |  ¡  dS )zi Invoke the action as specified by the parsed options.  Returns 0 if
        there was no error.
        r   )r   ÚpreviewÚ_previewÚ	_generate)r   r   r   r   Úinvoke3   s    zDriver.invokec                 C   s4   ddl m} | | jg¡}t| jƒ}| ¡  | ¡ S )zh Preview the .ui file.  Return the exit status to be passed back to
        the parent process.
        r   )Ú	QtWidgets)ÚPyQt5r   ZQApplicationr   r   ÚshowÚexec_)r   r   ZappZwidgetr   r   r   r   ?   s
    
zDriver._previewc                 C   sÐ   d}t jdkrP| jjdkr8ddlm} |t jjdd�}qvt| jjddd�}d	}n&| jjdkrdt j}nt| jjdƒ}d	}| jj	}|rˆd	}n| jj
ršd	}d
}nd}t| j|| jj| jj|| jj|ƒ |rÌ| ¡  dS )z Generate the Python code. Fi   ú-r   )ÚTextIOWrapperÚutf8)ÚencodingÚwtTÚ.N)ÚsysÚ
hexversionr   ÚoutputÚior"   ÚstdoutÚbufferÚopenÚimport_fromÚfrom_importsr   r   ÚexecuteÚindentZresource_suffixÚclose)r   Zneeds_closer"   Zpyfiler.   r/   r   r   r   r   L   s.    

ÿzDriver._generatec                 C   s   t j d|j|jf ¡ dS )z Handle an IOError exception. zError: %s: "%s"
N)r'   ÚstderrÚwriteÚstrerrorÚfilename©r   Úer   r   r   Ú
on_IOErrorp   s    zDriver.on_IOErrorc                 C   s   t j d| ¡ dS )z! Handle a SyntaxError exception. zError in input file: %s
N)r'   r3   r4   r7   r   r   r   Úon_SyntaxErroru   s    zDriver.on_SyntaxErrorc                 C   s   t j t|ƒd ¡ dS )z& Handle a NoSuchClassError exception. Ú
N©r'   r3   r4   Ústrr7   r   r   r   Úon_NoSuchClassErrorz   s    zDriver.on_NoSuchClassErrorc                 C   s   t j t|ƒd ¡ dS )z' Handle a NoSuchWidgetError exception. r;   Nr<   r7   r   r   r   Úon_NoSuchWidgetError   s    zDriver.on_NoSuchWidgetErrorc                 C   sN   t  | j¡jt jkr,ddl}|jt ¡ Ž  nddl	m
} tj d|j ¡ dS )z Handle a generic exception. r   N)ÚQtCorea?  An unexpected error occurred.
Check that you are using the latest version of PyQt5 and send an error report to
support@riverbankcomputing.com, including the following information:

  * your version of PyQt (%s)
  * the UI file that caused this error
  * the debug output of pyuic5 (use the -d flag when calling pyuic5)
)r   r   r	   Úlevelr   Ú	tracebackÚprint_exceptionr'   Úexc_infor   r@   r3   r4   ZPYQT_VERSION_STR)r   r8   rB   r@   r   r   r   Úon_Exception„   s    ùzDriver.on_ExceptionN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r9   r:   r>   r?   rE   r   r   r   r   r      s   $r   )r'   r   Ú r   r   Úobjectr   r   r   r   r   Ú<module>   s   