o
    i                     @   s   d Z ddlZz ddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZ dZW n ey1   dZY nw erHdZe s>eg ZG d	d
 d
e	ZdS dS )A qt screenshot exporter.    N)QtCore)QPageLayout	QPageSize)QWebEngineSettingsQWebEngineView)QApplicationTFc                       sH   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	  Z
S )QtScreenshotr   c                    s   t    t| _dS )zInitialize the exporter.N)super__init__APPappself	__class__ \/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbconvert/exporters/qt_screenshot.pyr      s   

zQtScreenshot.__init__c                    s   | _ | _ t|  j j  tj	j
    tjd d _|drB j _ fdd}  j| n|drL j _n	d| }t|    j  dS )	zCapture the screenshot.F    z.pdfc                     s    j      dS )zCleanup the app.N)r   quitget_data)argsr   r   r   cleanup-   s   
z%QtScreenshot.capture.<locals>.cleanupz.pngz%Export file extension not supported: N)output_filepaginateloadr   QUrlloadFinishedconnect	on_loadedsetAttributeQtWA_DontShowOnScreenpagesettingsr   ShowScrollBarsdataendswith
export_pdfexportpdfPrintingFinished
export_pngRuntimeErrorshowr   exec)r   urlr   r   r   msgr   r   r   capture    s"   



zQtScreenshot.capturec                 C   s2   |     | _| | j tjd| j dS )zHandle app load.i  N)	r#   contentsSizetoSizesizeresizer   QTimer
singleShotr)   r   r   r   r   r   ;   s   zQtScreenshot.on_loadedc                 C   sz   | j rttj}t|tjt }nd}tt| j	 | | j
 | tj}t|tjt }|  j| j|d dS )zExport to pdf.g      ?)
pageLayoutN)r   r   A4r   Portraitr   	QMarginsFQSizeFr4   widthheightPointr#   
printToPdfr   )r   	page_sizepage_layoutfactorr   r   r   r(   B   s   
zQtScreenshot.export_pdfc                 C   s(   |   | jd | j  |   dS )zExport to png.PNGN)grabsaver   r   r   r   r   r   r   r   r+   Q   s   
zQtScreenshot.export_pngc                 C   sX   t j| jr*t| jd}| | _W d   n1 sw   Y  t | j dS dS )zGet output data.rbN)ospathexistsr   openreadr&   unlink)r   fr   r   r   r   W   s   zQtScreenshot.get_data)__name__
__module____qualname____doc__r   r1   r   r(   r+   r   __classcell__r   r   r   r   r	      s    r	   )rR   rH   PyQt5r   PyQt5.QtGuir   r   PyQt5.QtWebEngineWidgetsr   r   PyQt5.QtWidgetsr   QT_INSTALLEDModuleNotFoundErrorr   instancer	   r   r   r   r   <module>   s"    