
    q'Vec&                     $   d 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	m
Z
mZmZmZmZmZmZ ddlmZmZ d Zd Zd	 Zd
 Zd Zej                            ej        dk    oej        dd         dk    d          d             Zej                            ej        dk    oej        dd         dk    d          d             Zej                            ej        dk    oej        dd         dk    d          d             Zej                            ej        dk    oej        dd         dk    d          d             Z ej                            e	o ej!        d          d          d             Z"d Z#ej                            ej        dk    oej        dd         dk    oe	ped          ej        $                    dddg          ej        $                    dddg          d                                      Z%d! Z&dS )"zTest QtWidgets.    N)sleep)TimeoutError)PYQT5PYQT6PYQT_VERSIONPYSIDE2PYSIDE6QtCoreQtGui	QtWidgets)not_using_condausing_condac                 ^   t           j        j        sJ t           j        j        sJ t           j        j        sJ t          j        d          }|                    d           |                                dk    sJ |\  }}|                    |           |                                sJ dS )z/Test functions mapping for QtWidgets.QTextEdit.NZ   )r   	QTextEditsetTabStopWidthtabStopWidthprint_exists)qtbot
pdf_writertextedit_widgetprint_deviceoutput_paths        9lib/python3.11/site-packages/qtpy/tests/test_qtwidgets.pytest_qtextedit_functionsr      s    ....++++%%%%)$//O##B'''''))R//// *L+<(((    c                  ,    t           j        j        sJ dS )z.Test functions mapping for QtWidgets.QLineEditN)r   	QLineEditgetTextMargins r   r   test_qlineedit_functionsr"   #   s    ------r   c                      t           j        J t           j        J t           j        J t           j        J t           j        J dS )z:Test that we move back what has been moved to QtGui in Qt6N)r   QActionQActionGroupQFileSystemModel	QShortcutQUndoCommandr!   r   r   test_what_moved_to_qtgui_in_qt6r)   (   sS    (((!---%111***!-----r   c                 ^   t           j        j        sJ t           j        j        sJ t           j        j        sJ t          j        d          }|                    d           |                                dk    sJ |\  }}|                    |           |                                sJ dS )z4Test functions mapping for QtWidgets.QPlainTextEdit.Nr   )r   QPlainTextEditr   r   r   r   )r   r   plaintextedit_widgetr   r   s        r   test_qplaintextedit_functionsr-   1   s    #3333#0000#****$3D99((,,,,,.."4444 *L+---r   c                     t           j        j        J t           j                                        p$t          j        t          j        t          g          } | J t          j        	                    dt           j                                        j
                   t           j                                         t           j                                        p$t          j        t          j        t          g          } | J t          j        	                    dt           j                                        j
                   |                                  dS )z#Test `QtWidgets.QApplication.exec_`Nd   )r   QApplicationexec_instancesys
executable__file__r
   QTimer
singleShotquit)apps    r   test_QApplication_exec_r:   >   s   !'333

 
)
)
+
+ y/E	"0 0C ???
MS)"8"A"A"C"C"HIII  """

 
)
)
+
+ y/E	"0 0C ???
MS)"8"A"A"C"C"HIIIIIKKKKKr   darwin   )      z"Stalls on macOS CI with Python 3.7)reasonc                     t           j        j        sJ t          j        d          }t          j                            d|j                   |                                 dS )z-Test functions mapping for QtWidgets.QDialog.Nr/   r   QDialogr1   r
   r6   r7   accept)r   dialogs     r   test_qdialog_functionsrE   O   sQ     """"t$$F
MS&-000
LLNNNNNr   c                     t           j        j        sJ  G d dt           j                  }|j        sJ  |            }t          j                            d|j                   |                                 dS )zBTest functions mapping for QtWidgets.QDialog when using a subclassc                        e Zd Z fdZ xZS )+test_qdialog_subclass.<locals>.CustomDialogc                 t    t                                          d            |                     d           d S )NTesting)super__init__setWindowTitle)self	__class__s    r   rL   z4test_qdialog_subclass.<locals>.CustomDialog.__init__d   s5    GGT"""	*****r   )__name__
__module____qualname__rL   __classcell__)rO   s   @r   CustomDialogrH   c   s8        	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+r   rT   r/   NrA   )r   rT   rD   s      r   test_qdialog_subclassrU   [   s     """"+ + + + +y( + + +
 \^^F
MS&-000
LLNNNNNr   c                     t          j                    }t          j        |          }|                    d           |                    dt          j        j                   |                    t	          j                    dt          j        j                   |                                  	                    |          5  t          j                            d|j                   |                                 t          j                            d fd           t           j                            |                                t          j        dd                     ddd           dS # 1 swxY w Y   dS )z-Test functions mapping for `QtWidgets.QMenu`.QtPyQtPy with a shortcut QtPy with an icon and a shortcutr/   c                                            t          j                            dd          t          j        j                  S )N   )keyClickr   r0   widgetAtr
   Qt
