@contextmanager
def process_dialog(delay=0, accept=False, reject=False, function=None):
    """
    Context manager to automatically capture the active dialog and carry out
    certain actions.

    Note that only one of ``accept``, ``reject``, or ``function`` should be
    specified.

    Parameters
    ----------
    delay : int, optional
        The delay in ms before acting on the dialog (since it may not yet exist
        when the context manager is called).
    accept : bool, optional
        If `True`, accept the dialog after the specified delay.
    reject : bool, optional
        If `False`, reject the dialog after the specified delay
    function : func, optional
        For more complex user actions, specify a function that takes the dialog
        as the first and only argument.
    """

    def _accept(dialog):
        dialog.accept()

    def _reject(dialog):
        dialog.reject()

    n_args = sum((accept, reject, function is not None))

    if n_args > 1:
        raise ValueError("Only one of ``accept``, ``reject``, or "
                         "``function`` should be specified")
    elif n_args == 0:
        raise ValueError("One of ``accept``, ``reject``, or "
                         "``function`` should be specified")

    if accept:
        function = _accept
    elif reject:
        function = _reject

    def wrapper():
        from glue.external.qt import get_qapp
        app = get_qapp()
        dialog = app.focusWidget().window()
        function(dialog)

    timer = QtCore.QTimer()
    timer.setInterval(delay)
    timer.setSingleShot(True)
    timer.timeout.connect(wrapper)
    timer.start()

    yield
dataset/ETHPy150Open glue-viz/glue/glue/utils/qt/helpers.py/process_dialog/original