コード例 #1
0
def show_error_message_box(title, text, parent=None):
    """
    Shows an error message box that can be used to show critical text to users.

    :param str title: text that is displayed in the title bar of the dialog
    :param str text: default text which is placed n the plain text edit
    :param QWidget parent: optional parent widget for the input text dialog. If not given, current DCC main parent
        window will be used.
    """

    if not QT_AVAILABLE:
        return

    from artella import dcc
    from artella.core import resource

    parent = parent if parent else dcc.get_main_window()
    window_icon = resource.icon('artella')

    message_box = QtWidgets.QMessageBox(parent)
    message_box.setWindowTitle(title)
    message_box.setWindowIcon(window_icon)
    message_box.setIcon(message_box.Icon.Critical)
    flags = message_box.windowFlags() ^ QtCore.Qt.WindowContextHelpButtonHint | QtCore.Qt.WindowStaysOnTopHint
    if text:
        message_box.setText(text)
    message_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
    message_box.setWindowFlags(flags)
    message_box.exec_()
コード例 #2
0
def show_question_message_box(title, text, cancel=True, parent=None):
    """
    Shows a question message box that can be used to show question text to users.

    :param str title: text that is displayed in the title bar of the dialog
    :param str text: default text which is placed n the plain text edit
    :param bool cancel: Whether or not cancel button should appear in question message box
    :param QWidget parent: optional parent widget for the input text dialog. If not given, current DCC main parent
        window will be used.
    :return: True if the user presses the Ok button; False if the user presses the No button; None if the user preses
        the Cancel button
    :rtype: bool or None
    """

    if not QT_AVAILABLE:
        return None

    from artella import dcc

    parent = parent if parent else dcc.get_main_window()

    message_box = QtWidgets.QMessageBox(parent)
    message_box.setWindowTitle(title)
    flags = message_box.windowFlags() ^ QtCore.Qt.WindowContextHelpButtonHint | QtCore.Qt.WindowStaysOnTopHint
    if text:
        message_box.setText(text)
    if cancel:
        message_box.setStandardButtons(
            QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Cancel)
    else:
        message_box.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
    message_box.setWindowFlags(flags)
    result = message_box.exec_()

    if result == QtWidgets.QMessageBox.Yes:
        return True
    elif result == QtWidgets.QMessageBox.No:
        return False
    elif result == QtWidgets.QMessageBox.Cancel:
        return None