Key_Escaper   s   r   <lambda>z&test_QMenu_functions.<locals>.<lambda>   s3    ENN&//155	$  r   r[   N)r   QMainWindowQMenu	addActionr   QKeySequence
UnknownKeyQIconshowwaitExposedr
   r6   r7   closer1   actionsQPoint)r   windowmenus   `  r   test_QMenu_functionsro   n   s    "$$F?6""DNN6NN)5+=+HIIINN*%  
 KKMMM			6	"	" C C  dj111

 	     	
 	
 	
 	dllnnfmAq.A.ABBBC C C C C C C C C C C C C C C C C Cs   B"E22E69E6c                     t          j                    }|                    dt          j        j                   |                    t          j                    dt          j        j                   dS )zLTest `QtWidgets.QToolBar.addAction` compatibility with Qt6 arguments' order.rX   rY   N)r   QToolBarrd   r   re   rf   rg   )r   toolbars     r   test_QToolBar_functionsrs      sf      ""G,e.@.KLLL*%    r   z5.9zaA specific setup with at least sip 4.9.9 is needed for PyQt5 5.9.*to work with scoped enum accessc                     t           j        j        t           j        j        j        k    sJ t           j        j        t           j        j        j        k    sJ t           j        j        t           j        j	        j        k    sJ t           j
        j        t           j
        j        j        k    sJ t           j        j        t           j        j        j        k    sJ dS )z:Test scoped and unscoped enum access for qtpy.QtWidgets.*.N)r   QFileDialog
AcceptOpen
AcceptModeQMessageBoxInvalidRole
ButtonRoleQStyle
State_None	StateFlagQSlider	TicksLeftTickPosition
TicksAboveSC_SliderGroove
SubControlr!   r   r   test_enum_accessr      s     	( +6	7 	7 	7 	7 	) +7	8 	8 	8 	8 &)*:*D*OOOOO#)4	5 	5 	5 	5 	(&6	7 	7 	7 	7 	7 	7r   c                  "    t           j        J dS )z
    Test for presence of QOpenGLWidget.

    QOpenGLWidget was a member of QtWidgets in Qt5, but moved to QtOpenGLWidgets in Qt6.
    QtPy makes QOpenGLWidget available in QtWidgets to maintain compatibility.
    N)r   QOpenGLWidgetr!   r   r   test_opengl_importsr      s     ".....r   z>Crashes on macOS with Python 3.7 with 'Illegal instruction: 4'keyworddir	directoryr2   TFc                     G fddt           j                  }	 t          j        j        j        }n!# t          $ r t          j        j        }Y nw xY wdd|t          |           d|i} |            }|                                 	                    |j
        d           |rt          j                    nt          j        } |j        d
i | 	                    |j        d           d	S )a!  
    This function is testing if the decorators that renamed the dir/directory
    keyword are working.

    It may stop working if the Qt bindings do some overwriting of the methods
    in constructor. It should not happen, but the PySide team
    did similar things in the past (like overwriting enum module in
    PySide6==6.3.2).

    keyword: str
        The keyword that should be used in the function call.
    instance: bool
        If True, the function is called on the instance of the QFileDialog,
        otherwise on the class.
    c                        e Zd ZdZd fd	ZdS )0test_qfiledialog_dir_compat.<locals>.CloseThreadaI  
        On some implementations the `getExistingDirectory` functions starts own
        event loop that will not trigger QTimer started before the call. Until
        the dialog is closed the main event loop will be stopped.

        Because of this it is required to use the thread to interact with the
        dialog.
        Tc                 J   t          d           |}t          j                                        }|                                D ]X}t          |t          j                  r|                                r1                    |t          j
        j                   d}Yt          d           |                                D ]I}t          |t          j                  r|                                r1|                     d            d S |r|                                  d S d S )Ng      ?Fg?)allow_restart)r   r   r0   r2   topLevelWidgets
isinstanceru   isHiddenr\   r
   r^   	Key_Enterrun)rN   r   need_restartr9   dlgr   s        r   r   z4test_qfiledialog_dir_compat.<locals>.CloseThread.run   s   #JJJ(L(1133C**,, % %"3	(=>>||~~  sFI$7888$#JJJ**,, 	 	 #3	(=>>||~~ u--- 




 r   N)T)rP   rQ   rR   __doc__r   r`   s   r   CloseThreadr      s=        	 	 	  	  	  	  	  	  	  	r   r   captionzSelect a directoryoptionsi  )timeouti  Nr!   )r
   QThreadr   ru   OptionDontUseNativeDialogAttributeErrorstrstart	waitUntil	isRunninggetExistingDirectory
isFinished)	tmp_pathr   r   r2   r   optkwargsthrr   s	    `       r   test_qfiledialog_dir_compatr      s   2* * * * * * *fn * * *\8#*> 8 8 8#78
 	'X3F +--CIIKKK	OOCM4O000%-
H)

!
!
!93HCC&&v&&&	OOCNDO11111s   4 AAc                      t           j        j        J t           j                                        t           j                            d          k    sJ dS )zZ
    Test existence of `QFlags<Option>` typedef `Options` that was removed from PyQt6
    Nr   )r   ru   Optionsr   r!   r   r   test_qfiledialog_flags_typedefr     sM      (444 ((**i.C.J.J1.M.MMMMMMMr   )'r   
contextlibr3   timer   pytestpytestqt.exceptionsr   qtpyr   r   r   r   r	   r
   r   r   qtpy.tests.utilsr   r   r   r"   r)   r-   r:   markskipifplatformversion_inforE   rU   ro   rs   
startswithr   r   parametrizer   r   r!   r   r   <module>r      s         



        , , , , , ,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 : 9 9 9 9 9 9 9
  
  
 . . .
. . .
  
  
   " LH?!1"1"!5!?/    	  LH?!1"1"!5!?/    	  LH?!1"1"!5!?/   C C	 C< LH?!1"1"!5!?/    	  	,%l%e,,&   
  
*/ / / LH !&		'K	    UK$899dE]33P2 P2 43 :9 P2fN N N N Nr   