
    G8cR                     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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 	 d dlmZmZ d dlmZ d
Zej8                  d        Zej0                  j=                  dd      d        Z G d dej@                        Z!d Z"ej0                  j=                  dd      ej0                  jG                  ddddifdddifg      d               Z$d Z%ej0                  jM                  ejN                  dk(  d      ej0                  j=                  dd      ej0                  jG                  ddddifdddifg      d                      Z(ej0                  j=                  dd      d         Z)ej0                  jG                  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 d0d1fd2g dfd3g d4fd3d&gd5fgg d67      ej0                  jG                  d8 ejT                  dej0                  j=                  dd      9       ejT                  dej0                  j=                  dd      9      g      d:               Z+ej0                  j=                  dd      d;        Z,ej0                  j=                  dd      d<        Z-ej0                  j=                  dd      d=        Z.ej0                  j=                  dd      d>        Z/ej0                  j=                  dd      d?        Z0ej0                  j=                  dd      d@        Z1ej0                  j=                  dd      dA        Z2dB Z3dC Z4ej0                  jG                  dD e4             dE        Z5y# e$ r ej0                  j3                  d	      ZY Uw xY w)F    N)datedatetime)mock)pyplot)Gcf)_c_internal_utils)QtGui	QtWidgets)_formlayoutzNo usable Qt bindings<   c                 H    t        j                  d      }|j                  }|S )Nzmatplotlib.backends.qt_compat)pytestimportorskipQtCore)request	qt_compatr   s      B/usr/lib/python3/dist-packages/matplotlib/tests/test_backend_qt.pyqt_corer      s#    ##$CDIFM    QtAggT)skip_on_importerrorc                      t        j                   t        j                        } t        j                         }|j
                  j                  j                  j                          | t        j                  k(  sJ y N)	copyr   figspltfigurecanvasmanagerwindowclose)	init_figsfigs     r   test_fig_closer$   &   sU     		#((#I **,C JJ##%    r   c                   (     e Zd ZdZ fdZd Z xZS )WaitForStringPopenzL
    A Popen that passes flags that allow triggering KeyboardInterrupt.
    c                     t         j                  dk(  rt        j                  |d<   t	        |   |i |i t        j                  dddt        j                  dd y )Nwin32creationflagsAgg0)
MPLBACKENDSOURCE_DATE_EPOCHT)envstdoutuniversal_newlines)	sysplatform
subprocessCREATE_NEW_CONSOLEsuper__init__osenvironPIPE)selfargskwargs	__class__s      r   r6   zWaitForStringPopen.__init__=   s[    <<7"&0&C&CF?#	=	= N2::MUM??t		=r   c                     d}	 | j                   j                  d      }|st        d|      ||z  }|j                  |      ryC)z%Read until the terminator is reached.    z)Subprocess died before emitting expected N)r/   readRuntimeErrorendswith)r:   
terminatorbufcs       r   wait_forzWaitForStringPopen.wait_forF   sW      #A"?
~NP P1HC||J' r   )__name__
__module____qualname____doc__r6   rG   __classcell__)r=   s   @r   r&   r&   8   s    =
r   r&   c                   	
 dd l 
dd lm} dd l	dd l} |j
                  |        ddlm} 	
fd}t        ||      }|j                  d|       |j                         }|j                  j                  dd        |j                  j                  dfd       	  |di | y # t        $ r t        dd	
       Y y w xY w)Nr   r   c                      j                   dk(  rdd l} | j                  dd       y dd l} j                   j
                         |j                         y )Nr(   r   )r2   win32apiGenerateConsoleCtrlEventsignalkillgetpidSIGINT)rP   rR   r7   r1   s     r   interrupterz&_test_sigint_impl.<locals>.interrupter\   sA    <<7"--a3BGGIBIIK/r   r@   
