a
    Df-                     @   s  d dl mZmZmZmZ er&ddlT ner4ddlT nddgZer^ddlm	Z	 ddl
mZmZ n~erddlm	Z	 ddlmZ zNdd	lmZ dd
lmZ ddlmZ G dd deZdd Zeje_ee_W n ey   Y n0 G dd deZdd ZdddZerdddZdS )   )PYQT5PYQT6PYSIDE2PYSIDE6    )*loadUi
loadUiType)QMetaObject)	QUiLoaderr	   )r   )Element)	compileUi)UIParserc                   @   s   e Zd Zdd ZdS )ElemPatchedc                 O   s   | j |i |S N)iter)selfargskwargs r   U/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/qtpy/uic.pygetiterator\   s    zElemPatched.getiteratorN)__name__
__module____qualname__r   r   r   r   r   r   [   s   r   c                 C   s   |  t|S r   )_readResourcesr   )r   elemr   r   r   readResources_   s    r   c                   @   s$   e Zd ZdZdddZd	ddZdS )
UiLoadera  
        Subclass of :class:`~PySide.QtUiTools.QUiLoader` to create the user
        interface in a base instance.

        Unlike :class:`~PySide.QtUiTools.QUiLoader` itself this class does not
        create a new instance of the top-level widget, but creates the user
        interface in an existing instance of the top-level class if needed.

        This mimics the behaviour of :func:`PyQt4.uic.loadUi`.
        Nc                 C   s,   t | | || _|du r"i | _n|| _dS )ah  
            Create a loader for the given ``baseinstance``.

            The user interface is created in ``baseinstance``, which must be an
            instance of the top-level class in the user interface to load, or a
            subclass thereof.

            ``customWidgets`` is a dictionary mapping from class name to class
            object for custom widgets. Usually, this should be done by calling
            registerCustomWidget on the QUiLoader, but with PySide 1.1.2 on
            Ubuntu 12.04 x86_64 this causes a segfault.

            ``parent`` is the parent object of this loader.
            N)r   __init__baseinstancecustomWidgets)r   r    r!   r   r   r   r   s   s
    zUiLoader.__init__ c              
   C   s   |du r| j r| j S ||  v s(|dkr:t| |||}nJz| j| |}W n6 ty } ztd| d|W Y d}~n
d}~0 0 | j rt| j || |S )z
            Function that is called for each widget defined in ui file,
            overridden here to populate baseinstance instead.
            NZLinezNo custom widget z found in customWidgets)r    ZavailableWidgetsr   createWidgetr!   KeyErrorZNoCustomWidgetsetattr)r   
class_nameparentnamewidgeterrorr   r   r   r#      s(    
zUiLoader.createWidget)N)Nr"   )r   r   r   __doc__r   r#   r   r   r   r   r   g   s   
r   c                 C   s   ddl }ddlm} | }|| }|d}|du r:i S i }t|D ]4}|dj}|dj}	||	}
t|
|||< qF|S )z
        This function is used to parse a ui file and look for the <customwidgets>
        section, then automatically load all the custom widget classes.
        r   NElementTreeZcustomwidgetsclassheader)		importlibxml.etree.ElementTreer-   parsefindlisttextimport_modulegetattr)Zui_filer0   r-   etreeuiZcustom_widgetsZcustom_widget_classesZcustom_widgetZcw_classZ	cw_headermoduler   r   r   _get_custom_widgets   s    


r;   Nc                 C   s<   t | }t||}|dur$|| || }t| |S )aj  
        Dynamically load a user interface from the given ``uifile``.

        ``uifile`` is a string containing a file name of the UI file to load.

        If ``baseinstance`` is ``None``, the a new instance of the top-level
        widget will be created. Otherwise, the user interface is created within
        the given ``baseinstance``. In this case ``baseinstance`` must be an
        instance of the top-level widget class in the UI file to load, or a
        subclass thereof. In other words, if you've created a ``QMainWindow``
        interface in the designer, ``baseinstance`` must be a ``QMainWindow``
        or a subclass thereof, too. You cannot load a ``QMainWindow`` UI file
        with a plain :class:`~PySide.QtGui.QWidget` as ``baseinstance``.

        :method:`~PySide.QtCore.QMetaObject.connectSlotsByName()` is called on
        the created user interface, so you can implemented your slots according
        to its conventions in your widget class.

        Return ``baseinstance``, if ``baseinstance`` is not ``None``. Otherwise
        return the newly created instance of the user interface.
        N)r;   r   ZsetWorkingDirectoryloadr
   ZconnectSlotsByName)uifiler    ZworkingDirectoryr!   loaderr)   r   r   r   r      s    



Fc                 C   s   ddl }ddlm} ddlm} ddlm} | }|| }|d	d}|dj
}	t| d	d
Z}
| }i }t|
|d|d t| dd}t|| |d|	  }	t||}W d   n1 s0    Y  |	|fS )aV  Load a .ui file and return the generated form class and
            the Qt base class.

            The "loadUiType" command convert the ui file to py code
            in-memory first and then execute it in a special frame to
            retrieve the form_class.

            Credit: https://stackoverflow.com/a/14195313/15954282
            r   N)StringIOr,   r   )	QtWidgetsr)   r.   zutf-8)encoding)indentfrom_importsz<string>execzUi_%s)sysior?   r1   r-   r"   r@   r2   r3   getr5   openr   compilegetvaluerD   r7   )r=   rC   rE   r?   r-   r@   r8   r9   Zwidget_classZ
form_classfdZcode_streamframeZpycZ
base_classr   r   r   r	      s"    

()NN)F)r"   r   r   r   r   Z	PyQt6.uicZ	PyQt5.uic__all__ZPySide6.QtCorer
   ZPySide6.QtUiToolsr   r	   ZPySide2.QtCoreZPySide2.QtUiToolsr1   r   Z
pyside2uicr   Zpyside2uic.uiparserr   r   r   r   ImportErrorr   r;   r   r   r   r   r   <module>   s4   

@
O
#