An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authored52c4eec7
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
from PyQt5.QtCore import (
QCoreApplication,
)
from PyQt5.QtWidgets import (
QApplication, QMessageBox,
)
_translate = QCoreApplication.translate
####################################
# 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 _translate("Exception", "Generic error message")
def short_message(self):
return _translate("Exception", "Undefined error message")
def message(self):
return _translate("Exception", "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 NotImplementedMethodeError(ExeceptionWithMessageBox):
def __init__(self, obj, func):
super(NotImplementedMethodeError, self).__init__(
title = _translate("Exception", "Method not implemented")
)
self.obj = obj
self.func = func
self.alert()
def __str__(self):
return (
_translate("Exception", "Method") +
f" '{self.func.__name__}' " +
_translate("Exception", "not implemented") +
_translate("Exception", "for class") +
f" '{self.obj.__class__}'"
)
def header(self):
return _translate("Exception", "Not implemented method")
def short_message(self):
return _translate("Exception", "Not implemented method")
def message(self):
return (
_translate("Exception", "Method") +
f" '{self.func.__name__}' " +
_translate("Exception", "not implemented") +
_translate("Exception", "for class") +
f" '{self.obj.__class__}'"
)
class FileFormatError(ExeceptionWithMessageBox):
def __init__(self, filename, reason):
super(FileFormatError, self).__init__(
title = _translate("Exception", "FileFormatError")
)
self.reason = reason
self.filename = filename
def __str__(self):
return (
_translate("Exception", "Invalid file format:") +
f" '{self.filename}'\n{self.message()}"
)
def header(self):
return _translate("Exception", "File format error")
def short_message(self):
return _translate("Exception", "Invalid file format")
def message(self):
return (
_translate("Exception", "Invalid file") +
f" '{self.filename}' " +
_translate("Exception", "format because of") +
f" '{self.reason}'"
)