draw_eventc                      t        dd      S NDRAWTflushprintr;   s    r   <lambda>z#_test_sigint_impl.<locals>.<lambda>i   s    eF$/ r   c                  $    j                         S r   start)r;   timers    r   r`   z#_test_sigint_impl.<locals>.<lambda>m   s    ekkm r   SUCCESSTr[    )r1   matplotlib.pyplotr   r7   	threadingswitch_backendmatplotlib.backends.qt_compatr   getattrTimerr   r   mpl_connectKeyboardInterruptr^   )backendtarget_namer<   r   rh   r   rV   targetr#   r7   r1   rd   s            @@@r   _test_sigint_implrr   S   s    #Cw40 S+&FOOA{+E
#**,CJJ/ JJ#% %it$%s    B) )CCztarget, kwargsshowblockpauseinterval
   c                 v   t        j                         }t        t        j                  dt        j                  t              d|d| d|dz   g      }	 |j                  d       |j                  t              \  }}t        |       d|v sJ y #  |j                          |j                         \  }} xY w)N-cz
_test_sigint_impl(, )rZ   timeoutre   )r   get_backendr&   r1   
executableinspect	getsourcerr   rG   communicate_test_timeoutrS   r^   rq   r<   ro   procr/   _s         r   test_sigintr   u   s     ooG				,	-{"VJb
!	D
E	FGDf$$]$;	
 
&M		$$&	s   *B &B8c                   	 dd l }dd lm}  |j                  |        ddlm} t        ||      } |j                         }|j                  j                  dd        |j                  j                  d      	d	_        	j                  t        dd	       	fd
} |j                   |j                  |       	  |di | y # t        $ r t        dd	       Y y w xY w)Nr   rN   rW   c                      t        dd      S rY   r]   r_   s    r   r`   z7_test_other_signal_before_sigint_impl.<locals>.<lambda>   s    vT)B r   r@   )rv   TSIGUSR1r[   c                 &    j                          y r   rb   )signumframerd   s     r   custom_signal_handlerzD_test_other_signal_before_sigint_impl.<locals>.custom_signal_handler   s    r   re   rf   )rR   rg   r   ri   rj   r   rk   r   r   rm   	new_timersingle_shotadd_callbackr^   r   rn   )
ro   rp   r<   rR   r   r   rq   r#   r   rd   s
            @r   %_test_other_signal_before_sigint_implr      s    #Cw4S+&F
#**,CJJ<BD JJ  ! ,EE	uit4FMM&.."78% %it$%s   <C CCr(   z,No other signal available to send on Windowsreasonc                 x   t        j                         }t        t        j                  dt        j                  t              d|d| d|dz   g      }	 |j                  d       t        j                  |j                  t        j                         |j                  d       t        j                  |j                  t        j                         |j                  t               \  }}t#        |       d|v sJ t        j$                          y #  |j                          |j                         \  }} xY w)	Nry   z'
_test_other_signal_before_sigint_impl(rz   r{   rZ   r   r|   re   )r   r~   r&   r1   r   r   r   r   rG   r7   rS   pidrR   r   rU   r   r   r^   r   r   s         r   test_other_signal_before_sigintr      s     ooG				@	A	3kF:Rz
4
4	56D
	f
&..)i 
&--($$]$;	
 
