
    o'e(                     :    d dl Z d dlZddlmZmZ  G d de      Zy)    N   )	compileUiloadUic                   J    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)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                 F   |j                   rt        j                  | j                        }t        j                         }|j                  t        j                  d             |j                  |       |j                  t        j                         || _
        || _        y)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optsui_fileloggerhandlers        2/usr/lib/python3/dist-packages/PyQt5/uic/driver.py__init__zDriver.__init__$   su    
 ::&&t'7'78F++-G  !2!23J!KLg&OOGMM*
    c                 p    | j                   j                  r| j                         S | j                          y)zi Invoke the action as specified by the parsed options.  Returns 0 if
        there was no error.
        r   )r   preview_preview	_generate)r   s    r   invokezDriver.invoke3   s*    
 ::==?"r   c                     ddl m} |j                  | j                  g      }t	        | j                        }|j                          |j                         S )zh Preview the .ui file.  Return the exit status to be passed back to
        the parent process.
        r   )	QtWidgets)PyQt5r#   QApplicationr   r   showexec_)r   r#   appwidgets       r   r   zDriver._preview?   s@    
 	$$$dmm_5&yy{r   c           	         d}t         j                  dk\  rg| j                  j                  dk(  r)ddlm}  |t         j                  j                  d      }nqt        | j                  j                  dd      }d	}nL| j                  j                  dk(  rt         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|j!                          yy)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indentresource_suffixclose)r   needs_closer,   pyfiler8   r9   s         r   r    zDriver._generateL   s    >>Z'zz  C',&szz'8'86Jdjj//G"zz  C'djj//6"jj,,LZZ$$LK L$--););TZZ=N=Ndjj88+	G LLN r   c                 x    t         j                  j                  d|j                  d|j                  d       y)z Handle an IOError exception. zError: z: "z"
N)r1   stderrwritestrerrorfilenamer   es     r   
on_IOErrorzDriver.on_IOErrorp   s#     	

!**ajjIJr   c                 H    t         j                  j                  d|z         y)z! Handle a SyntaxError exception. zError in input file: %s
N)r1   rA   rB   rE   s     r   on_SyntaxErrorzDriver.on_SyntaxErroru   s     	

4q89r   c                 Z    t         j                  j                  t        |      dz          y)z& Handle a NoSuchClassError exception. 
Nr1   rA   rB   strrE   s     r   on_NoSuchClassErrorzDriver.on_NoSuchClassErrorz        	

Q$'r   c                 Z    t         j                  j                  t        |      dz          y)z' Handle a NoSuchWidgetError exception. rK   NrL   rE   s     r   on_NoSuchWidgetErrorzDriver.on_NoSuchWidgetError   rO   r   c                 (   t        j                  | j                        j                  t         j                  k(  r&ddl} |j                  t        j                           yddl	m
} t        j                  j                  d|j                  z         y)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_exceptionr1   exc_infor$   rS   rA   rB   PYQT_VERSION_STR)r   rF   rU   rS   s       r   on_ExceptionzDriver.on_Exception   sj     T--.44E%I%%s||~6$JJ   r   N)__name__
__module____qualname____doc__r   r   r!   r   r    rG   rI   rN   rQ   rY    r   r   r   r      s=     K 
"HK
:
(
(
r   r   )r1   r
    r   r   objectr   r^   r   r   <module>ra      s   .   xV xr   