o
    tfc&                     @   s  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d Zd	d
 Zdd Zdd Zdd ZejjejdkoZejdd dkdddd Zejjejdkorejdd dkdddd Zejjejdkoejdd dkdddd Zejjejdkoejdd dkdddd Z ejje	oe!dddd d! Z"d"d# Z#ejjejdkoejdd dkoe	ped$dej$d%d&d'gej$d(d)d*gd+d, Z%d-d. Z&dS )/zTest QtWidgets.    N)sleep)TimeoutError)PYQT5PYQT6PYQT_VERSIONPYSIDE2PYSIDE6QtCoreQtGui	QtWidgets)not_using_condausing_condac                 C   j   t jjsJ t jjsJ t jjsJ t d}|d | dks$J |\}}|| | s3J dS )z/Test functions mapping for QtWidgets.QTextEdit.NZ   )r   Z	QTextEditsetTabStopWidthtabStopWidthprint_exists)qtbot
pdf_writerZtextedit_widgetprint_deviceoutput_path r   b/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/qtpy/tests/test_qtwidgets.pytest_qtextedit_functions      


r   c                   C   s   t jjsJ dS )z.Test functions mapping for QtWidgets.QLineEditN)r   Z	QLineEditZgetTextMarginsr   r   r   r   test_qlineedit_functions#   s   r   c                   C   sJ   t jdusJ t jdusJ t jdusJ t jdusJ t jdus#J dS )z:Test that we move back what has been moved to QtGui in Qt6N)r   ZQActionZQActionGroupZQFileSystemModelZ	QShortcutZQUndoCommandr   r   r   r   test_what_moved_to_qtgui_in_qt6(   s
   r   c                 C   r   )z4Test functions mapping for QtWidgets.QPlainTextEdit.Nr   )r   ZQPlainTextEditr   r   r   r   )r   r   Zplaintextedit_widgetr   r   r   r   r   test_qplaintextedit_functions1   r   r   c                  C   s   t jjdusJ t j pt tjtg} | dusJ tj	dt j j
 t j  t j p7t tjtg} | dus>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)appr   r   r   test_QApplication_exec_>   s   
r*   darwin   )      z"Stalls on macOS CI with Python 3.7)reasonc                 C   s2   t jjsJ t d}tjd|j |  dS )z-Test functions mapping for QtWidgets.QDialog.Nr   r   ZQDialogr!   r	   r&   r'   accept)r   dialogr   r   r   test_qdialog_functionsO   s   
r3   c                 C   sJ   t jjsJ G dd dt j}|jsJ | }tjd|j |  dS )zBTest functions mapping for QtWidgets.QDialog when using a subclassc                       s   e Zd Z fddZ  ZS )z+test_qdialog_subclass.<locals>.CustomDialogc                    s   t  d  | d d S )NZTesting)super__init__ZsetWindowTitle)self	__class__r   r   r5   d   s   z4test_qdialog_subclass.<locals>.CustomDialog.__init__)__name__
__module____qualname__r5   __classcell__r   r   r7   r   CustomDialogc   s    r=   r   Nr0   )r   r=   r2   r   r   r   test_qdialog_subclass[   s   
r>   c                    s   t  }t |}|d |dtjj |t dtjj |   	|- t
jd|j |  t
jd fdd t j| t
dd W d   dS 1 sZw   Y  dS )	z-Test functions mapping for `QtWidgets.QMenu`.ZQtPyQtPy with a shortcut QtPy with an icon and a shortcutr   c                      s     tjddtjjS )N   )keyClickr   r    ZwidgetAtr	   QtZ
Key_Escaper   r   r   r   <lambda>   s    z&test_QMenu_functions.<locals>.<lambda>rA   N)r   ZQMainWindowZQMenu	addActionr
   QKeySequence
UnknownKeyQIconshowZwaitExposedr	   r&   r'   closer!   actionsZQPoint)r   ZwindowZmenur   rD   r   test_QMenu_functionsn   s&   


"rM   c                 C   s2   t  }|dtjj |t dtjj dS )zLTest `QtWidgets.QToolBar.addAction` compatibility with Qt6 arguments' order.r?   r@   N)r   ZQToolBarrF   r
   rG   rH   rI   )r   Ztoolbarr   r   r   test_QToolBar_functions   s   rN   z5.9zaA specific setup with at least sip 4.9.9 is needed for PyQt5 5.9.*to work with scoped enum accessc                   C   sr   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s7J dS )z:Test scoped and unscoped enum access for qtpy.QtWidgets.*.N)r   QFileDialogZ
AcceptOpenZ
AcceptModeZQMessageBoxZInvalidRoleZ
ButtonRoleZQStyleZ
State_NoneZ	StateFlagZQSliderZ	TicksLeftZTickPositionZ
TicksAboveZSC_SliderGrooveZ
SubControlr   r   r   r   test_enum_access   s   rP   c                   C   s   t jdus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   ZQOpenGLWidgetr   r   r   r   test_opengl_imports   s   rQ   z>Crashes on macOS with Python 3.7 with 'Illegal instruction: 4'keyworddir	directoryr"   TFc           	         s   G  fdddt j}ztjjj}W n ty   tjj}Y nw dd|t| d|i}| }|   j	|j
dd |r?t ntj}|jd
i |  j	|jd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                       s   e Zd ZdZd fdd	ZdS )z0test_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                    s   t d |}tj }| D ]}t|tjr| rq |t	j
j d}qt d | D ]}t|tjr;| r<q/| jdd  d S |rM|   d S d S )Ng      ?Fg?)allow_restart)r   r   r    r"   ZtopLevelWidgets
isinstancerO   ZisHiddenrB   r	   rC   Z	Key_Enterrun)r6   rU   Zneed_restartr)   dlgrD   r   r   rW      s.   


z4test_qfiledialog_dir_compat.<locals>.CloseThread.runN)T)r9   r:   r;   __doc__rW   r   rD   r   r   CloseThread   s    	rZ   captionzSelect a directoryoptionsi  )timeouti  Nr   )r	   ZQThreadr   rO   OptionZDontUseNativeDialogAttributeErrorstrstartZ	waitUntilZ	isRunningZgetExistingDirectoryZ
isFinished)	Ztmp_pathr   rR   r"   rZ   optkwargsZthrrX   r   rD   r   test_qfiledialog_dir_compat   s    .rd   c                   C   s.   t jjdus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   rO   Optionsr^   r   r   r   r   test_qfiledialog_flags_typedef  s   rf   )'rY   
contextlibr#   timer   ZpytestZpytestqt.exceptionsr   Zqtpyr   r   r   r   r   r	   r
   r   Zqtpy.tests.utilsr   r   r   r   r   r   r*   markZskipifplatformversion_infor3   r>   rM   rN   
startswithrP   rQ   Zparametrizerd   rf   r   r   r   r   <module>   sd    (
	






S