&MJJL		$$&	s   BD &D9Qt5Aggc                     ddl m} t        j                          d  fd} j                  j                  d|       t        j                  t        j                        }d }t        j                  t        j                  |       	 t        j                  j                  j                  j                          |k7  sJ t        j                  t        j                        |k(  sJ t        j                  t        j                  fD ]  } j                  j                  d|       t        j                  t        j                  |       |j                          |k(  sJ t        j                  t        j                        |k(  rJ  	 t        j                  t        j                  |       y # t        j                  t        j                  |       w xY w)Nr   )_BackendQT5c                      t        j                  t         j                         j                  j	                          y r   )rR   	getsignalrU   QCoreApplicationexit)event_loop_handlerr   s   r   fire_signal_and_quitz6test_fig_sigint_override.<locals>.fire_signal_and_quit   s.     $--fmm< 	  %%'r   c                      y r   rf   )r   r   s     r   custom_handlerz0test_fig_sigint_override.<locals>.custom_handler   s    r   )matplotlib.backends.backend_qt5r   r   r   QTimer
singleShotrR   r   rU   
matplotlibbackends
backend_qt
_BackendQTmainloopSIG_DFLSIG_IGN)r   r   r   original_handlerr   r   s   `    @r   test_fig_sigint_overrider      s^   ;JJL ( NNa!56 ''6 MM&--07 	&&11::< "^333 ..@@@  &~~v~~> 	ENNN%%a)=>MM&--8  "%777##FMM2nDDD	E 	fmm%56fmm%56s   DF7 F7 7&Gzqt_key, qt_mods, answerKey_AShiftModifierAaControlModifierzctrl+a
Key_Aacute   Á   áKey_ControlAltModifierzalt+controlKey_Altzctrl+alt)r   r   MetaModifieru   ctrl+alt+meta+áKey_PlayKey_Backspace	backspacezctrl+backspace)shiftlowercontrolunicode_upperunicode_loweralt_controlcontrol_altmodifier_ordernon_unicode_keyr   backspace_mod)idsro   )marksc                   	
 ddl m	m
 t        j                  dk(  r8|6|j                  dd      }|j                  dd      }|j                  dd      }d 	d	      j                  |D ]  }t         	d	      |      z    G 	
fd
d      }fd}t        j                         j                  }|j                  d|       |j                   |              |k(  sJ y)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   _enum_to_intdarwinNctrlcmdr   metaQtCore.Qt.KeyboardModifierc                   ,    e Zd Zd Z fdZfdZy) test_correct_key.<locals>._Eventc                      y)NFrf   )r:   s    r   isAutoRepeatz-test_correct_key.<locals>._Event.isAutoRepeatB  s    ur   c                 4     t         d                  S )NQtCore.Qt.Key)rk   )r:   r   r   qt_keys    r   keyz$test_correct_key.<locals>._Event.keyC  s    ggeO.Df&MNNr   c                     S r   rf   )r:   qt_mods    r   	modifiersz*test_correct_key.<locals>._Event.modifiersD  s    F]r   N)rH   rI   rJ   r   r   r   )r   r   r   r   s   r   _Eventr   A  s    ,N*r   r   c                     | j                   y r   )r   )eventresults    r   on_key_pressz&test_correct_key.<locals>.on_key_pressF  s    r   key_press_event)rj   r   r   r1   r2   replace
NoModifierrk   r   r   r   rm   keyPressEvent)ro   r   r   qt_modsanswermodr   r   	qt_canvasr   r   r   r   s     `      @@@@r   test_correct_keyr      s    v =
||xF$6.	51/F/0;;F D'% <=sCCD+ +
 

##I+\:FH%Vr   c                     d} t        j                  |       5 d_        t        j                  dd      }|j
                  j                          fd}j                  j                          j                         }j                         j                         j                          |d       |j                  dk(  sJ j                  j                  dk(  sJ j                  j                  d	k(  sJ |j                         d
k(  sJ |j                         dk(  sJ j!                         dk(  sJ |j#                         dk(  j%                         sJ  |d       |j                  dk(  sJ j                  j                  dk(  sJ j                  j                  dk(  sJ |j                         d
k(  sJ |j                         dk(  sJ j!                         dk(  sJ |j#                         dk(  j%                         sJ  |d       |j                  dk(  sJ j                  j                  dk(  sJ j                  j                  dk(  sJ |j                         d
k(  sJ |j                         dk(  sJ j!                         dk(  sJ |j#                         dk(  j%                         sJ 	 ddd       y# 1 sw Y   yxY w)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   )figsizedpic                     | _         j                  j                  d       j                          j	                          j
                  | k(  sJ y )N`   )return_valuelogicalDotsPerInchChangedemitdrawflush_eventsdevice_pixel_ratio)ratiopr   screens    r   set_device_pixel_ratioz>test_device_pixel_ratio_change.<locals>.set_device_pixel_ratio_  sL    "AN ,,11"5NN""$ //5888r   ih  i  i  X     )r   r   r   i  i  g      ?   i  N)r   patchr   r   r   r   rs   r   sizer    windowHandler   r   rendererwidthheightget_width_heightget_size_inchesall)propr#   r   r  r   r   r   s       @@@r   test_device_pixel_ratio_changer  P  s    MD	D	 >7QjjS1JJ		9 	 ~~!!#00299;q! ww#~~!!''4///!!((C/// zz|s"""{{}###))+z999##%/44666q! ww#~~!!''4///!!((C/// zz|s"""{{}###))+z999##%/44666s# ww#~~!!''3...!!((C/// zz|s"""{{}###))+z999##%/44666}>7 >7 >7s   J+KKc                      t        j                         \  } }t        j                  dd       5  | j                  j
                  j                  j                          d d d        y # 1 sw Y   y xY w)N#matplotlib.backends.qt_compat._execc                      y r   rf   objs    r   r`   z"test_subplottool.<locals>.<lambda>      r   )r   subplotsr   r  r   r   toolbarconfigure_subplotsr#   axs     r   test_subplottoolr    sR    llnGC	9;K	L 8

""5578 8 8s   /A''A0c                     t        j                         \  } }|j                  ddg       |j                  dgg       |j	                  t        d      t        d      t        d             t        j                  dd       5  | j                  j                  j                  j                          d d d        y # 1 sw Y   y xY w)Nr@   r   r   )rF   r  c                      y r   rf   r  s    r   r`   z$test_figureoptions.<locals>.<lambda>  r  r   )r   r  plotimshowscatterranger   r  r   r   r  edit_parametersr  s     r   test_figureoptionsr     s    llnGCGGQFOIIseJJuQxqU1XJ.	9;K	L 5

""2245 5 5s   /B<<Cc                  B   t        j                         \  } }t        ddd      t        ddd      g}|j                  ||       t	        j
                  dd       5  | j                  j                  j                  j                          d d d        y # 1 sw Y   y xY w)N  r@   yearmonthdayr   r  c                      y r   rf   r  s    r   r`   z7test_figureoptions_with_datetime_axes.<locals>.<lambda>  r  r   )
r   r  r   r  r   r  r   r   r  r  )r#   r  xydatas      r   %test_figureoptions_with_datetime_axesr)    s    llnGCd!+d!+F GGFF	9;K	L 5

""2245 5 5s   /BBc                  X   t        j                         \  } }| j                  j                          | j                  j                  j
                  }d\  }}| j                  ||       | j                  j                         |t        j                  d   z  k(  sJ | j                  j                         |t        j                  d   z  k(  sJ |j                         }|j                         }| j                  ||       |j                         |k(  sJ |j                         |k(  sJ y )N)r   r   z
figure.dpi)r   r  r   r   r   r    set_size_inchesr  r   rcParamsr  )r#   r  r    wh	old_width
old_heights          r   test_double_resizer1    s     llnGCJJOOZZ&&FDAq1::Z%8%8%F!FFFF::!j&9&9,&G"GGGGIJ1<<>Y&&&==?j(((r   c                      ddl m}  dfd}t        j                         \  }}||_         | |      }d|_        sJ y )Nr   )FigureCanvasQTAggFc                 >    | j                   j                          dy )NT)r   	draw_idle)r#   stalecalleds     r   crashing_callbackz-test_canvas_reinit.<locals>.crashing_callback  s    

