a
    s=ic$                  	   @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z ddlZddlmZ ddlmZ dZdZd	Zd
ZejdZedure ZeeeedZejdreZnejdreZnejdreZnejdreZnrej pd dr*edv r ee ZndZdZn:edu r:dZn*eev rNee Zned ed!edd Z"eeeeefv re"  nedu rere"efe"efgZ#ne"efe"efe"efe"efgZ#e#D ]6\Z$Zz
e$  W n e%y   Y qY n0  q(qe%d d!e& ne'de ejdkrtee( d edkrtt)j*+ , g dkrtej-dd edkre.d ne/Z0e1dd!d" Z2d#d$ Z3d%d& Z4d'd( Z5ej6d)d* Z7ej8G d+d, d,Z9dS )-a[  
Qt binding and backend selector.

The selection logic is as follows:
- if any of PyQt6, PySide6, PyQt5, or PySide2 have already been
  imported (checked in that order), use it;
- otherwise, if the QT_API environment variable (used by Enthought) is set, use
  it to determine which binding to use;
- otherwise, use whatever the rcParams indicate.
    N)parse)_api   )_QT_FORCE_QT5_BINDINGPyQt6PySide6PyQt5PySide2QT_API)Zpyqt6Zpyside6pyqt5pyside2zPyQt6.QtCorezPySide6.QtCorezPyQt5.QtCorezPySide2.QtCore Zqt5r   r   TzTThe environment variable QT_API has the unrecognized value {!r}; valid values are {}z, c                     s  t tkrFddlmamamam}  tjatj	t_
tjt_tjt_| jant tkr|ddlmamamama dd lfddant tkrddlmamama dd l} tjatj	t_
tjt_tjt_| janDt tkrddlmamamama dd l  fddantdt  tjjad S )	Nr   )QtCoreQtGui	QtWidgetssip)r   r   r   __version__c                    s     |  S NZisValidobj)	shiboken6 n/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py
_isdeletedT       r   )r   r   r   c                    s     |  S r   r   r   )	shiboken2r   r   r   `   s    Unexpected QT_API: )r
   QT_API_PYQT6r   r   r   r   r   ZPYQT_VERSION_STRr   Z
pyqtSignalZSignalZpyqtSlotZSlotZpyqtPropertyPropertyZ	isdeletedr   QT_API_PYSIDE6r   r   QT_API_PYQT5r   QT_API_PYSIDE2r	   r   AssertionErrorZQFileDialogZgetSaveFileNameZ_getSaveFileName)r   r   )r   r   r   _setup_pyqt5plusG   s2    r%   z<Failed to import any of the following Qt binding modules: {}r   darwinz10.16)         ZQT_MAC_WANTS_LAYER1valuec                 C   s,   t tdkr| n| dd tjtj S )Nr   .r   )operator
attrgetterr
   
rpartitionsysmodulesr   __package__)namer   r   r   _enum   s
    
r4   c                 C   s   t | dr|  n|   d S )Nexec)hasattrr5   exec_r   r   r   r   _exec   s    r8   c                 C   sJ   z|   pdW S  ty    Y n0 z|  p.dW S  tyD   Y dS 0 dS )z
    Return obj.devicePixelRatioF() with graceful fallback for older Qt.

    This can be replaced by the direct call when we require Qt>=5.6.
    r   N)ZdevicePixelRatioFAttributeErrorZdevicePixelRatior   r   r   r   _devicePixelRatioF   s    r:   c                 C   s   t | dr| | dS )z
    Call obj.setDevicePixelRatio(val) with graceful fallback for older Qt.

    This can be replaced by the direct call when we require Qt>=5.6.
    setDevicePixelRatioN)r6   r;   )r   valr   r   r   _setDevicePixelRatio   s    
r=   c              
   #   sB  t t j}d d}|dt jt jfv r,d}ntt \}|d t |	 }t
	 tdj}d |jjfdd} fdd}t  t j| zPdV  W |s|    |d t | t  t j|  dur|   nL|s<|    |d t | t  t j|  dur<|   0 dS )	aN  
    This manager allows to terminate a plot by sending a SIGINT. It is
    necessary because the running Qt backend prevents Python interpreter to
    run and process signals (i.e., to raise KeyboardInterrupt exception). To
    solve this one needs to somehow wake up the interpreter and make it close
    the plot window. We do this by using the signal.set_wakeup_fd() function
    which organizes a write of the signal number into a socketpair connected
    to the QSocketNotifier (since it is part of the Qt backend, it can react
    to that write event). Afterwards, the Qt handler empties the socketpair
    by a recv() command to re-arm it (we need this if a signal different from
    SIGINT was caught by set_wakeup_fd() and we shall continue waiting). If
    the SIGINT was caught indeed, after exiting the on_signal() function the
    interpreter reacts to the SIGINT according to the handle() function which
    had been set up by a signal.signal() call: it causes the qt_object to
    exit by calling its quit() method. Finally, we call the old SIGINT
    handler with the same arguments that were given to our custom handle()
    handler.

    We do this only if the old handler for SIGINT was not None, which means
    that a non-python handler was installed, i.e. in Julia, and not SIG_IGN
    which means we should ignore the interrupts.
    NFTzQtCore.QSocketNotifier.Typec                     s&   z  d W n ty    Y n0 d S )Nr   )recvBlockingIOErrorargs)rsockr   r   _may_clear_sock   s    z/_maybe_allow_interrupt.<locals>._may_clear_sockc                     s   |     d S r   )quitr@   )handler_argsqappr   r   handle   s    z&_maybe_allow_interrupt.<locals>.handle)signal	getsignalSIGINTSIG_IGNSIG_DFLsocket
socketpairsetblockingset_wakeup_fdfilenor   ZQSocketNotifierr4   ZRead	activatedconnectcloseZ
setEnabled)rF   Zold_sigint_handlerskipZwsockZold_wakeup_fdZsnrC   rG   r   )rE   rF   rB   r   _maybe_allow_interrupt   sD    








rV   c                   @   s8   e Zd Zededd Zededd ZdS )__getattr__z3.5c                 C   s   t tdftdfdS )Nr'   r   )dictr"   r#   selfr   r   r   <lambda>
  s   z__getattr__.<lambda>c                 C   s   t t dd S )Nr,   r   )intr   ZqVersionsplitrY   r   r   r   r[     r   N)__name__
__module____qualname__r   
deprecatedpropertyZETSZQT_RC_MAJOR_VERSIONr   r   r   r   rW     s   
rW   ):__doc__	functoolsr-   osplatformr0   rH   rM   
contextlibZpackaging.versionr   parse_versionZ
matplotlibZmplr   r   r   r   r!   r"   r#   environgetZ
QT_API_ENVlowerZ_ETSr1   r
   ZrcParamsZ_get_backend_or_none
startswithRuntimeErrorformatjoinr%   _candidates_setupImportErrorvaluesr$   mac_verr   ZQLibraryInfoversionsegments
setdefaultr.   r\   Z_to_int	lru_cacher4   r8   r:   r=   contextmanagerrV   Zcaching_module_getattrrW   r   r   r   r   <module>   s   





 





F