ó
c›V]c           @   sñ   d  d l  Z  d d l m Z m Z m Z m Z d d l m Z e rQ d  d l Tnœ e rd d  d l	 Tn‰ d g Z
 e r– d  d l m Z d  d l m Z n) e r¿ d  d l m Z d  d l m Z n  d	 e f d
 „  ƒ  YZ d „  Z d d d „ Z d S(   iÿÿÿÿNi   (   t   PYSIDEt   PYSIDE2t   PYQT4t   PYQT5(   t	   QComboBox(   t   *t   loadUi(   t   QMetaObject(   t	   QUiLoadert   UiLoaderc           B   s)   e  Z d  Z d d „ Z d d d „ Z RS(   s£  
        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`.
        c         C   s>   t  j |  | ƒ | |  _ | d k r1 i  |  _ n	 | |  _ d S(   sh  
            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   t   __init__t   baseinstancet   Nonet   customWidgets(   t   selfR   R   (    (    s'   lib/python2.7/site-packages/qtpy/uic.pyR
   d   s
    	t    c         C   s»   | d k r |  j r |  j S| |  j ƒ  k s: | d k rU t j |  | | | ƒ } n? y |  j | | ƒ } Wn% t k
 r“ t d | d ƒ ‚ n X|  j r³ t |  j | | ƒ n  | Sd S(   s“   
            Function that is called for each widget defined in ui file,
            overridden here to populate baseinstance instead.
            t   Lines   No custom widget s    found in customWidgetsN(	   R   R   t   availableWidgetsR   t   createWidgetR   t   KeyErrort	   Exceptiont   setattr(   R   t
   class_namet   parentt   namet   widget(    (    s'   lib/python2.7/site-packages/qtpy/uic.pyR   }   s    	N(   t   __name__t
   __module__t   __doc__R   R
   R   (    (    (    s'   lib/python2.7/site-packages/qtpy/uic.pyR	   X   s   
c         C   sÆ   d d l  } d d l } d d l m } | ƒ  } | j |  ƒ } | j d ƒ } | d k r_ i  Si  } xZ | j ƒ  D]L } | j d ƒ j }	 | j d ƒ j }
 | j	 |
 ƒ } t
 | |	 ƒ | |	 <qr W| S(   s£   
        This function is used to parse a ui file and look for the <customwidgets>
        section, then automatically load all the custom widget classes.
        iÿÿÿÿN(   t   ElementTreet   customwidgetst   classt   header(   t   syst	   importlibt   xml.etree.ElementTreeR   t   parset   findR   t   getchildrent   textt   import_modulet   getattr(   t   ui_fileR!   R"   R   t   etreet   uit   custom_widgetst   custom_widget_classest   custom_widgett   cw_classt	   cw_headert   module(    (    s'   lib/python2.7/site-packages/qtpy/uic.pyt   _get_custom_widgets¢   s    	c         C   sW   t  |  ƒ } t | | ƒ } | d k	 r7 | j | ƒ n  | j |  ƒ } t j | ƒ | S(   sj  
        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(   R3   R	   R   t   setWorkingDirectoryt   loadR   t   connectSlotsByName(   t   uifileR   t   workingDirectoryR   t   loaderR   (    (    s'   lib/python2.7/site-packages/qtpy/uic.pyR   Ã   s    (   t   osR   R    R   R   R   t	   QtWidgetsR   t	   PyQt5.uict	   PyQt4.uict   __all__t   PySide.QtCoreR   t   PySide.QtUiToolsR   t   PySide2.QtCoret   PySide2.QtUiToolsR	   R3   R   R   (    (    (    s'   lib/python2.7/site-packages/qtpy/uic.pyt   <module>   s    "	@J	!