r   T)!matplotlib.backends.backend_qtaggr3  r   r  stale_callbackr6  )r3  r8  r#   r  r   r7  s        @r   test_canvas_reinitr;    sA    CF
 llnGC*Cs#FCIM6r   c                  
   ddl m}   |         dt        ddd      fdt        ddd      fg}t	        j
                  |      }|j                          |j                         }|t        ddd      t        ddd      gk(  sJ y )	Nr   )_create_qAppzDatetime fieldr"  r      r#  z
Date field)matplotlib.backends.backend_qtr=  r   r   r   
FormWidgetsetupget)r=  formwidgetvaluess       r   2test_form_widget_get_with_datetime_and_date_fieldsrF    s    ;N 
8QB?@	tQB78D ##D)F
LLNZZ\Fd!,$aR(   r   c                     dd l } ddlm}m} ddlm}m}  |d      j                    |d      j                    |d      j                    |d      j                   dD ]  }t         |d      |         |d      j                    |d      j                   g dd	d
ddddddddddddddddd| j                  dk7  rdndfd| j                  dk7  rd ndfd!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0D ci c]  \  }} |t         |d1      |            |  }}}d2D 	
cg c]5  \  }	}
 |t         |d3      |	             |t         |d1      |
            f7 }}	}
|j                  d4f|j                  d5f|j                   d6f|j"                  d7f|j$                  d8ffD ci c]  \  }}|t         |d9      |       }}}d:|j&                  fd;|j(                  fd<|j*                  fd=|j,                  fd>|j.                  ffD ci c]  \  }}t         |d?      |      | }}} |d@      j0                    |dA      j2                    |dB      j4                    |dB      j4                    |dC      j6                    |dC      j8                    |dD      j:                    |dD      j<                    |dE      j>                    |dB      j4                    |dB      j4                    |dC      j6                    |dC      j8                    |dD      j:                    |dD      j<                   y c c}}w c c}
}	w c c}}w c c}}w )FNr   r   )cursorsMouseButtonzQtGui.QDoubleValidator.Statez)QtWidgets.QDialogButtonBox.StandardButton)OkCancelzQtGui.QImage.Format)
Key_Escapeescape)Key_Tabtab)r   r   )
Key_Returnenter)	Key_EnterrQ  )
Key_Insertinsert)
Key_Deletedelete)	Key_Pauseru   )
Key_SysReqsysreq)	Key_Clearclear)Key_Homehome)Key_Endend)Key_Leftleft)Key_Upup)	Key_Rightright)Key_Downdown)
Key_PageUppageup)Key_PageDownpagedown)	Key_Shiftr   r   r   r   r   Key_Metar   )r   alt)Key_CapsLock	caps_lock)Key_F1f1)Key_F2f2)Key_F3f3)Key_F4f4)Key_F5f5)Key_F6f6)Key_F7f7)Key_F8f8)Key_F9f9)Key_F10f10)r  f11)Key_F12f12)Key_Super_Lr5   )Key_Super_Rr5   r   ))r   r   )r   r   )r   rl  )r   rm  r   SizeAllCursorPointingHandCursorArrowCursorCrossCursor
WaitCursorzQtCore.Qt.CursorShape
LeftButtonRightButtonMiddleButtonXButton1XButton2zQtCore.Qt.MouseButtonzQtCore.Qt.WidgetAttributezQtCore.Qt.FocusPolicyzQtCore.Qt.ToolBarAreazQtCore.Qt.AlignmentFlagzQtWidgets.QSizePolicy.PolicyzQtCore.Qt.MaskMode) r1   rj   r   r   matplotlib.backend_basesrH  rI  
AcceptablerJ  rK  Applyrk   Format_ARGB32_Premultipliedr2   MOVEHANDPOINTERSELECT_REGIONWAITLEFTRIGHTMIDDLEBACKFORWARDWA_OpaquePaintEventStrongFocusTopToolBarArea
AlignRightAlignVCenter	ExpandingIgnoredMaskOutColor)r1   r   r   rH  rI  btn_typekvSPECIAL_KEYSr   r   _MODIFIER_KEYScursordbuttonds                 r   _test_enums_implr    s   <=	
()44	
5699	
56==	
56<<$ NABHMN 

 <<	
 <<
