diff --git a/src/Model/Except.py b/src/Model/Except.py new file mode 100644 index 0000000000000000000000000000000000000000..b88eccd2f298fd435a63f12f076fb94ac7bedbfe --- /dev/null +++ b/src/Model/Except.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- + +from PyQt5.QtWidgets import ( + QApplication, QMessageBox, +) + +#################################### +# Message Box for python exception # +#################################### + +def exception_message_box(exception): + msg = QMessageBox() + msg.setIcon(QMessageBox.Critical) + + msg.setText("Exception :") + msg.setInformativeText(f"{exception}") + msg.setWindowTitle("Exception") + + msg.exec_() + +################ +# Custom error # +################ + +class ExeceptionWithMessageBox(Exception): + def __init__(self, title = "Exeception"): + self.title = title + + def header(self): + return "Generic error message" + + def short_message(self): + return "Undefined error message" + + def message(self): + return "Undefined error message" + + def alert(self): + msg = QMessageBox() + msg.setIcon(QMessageBox.Critical) + + msg.setText(f"{self.header()} : {self.short_message()}") + msg.setInformativeText(f"{self.message()}") + msg.setWindowTitle(f"{self.title}") + + msg.exec_() + + +class FileFormatError(ExeceptionWithMessageBox): + def __init__(self, filename, reason): + super(FileFormatError, self).__init__(title = "FileFormatError") + + self.reason = reason + self.filename = filename + + def __str__(self): + return f"Invalid file format: '{self.filename}'\n{self.message()}" + + def header(self): + return "File format error" + + def short_message(self): + return "Invalid file format" + + def message(self): + return f"Invalid file '{self.filename}' format because of '{self.reason}'"