B
    M­ñV¾  ã               @   s|   d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 e
eƒZe
ejƒZG dd„ deeƒZdd	„ ZeejƒZdd
d„ZdS )z@ Defines miscellaneous Qt-related helper classes and functions.
é    N)ÚQtCoreÚQtGui)Ú	iteritems)Ú	HasTraitsÚ	TraitTypec               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚMetaQObjectHasTraitsa   A metaclass that inherits from the metaclasses of HasTraits and QObject.

    Using this metaclass allows a class to inherit from both HasTraits and
    QObject. Using SuperQObject instead of QObject is highly recommended. See
    QtKernelManager for an example.
    c             C   sd   xNt |ƒD ]B\}}t|tƒr$||_q
t |¡r
t|tƒr
|ƒ }||_|||< q
W t | |||¡}|S )N)	r   Ú
isinstancer   ÚnameÚinspectZisclassÚ
issubclassÚMetaQObjectÚ__new__)Úmclsr	   ÚbasesÚ	classdictÚkÚvZvinstÚcls© r   ú-lib/python3.7/site-packages/qtconsole/util.pyr      s    


zMetaQObjectHasTraits.__new__c             C   s$   t  | |||¡ t | |||¡ d S )N)r   Ú__init__ÚMetaHasTraits)r   r	   r   r   r   r   r   r   '   s    zMetaQObjectHasTraits.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                s   G ‡ ‡fdd„dˆ ƒ‰ˆS )aÜ   Permits the use of super() in class hierarchies that contain Qt classes.

    Unlike QObject, SuperQObject does not accept a QObject parent. If it did,
    super could not be emulated properly (all other classes in the heierarchy
    would have to accept the parent argument--they don't, of course, because
    they don't inherit QObject.)

    This class is primarily useful for attaching signals to existing non-Qt
    classes. See QtKernelManagerMixin for an example.
    c                   s&   e Zd Z‡ fdd„Z‡ ‡fdd„ZdS )zsuperQ.<locals>.SuperQClassc                s   ˆ   | ¡}ˆ  |¡ |S )N)r   r   )r   ÚargsÚkwZinst)ÚQClassr   r   r   =   s    

z#superQ.<locals>.SuperQClass.__new__c                sZ   | j  ¡ }xˆ  ¡ D ]}| |¡ qW | ˆ¡d }|t|ƒk rV|| j| f|ž|Ž d S )Né   )Ú	__class__ÚmroÚremoveÚindexÚlenr   )Úselfr   r   r!   Zqt_classZ
next_index)r   ÚSuperQClassr   r   r   D   s    
z$superQ.<locals>.SuperQClass.__init__N)r   r   r   r   r   r   )r   r&   r   r   r&   ;   s   r&   r   )r   r   )r   r&   r   ÚsuperQ0   s    r'   c             C   s6   t  | ¡}t  |¡}|dk	r2| ¡ | kr2t  |¡}|S )a»  Return a font of the requested family, using fallback as alternative.

    If a fallback is provided, it is used in case the requested family isn't
    found.  If no fallback is given, no alternative is chosen and Qt's internal
    algorithms may automatically choose a fallback font.

    Parameters
    ----------
    family : str
      A font name.
    fallback : str
      A font name.

    Returns
    -------
    font : QFont object
    N)r   ZQFontZ	QFontInfoÚfamily)r(   ZfallbackZfontZ	font_infor   r   r   Úget_fontU   s
    


r)   )N)r   r
   Zqtconsole.qtr   r   Zipython_genutils.py3compatr   Z	traitletsr   r   Útyper   ZQObjectr   r   r'   ZSuperQObjectr)   r   r   r   r   Ú<module>   s   