'
$'
'
 +'
 $	'

 #'
 %'
 %'
 #'
 %'
 #'
 !'
 '
 !'
 '
 #'
  !!'
" %#'
$ )%'
& #''
* )AIuM+'
, 3<<8#;K-'
. /'
0 *1'
2 3'
4 5'
6 7'
8 9'
: ;'
< ='
> ?'
@ A'
B C'
D E'
F G'
H I'
J %K'
L %M'
*Aq 	o.23Q6*L *f

 C GE">?EFGE/2C89	
N  \\?+\\/0__m,""M2\\<(
	Aq 	
7501155	G 	 ;++,K--.[//0))*,,-
	Aq 	-.2A5	G 	 

%&::	
!"..	
!"11	
!"11	
#$//	
#$11	
()33	
()11	
,,	
!"11	
!"11	
#$//	
#$11	
()33	
()11}*\		s   #M;:M>M$M%c            
      ~   g } dD cg c]
  }|gd|df c}D ]  \  }}d }|D cg c]$  }t         j                  j                  |      r#|& }}t        j                  dk(  rt        j                         sd}nL|r!dj                  dj                  |            }n)|d   d	k(  r!t        j                  j                  d
      rd}g }|r5|j                  t        j                  j                  d| d|              | j                  t        j                   ||t#        |                    | S c c}w c c}w )N)PyQt6PySide6PyQt5PySide2qtagg)r,   QT_APIlinuxz'$DISPLAY and $WAYLAND_DISPLAY are unsetz{} cannot be importedrz   r,   macosxTF_BUILDzmacosx backend fails on Azurez	Skipping z	 because r   )r   id)	importlibutil	find_specr1   r2   r   display_is_validformatjoinr7   r8   rB  appendr   markskipparamstr)envsqt_apidepsr.   r   depmissingr   s           r   _get_testable_qt_backendsr  d  s,   D C Xg@A A	c "&L3inn.F.Fs.K3LLLLG#%668>F,33DIIg4FGF(*rzz~~j/I4FLL))"3%y9 * ; <FLLEc#h?@#A$ K%
 Ms   D5$D:D:r.   c                     t        j                  t        j                  dt	        j
                  t              dz   gi t        j                  ddi| t        dt         j                  d      }y )Nry   z
