
    dne-                     <   d dl mZmZmZmZ erddl yerddl yddgZerddlm	Z	 ddl
mZmZ nGerEddlm	Z	 ddlmZ 	 dd	lmZ dd
lmZ ddlmZ  G d de      Zd Zej,                  e_        ee_         G d de      Zd ZddZerddZyy# e$ r Y !w xY w)   )PYQT5PYQT6PYSIDE2PYSIDE6    )*loadUi
loadUiType)QMetaObject)	QUiLoaderr
   )r   )Element)	compileUi)UIParserc                       e Zd Zd Zy)ElemPatchedc                 &     | j                   |i |S N)iter)selfargskwargss      (lib/python3.12/site-packages/qtpy/uic.pygetiteratorzElemPatched.getiterator\   s    $499d5f55    N)__name__
__module____qualname__r    r   r   r   r   [   s    6r   r   c                 6    | j                  t        |            S r   )_readResourcesr   )r   elems     r   readResourcesr"   _   s    **;t+<==r   c                        e Zd ZdZddZddZy)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                 `    t        j                  | |       || _        |i | _        y|| _        y)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(   s      r   r&   zUiLoader.__init__s   s2      t\2 ,D$%'"%2"r   c                 N   || j                   r| j                   S || j                         v s|dk(  rt        j                  | |||      }n	  | j                  |   |      }| j                   rt        | j                   ||       |S # t
        $ r}t        d| d      |d}~ww xY w)z
            Function that is called for each widget defined in ui file,
            overridden here to populate baseinstance instead.
            NLinezNo custom widget z found in customWidgets)r'   availableWidgetsr   createWidgetr(   KeyErrorNoCustomWidgetsetattr)r   
class_nameparentnamewidgeterrors         r   r,   zUiLoader.createWidget   s     ~$"3"3 ((( T2244
f8L"//	!;T//
;FCF    ))48M   !(+J< 81 1 !!!s   B 	B$BB$r   )N )r   r   r   __doc__r&   r,   r   r   r   r$   r$   g   s    			32(	r   r$   c                 D   ddl }ddlm}  |       }|j                  |       }|j	                  d      }|i S i }t        |      D ]X  }|j	                  d      j                  }|j	                  d      j                  }	|j                  |	      }
t        |
|      ||<   Z |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ElementTreecustomwidgetsclassheader)		importlibxml.etree.ElementTreer9   parsefindlisttextimport_modulegetattr)ui_filer=   r9   etreeuicustom_widgetscustom_widget_classescustom_widgetcw_class	cw_headermodules              r   _get_custom_widgetsrN      s     	5 [[! 1!I "!.1 	HM$))'277H%**8499I,,Y7F.5fh.G!(+	H %$r   Nc                     t        |       }t        ||      }||j                  |       |j                  |       }t	        j
                  |       |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.
        )rN   r$   setWorkingDirectoryloadr   connectSlotsByName)uifiler'   workingDirectoryr(   loaderr3   s         r   r	   r	      sP    0 ,F3,6'&&'78V$&&v.r   c                    ddl }ddlm} ddlm} ddlm}  |       }|j                  |       }|j                  d      j                  d      }|j                  d      j                  }	t        | d	
      5 }
 |       }i }t        |
|d|       t        |j                         dd      }t        ||       |d|	z     }	t!        ||      }ddd       |	|fS # 1 sw Y   |	fS xY w)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)StringIOr8   r   )	QtWidgetsr3   r;   zutf-8)encoding)indentfrom_importsz<string>execzUi_%s)sysiorW   r>   r9   r5   rX   r?   r@   getrB   openr   compilegetvaluer\   rD   )rS   r[   r]   rW   r9   rX   rF   rG   widget_class
form_classfdcode_streamframepyc
base_classs                  r   r
   r
      s     #9#  MEV$B778,009L)..Jfw/ >2&j"k!,Ok224j&IS%  #7Z#78
$Y=
> z))> z))s   7ACC#)NN)F)r5   r   r   r   r   	PyQt6.uic	PyQt5.uic__all__PySide6.QtCorer   PySide6.QtUiToolsr   r
   PySide2.QtCorePySide2.QtUiToolsr>   r   
pyside2uicr   pyside2uic.uiparserr   r   r"   r    ImportErrorr$   rN   r	   r   r   r   <module>rt      s    , ,
 &G@ .;;	./	5,
 56g 6> '/&<&<H#%2H"M9 M^%>!F %	* i  		s   8B BB