o
    j2                     @   s  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mZ d dlmZ d dl	Z	d dl
Z
d dl
mZ d dlmZ d dl
mZ zd dlmZ d dlmZ d d	lmZ W n ey_   e	jd
ZY nw dZe	jdd Ze	jjddddd Ze	jjdddgdfdg dfddgdfddgdfdg dfddgdfd dgd!fdg d"d#fd$g dfd%g d&fd%dgd'fgg d(d)e	jd*e	jd+e	jjd+ddd,e	jde	jjdddd,gd-d. Z e	jjdddd/d0 Z!e	jjdddd1d2 Z"e	jjdddd3d4 Z#e	jjdddd5d6 Z$e	jjdddd7d8 Z%e	jjdddd9d: Z&e	jjdddd;d< Z'e	jjd+ddd=d> Z(d?d@ Z)e	jjddddAdB Z*e	jjddddCdD Z+dS )E    N)datedatetime)mock)pyplot)Gcf)_c_internal_utils)QtGui)	QtWidgets)_formlayoutzNo usable Qt bindings<   c                 C   s   ddl m} |S )Nr   )QtCore)matplotlib.backends.qt_compatr   )requestr    r   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/matplotlib/tests/test_backend_qt.pyqt_core   s   r   QtAggT)Zskip_on_importerrorc                  C   s4   t  tj} t }|jjj  | tjksJ d S N)	copyr   Zfigspltfigurecanvasmanagerwindowclose)Z	init_figsfigr   r   r   test_fig_close"   s   r   zqt_key, qt_mods, answerZKey_AZShiftModifierAaControlModifierzctrl+aZ
Key_Aacute   Á   áZKey_ControlAltModifierzalt+controlZKey_Altzctrl+alt)r   r"   ZMetaModifieru   ctrl+alt+meta+áZKey_PlayZKey_Backspace	backspacezctrl+backspace)shiftlowercontrolZunicode_upperZunicode_lowerZalt_controlZcontrol_altZmodifier_orderZnon_unicode_keyr#   Zbackspace_mod)ZidsbackendQt5Agg)marksc           
         s   ddl mm  tjdkr#|dur#|dd}|dd}|dd}d jjj|D ]}t	 jj|O q,G  fd	d
d
}|
tjdfdd fdd}t j}	|	d| |	|  |kslJ dS )z
    Make a figure.
    Send a key_press_event event (using non-public, qtX backend specific api).
    Catch the event.
    Assert sent and caught keys are the same.
    r   )_to_intr   darwinNZctrlcmdr&   metac                       s$   e Zd Zdd Z fddZdS )z test_correct_key.<locals>._Eventc                 S   s   dS )NFr   selfr   r   r   isAutoRepeat{       z-test_correct_key.<locals>._Event.isAutoRepeatc                    s   t  jjS r   )getattrQtKeyr.   r   r*   qt_keyr   r   key|   s    z$test_correct_key.<locals>._Event.keyN)__name__
__module____qualname__r0   r7   r   r5   r   r   _Eventz   s    r;   ZkeyboardModifiersc                    s    S r   r   r.   )qt_modr   r   <lambda>   r1   z"test_correct_key.<locals>.<lambda>c                    s
   | j  d S r   )r7   )event)resultr   r   on_key_press   s   
z&test_correct_key.<locals>.on_key_pressZkey_press_event)r   r*   r   sysplatformreplacer3   ZKeyboardModifierZ
NoModifierr2   setattrr	   ZQApplicationr   r   r   Zmpl_connectZkeyPressEvent)
r'   r   r6   Zqt_modsZanswerZmonkeypatchmodr;   r@   	qt_canvasr   )r   r*   r6   r<   r?   r   test_correct_key4   s$   ;



rG   c           
         s$  d}t | d _tjddd}|j   fdd}j    	  
 }g d}|D ]G\}}}}	|d	urF|| |j|ksMJ jj|ksUJ jj|	ks]J | d
kseJ | dksmJ  dksuJ | dk sJ q8W d	   d	S 1 sw   Y  d	S )z}
    Make sure that if the pixel ratio changes, the figure dpi changes but the
    widget remains the same logical size.
    z?matplotlib.backends.backend_qt.FigureCanvasQT.devicePixelRatioF   )      x   )Zfigsizedpic                    s   |  _   }tdd  ddd d D }|dkr.j|jj	j
 n| jd     j| ksEJ d S )Nc                 s   s    | ]}t |V  qd S r   )int).0xr   r   r   	<genexpr>   s    