_test_enums_impl()r-   r+   T)r.   r}   checkr/   r0   )r3   runr1   r   r   r   r  r7   r8   r   r9   )r.   r   s     r   test_enums_availabler  {  s[    >>				+	,/E	E	G;rzz;.;s;T49Dr   )6r   r  r   r7   rR   r3   r1   r   r   unittestr   r   r   r   r   matplotlib._pylab_helpersr   r   rj   r	   r
   matplotlib.backends.qt_editorr   ImportErrorr  r  
pytestmarkr   fixturer   ro   r$   Popenr&   rr   parametrizer   r   skipifr2   r   r   r  r   r  r  r   r)  r1  r;  rF  r  r  r  rf   r   r   <module>r     si      	   
 #    $ ) (;>9
    W$7! 8!")) 6%D W$7)gt_z2, 	 8
"%4 CLLG+I  KW$7)gt_z2, 	 8K, X4857 957p 	?#S)	"c	$%23	

 
r@A	-9	&'4>@	
 
R	"k*	
+6	;  *V FLLkk!!(!EG FLLkk!!'t!DF% W*hB W$7E7 8E7P W$78 88 W$75 85 W$75 85 W$7) 8)& W$7 8$ X48 9&p2f.  9 ;<9 =9K  ;!!"9:J;s   N  N*)N*