-
Pierre-Antoine Rouby authoredf4dd46cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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}'"