Commit f4dd46cd authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Model: Add missing custom execption file.

Showing with 66 additions and 0 deletions
+66 -0
# -*- 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}'"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment