Ejemplo n.º 1
0
def get_save_permission(message,
                        file_path=None,
                        title='Permission',
                        parent=None):
    """
    Shows a save path message box
    :param message: str, message to show to the user
    :param file_path: str, path you want to save
    :param title: str, title of the window
    :param parent: QWidget
    :return: bool
    """

    message_box = QMessageBox()
    message_box.setWindowTitle(title)
    flags = message_box.windowFlags(
    ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint
    if file_path:
        path_message = 'Path: {}'.format(file_path)
        message_box.setInformativeText(path_message)
    message_box.setWindowFlags(flags)
    save = message_box.addButton('Save', QMessageBox.YesRole)
    no_save = message_box.addButton('Do not save', QMessageBox.NoRole)
    cancel = message_box.addButton('Cancel', QMessageBox.RejectRole)
    message_box.exec_()

    if message_box.clickedButton() == save:
        return True
    elif message_box.clickedButton() == no_save:
        return False
    elif message_box.clickedButton() == cancel:
        return None

    return None
Ejemplo n.º 2
0
def get_permission(message=None, cancel=True, title='Permission', parent=None):
    """
    Shows a permission message box
    :param message: str, message to show to the user
    :param cancel: bool, Whether the user can cancel the operation or not
    :param title: str, title of the window
    :param parent: QWidget
    :return: bool
    """

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

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

    return None
Ejemplo n.º 3
0
def about_message(message, parent=None):
    """
    Shows an about message
    :param message: str
    :param parent: QWidget
    """

    parent = None
    message_box = QMessageBox(parent)
    flags = message_box.windowFlags(
    ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint
    message_box.setWindowFlags(flags)
    message_box.about(parent, 'About', message)
Ejemplo n.º 4
0
def warning_message(message, parent=None):
    """
    Shows a warning message
    :param message: str
    :param parent: QWidget
    """

    parent = None
    message_box = QMessageBox(parent)
    flags = message_box.windowFlags(
    ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint
    message_box.setWindowFlags(flags)
    message_box.warning(parent, 'Warning', message)
Ejemplo n.º 5
0
def critical_message(message, parent=None):
    """
    Shows a critical message
    :param message: str
    :param parent: QWidget
    """

    parent = None
    message_box = QMessageBox(parent)
    flags = message_box.windowFlags(
    ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint
    message_box.setWindowFlags(flags)
    message_box.critical(parent, 'Critical Error', message)
Ejemplo n.º 6
0
class PopUpWarning(Error):
    """
    display a popup error box with a custom message
    """
    def __init__(self, _msg):
        self.msg_box = QMessageBox()
        self.msg_box.setWindowFlags(self.msg_box.windowFlags()
                                    | QtCore.Qt.WindowStaysOnTopHint)
        self.msg_box.setWindowTitle("Warning")
        self.msg_box.setIcon(QMessageBox.Warning)
        self.msg_box.setStandardButtons(QMessageBox.Ok)
        self.msg_box.setText(_msg)
        self.msg_box.exec_()
Ejemplo n.º 7
0
class SidNotValid(Error):
    """
    Raised when the file can't be open
    """
    def __init__(self):
        self.msg_box = QMessageBox()
        self.msg_box.setWindowFlags(self.msg_box.windowFlags()
                                    | QtCore.Qt.WindowStaysOnTopHint)
        self.msg_box.setWindowTitle("Error")
        self.msg_box.setIcon(QMessageBox.Warning)
        self.msg_box.setStandardButtons(QMessageBox.Ok)
        self.msg_box.setText("Sid not valid")
        self.msg_box.exec_()
Ejemplo n.º 8
0
class NoSelectionError(Error):
    """
    Raised when the user don't select a file needed
    """
    def __init__(self):
        self.msg_box = QMessageBox()
        self.msg_box.setWindowFlags(self.msg_box.windowFlags()
                                    | QtCore.Qt.WindowStaysOnTopHint)
        self.msg_box.setWindowTitle("Error")
        self.msg_box.setIcon(QMessageBox.Critical)
        self.msg_box.setStandardButtons(QMessageBox.Ok)
        self.msg_box.setText("Select a file !")
        self.msg_box.exec_()
Ejemplo n.º 9
0
class Error(Exception):
    """
    Basic exeption class
    """
    def __init__(self, msg):
        self.msg_box = QMessageBox()
        self.msg_box.setWindowFlags(self.msg_box.windowFlags()
                                    | QtCore.Qt.WindowStaysOnTopHint)
        self.msg_box.setWindowTitle("Error")
        self.msg_box.setIcon(QMessageBox.Critical)
        self.msg_box.setStandardButtons(QMessageBox.Ok)
        self.msg_box.setText(msg)
        self.msg_box.exec_()