Ejemplo n.º 1
0
def showMessageBox(parent,
                   title,
                   text,
                   width=None,
                   height=None,
                   buttons=None,
                   headerIcon=None,
                   headerColor=None,
                   enableDontShowCheckBox=False,
                   force=False):
    """
    Open a question message box with the given options.

    :type parent: QWidget
    :type title: str
    :type text: str
    :type buttons: list[QMessageBox.StandardButton]
    :type headerIcon: str
    :type headerColor: str
    :type enableDontShowCheckBox: bool
    :type force: bool

    :rtype: MessageBox
    """
    key = '{0}MessageBox'.format(title.replace(" ", ""))
    data = settings.get(key, {})

    clickedButton = data.get("clickedButton", -1)
    dontShowAgain = data.get("dontShowAgain", False)

    # Force show the dialog if the user is holding the ctrl key down
    if studioqt.isControlModifier() or studioqt.isAltModifier():
        force = True

    if force or not dontShowAgain or not enableDontShowCheckBox:

        mb = createMessageBox(parent,
                              title,
                              text,
                              width=width,
                              height=height,
                              buttons=buttons,
                              headerIcon=headerIcon,
                              headerColor=headerColor,
                              enableDontShowCheckBox=enableDontShowCheckBox)

        mb.exec_()
        mb.close()

        clickedButton = mb.clickedStandardButton()
        if clickedButton != QtWidgets.QDialogButtonBox.Cancel:

            # Save the button that was clicked by the user
            settings.set(
                key, {
                    "clickedButton": int(clickedButton),
                    "dontShowAgain": bool(mb.isDontShowCheckboxChecked()),
                })

    return clickedButton
Ejemplo n.º 2
0
def showMessageBox(parent,
                   title,
                   text,
                   width=None,
                   height=None,
                   buttons=None,
                   headerIcon=None,
                   headerColor=None,
                   enableDontShowCheckBox=False,
                   force=False):
    """
    Open a question message box with the given options.

    :type parent: QWidget
    :type title: str
    :type text: str
    :type buttons: list[QMessageBox.StandardButton]
    :type headerIcon: str
    :type headerColor: str
    :type enableDontShowCheckBox: bool
    :type force: bool

    :rtype: MessageBox
    """
    settings = QtCore.QSettings(SETTINGS_PATH, QtCore.QSettings.IniFormat)

    key = 'MessageBox/{}/'.format(title.replace(" ", "_"))

    clickedButton = int(settings.value(key + "clickedButton") or -1)
    dontShowAgain = settings.value(key + "dontShowAgain")

    if isinstance(dontShowAgain, basestring):
        dontShowAgain = dontShowAgain == "true"

    # Force show the dialog if the user is holding the ctrl key down
    if studioqt.isControlModifier() or studioqt.isAltModifier():
        force = True

    if force or not dontShowAgain or not enableDontShowCheckBox:

        mb = createMessageBox(parent,
                              title,
                              text,
                              width=width,
                              height=height,
                              buttons=buttons,
                              headerIcon=headerIcon,
                              headerColor=headerColor,
                              enableDontShowCheckBox=enableDontShowCheckBox)

        mb.exec_()
        mb.close()

        # Save the button that was clicked by the user
        clickedButton = mb.clickedStandardButton()
        settings.setValue(key + "clickedButton", clickedButton)

        # Save the dont show again checked state
        dontShowAgain = mb.isDontShowCheckboxChecked()
        settings.setValue(key + "dontShowAgain", dontShowAgain)

        settings.sync()

    return clickedButton