B
    Z(                 @   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_NAMEZStreamHandlerZsetFormatterZ	FormatterZ
addHandlerZsetLevelDEBUG_opts_ui_file)selfZoptsZui_fileZloggerZhandler r   /lib/python3.7/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   Z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   ZshowZ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	}|rd	}n| jj
rd	}d
}nd}t| j|| jj| jj|| jj| |r|  dS )z Generate the Python code. Fi   -r   )TextIOWrapperutf8)encodingZwtT.N)sys
hexversionr   outputior   stdoutbufferopenimport_fromfrom_importsr   r   Z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   r&   r'   )r   r*   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   r&   r'   str)r   r*   r   r   r   on_NoSuchClassErrorz   s    zDriver.on_NoSuchClassErrorc             C   s   t jt|d  dS )z' Handle a NoSuchWidgetError exception. r-   N)r   r&   r'   r.   )r   r*   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   r1   r&   r'   ZPYQT_VERSION_STR)r   r*   r3   r1   r   r   r   on_Exception   s    zDriver.on_ExceptionN)__name__
__module____qualname____doc__r	   r   r   r   r   r+   r,   r/   r0   r6   r   r   r   r   r      s   $r   )r   r    r   r   objectr   r   r   r   r   <module>   s   