zQtest_device_pixel_ratio_change.<locals>.set_device_pixel_ratio.<locals>.<genexpr>.rJ   )   rR   `   )return_valuer   ZwindowHandletupleZqVersionsplitQCoreApplicationZ	sendEventZQEventTypeZDevicePixelRatioChangescreenZlogicalDotsPerInchChangedemitdrawflush_eventsZdevice_pixel_ratio)ratior   current_versionprF   r   r   r   set_device_pixel_ratio   s   z>test_device_pixel_ratio_change.<locals>.set_device_pixel_ratio))Nh      )rH   rb   rc   rd   )rJ      i  i  )g      ?   i  rb   NX  re   )rg   re   )r   patchrT   r   r   r   showr   r[   r\   sizerL   rendererwidthheightZget_width_heightZget_size_inchesall)
r   propr   ra   rj   optionsr]   rL   rl   rm   r   r_   r   test_device_pixel_ratio_change   s0   
"rq   c                  C   sP   t  \} }tddd  | jjj  W d    d S 1 s!w   Y  d S )N#matplotlib.backends.qt_compat._execc                 S      d S r   r   objr   r   r   r=      r1   z"test_subplottool.<locals>.<lambda>)r   subplotsr   rh   r   r   toolbarZconfigure_subplotsr   axr   r   r   test_subplottool   s   "rz   c                  C   s   t  \} }|ddg |dgg |jtdtdtdd tddd  | jj	j
  W d    d S 1 s=w   Y  d S )N   rJ   rH   )crr   c                 S   rs   r   r   rt   r   r   r   r=      r1   z$test_figureoptions.<locals>.<lambda>)r   rv   plotimshowZscatterranger   rh   r   r   rw   edit_parametersrx   r   r   r   test_figureoptions   s   "r   c                 C   s   t  \}}|dgg | d }d}tj|t|d fd |jjj	 }|t|ks.J |
 s4J W d    n1 s>w   Y  tj|dd |jjj	 }|d u sXJ W d    d S 1 scw   Y  d S )Nr{   z
foobar.pngzCmatplotlib.backends.qt_compat.QtWidgets.QFileDialog.getSaveFileName)rT   )NN)r   rv   r~   r   rh   strr   r   rw   Zsave_figureexists)Ztmp_pathr   ry   expectedro   fnamer   r   r   test_save_figure_return   s   "r   c                  C   sx   t  \} }tddddtddddg}||| tddd  | jjj	  W d    d S 1 s5w   Y  d S )N  r{   yearmonthdayrJ   rr   c                 S   rs   r   r   rt   r   r   r   r=      r1   z7test_figureoptions_with_datetime_axes.<locals>.<lambda>)
r   rv   r   r}   r   rh   r   r   rw   r   )r   ry   Zxydatar   r   r   %test_figureoptions_with_datetime_axes   s   "r   c                  C   s   t  \} }| j  | jjj}d\}}| || | j |tj	d  ks(J | j
 |tj	d  ks6J | }|
 }| || | |ksLJ |
 |ksTJ d S )N)rH   rJ   z
figure.dpi)r   rv   r   r[   r   r   Zset_size_inchesrl   
matplotlibZrcParamsrm   )r   ry   r   whZ	old_widthZ
old_heightr   r   r   test_double_resize   s   

r   c                     sH   ddl m}  d  fdd}t \}}||_| |}d|_ s"J d S )Nr   )FigureCanvasQTAggFc                    s   | j   d d S )NT)r   Z	draw_idle)r   staleZcalledr   r   crashing_callback  s   
z-test_canvas_reinit.<locals>.crashing_callbackT)Z!matplotlib.backends.backend_qtaggr   r   rv   Zstale_callbackr   )r   r   r   ry   r   r   r   r   test_canvas_reinit  s   r   c                  C   sx   ddl m}  |   dtddddfdtddddfg}t|}|  | }|tddddtddddgks:J d S )	Nr   )_create_qAppzDatetime fieldr   rH      r   z
Date field)Zmatplotlib.backends.backend_qtr   r   r   r
   Z
FormWidgetsetupget)r   formZwidgetvaluesr   r   r   2test_form_widget_get_with_datetime_and_date_fields  s   
r   c                  C   s   g } dd dD D ]S\}}d }dd |D }t jdkr"t s"d}n|r-dd|}n|d	 d
kr;tjdr;d}g }|rO|	t
jjd| d| d | 	t
j||t|d q	| S )Nc                 S   s   g | ]
}|gd |dfqS )qtagg)
MPLBACKENDZQT_APIr   )rN   Zqt_apir   r   r   
<listcomp>3  s    z-_get_testable_qt_backends.<locals>.<listcomp>)ZPyQt6ZPySide6ZPyQt5ZPySide2c                 S   s   g | ]
}t j|s|qS r   )	importlibutil	find_spec)rN   depr   r   r   r   8  s    linuxz'$DISPLAY and $WAYLAND_DISPLAY are unsetz{} cannot be importedz, r   macosxZTF_BUILDzmacosx backend fails on Azurez	Skipping z	 because )reason)r)   id)rA   rB   r   Zdisplay_is_validformatjoinosenvironr   appendpytestmarkskipparamr   )Zenvsdepsenvr   missingr)   r   r   r   _get_testable_qt_backends1  s*   

r   c              
      s   ddl m} t  d   fdd}jd| ttj}dd }ttj| zLt	j
jj   |ks9J ttj|ksCJ tjtjfD ]$}jd| ttj| |   |kscJ ttj|ksmJ qIW ttj| d S ttj| w )Nr   )_BackendQT5c                      s   t t j j  d S r   )signal	getsignalSIGINTrW   exitr   Zevent_loop_handlerr   r   r   fire_signal_and_quitR  s   z6test_fig_sigint_override.<locals>.fire_signal_and_quitc                 S   rs   r   r   )signumframer   r   r   custom_handlera  s   z0test_fig_sigint_override.<locals>.custom_handler)Zmatplotlib.backends.backend_qt5r   r   r   ZQTimerZ
singleShotr   r   r   r   backendsZ
backend_qtZ
_BackendQTZmainloopSIG_DFLSIG_IGN)r   r   r   Zoriginal_handlerr   r   r   r   test_fig_sigint_overrideH  s(   	"r   c                  C   s"   ddl m}  | ddddd d S )Nr   ipython_in_subprocessZqtr   r   r(   ))      )r      )   r   )Zmatplotlib.testingr   r   r   r   r   test_ipython  s   r   ),r   r   r   r   rA   r   r   Zunittestr   r   r   r   r   Zmatplotlib._pylab_helpersr   r   r   r   r	   Zmatplotlib.backends.qt_editorr
   ImportErrorr   r   Z
pytestmarkZ_test_timeoutZfixturer   r'   r   Zparametrizer   rG   rq   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    





+	#
@

	





8