Exception: Add exception with message box for not implement method.

mesh
Pierre-Antoine Rouby 2023-04-18 11:27:32 +02:00
parent 726921af6a
commit 52c4eec72a
5 changed files with 75 additions and 8 deletions

View File

@ -1,9 +1,16 @@
# -*- coding: utf-8 -*-
from PyQt5.QtCore import (
QCoreApplication,
)
from PyQt5.QtWidgets import (
QApplication, QMessageBox,
)
_translate = QCoreApplication.translate
####################################
# Message Box for python exception #
####################################
@ -27,13 +34,13 @@ class ExeceptionWithMessageBox(Exception):
self.title = title
def header(self):
return "Generic error message"
return _translate("Exception", "Generic error message")
def short_message(self):
return "Undefined error message"
return _translate("Exception", "Undefined error message")
def message(self):
return "Undefined error message"
return _translate("Exception", "Undefined error message")
def alert(self):
msg = QMessageBox()
@ -46,21 +53,66 @@ class ExeceptionWithMessageBox(Exception):
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 = "FileFormatError")
super(FileFormatError, self).__init__(
title = _translate("Exception", "FileFormatError")
)
self.reason = reason
self.filename = filename
def __str__(self):
return f"Invalid file format: '{self.filename}'\n{self.message()}"
return (
_translate("Exception", "Invalid file format:") +
f" '{self.filename}'\n{self.message()}"
)
def header(self):
return "File format error"
return _translate("Exception", "File format error")
def short_message(self):
return "Invalid file format"
return _translate("Exception", "Invalid file format")
def message(self):
return f"Invalid file '{self.filename}' format because of '{self.reason}'"
return (
_translate("Exception", "Invalid file") +
f" '{self.filename}' " +
_translate("Exception", "format because of") +
f" '{self.reason}'"
)

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from Model.Except import NotImplementedMethodeError
class Point(object):
def __init__(self, name:str = ""):
super(Point, self).__init__()
@ -20,3 +22,9 @@ class Point(object):
True if the point is named.
"""
return self._name.strip() != ""
def is_nan(self):
raise NotImplementedMethodeError(self, self.is_nan)
def dist(self, p2):
raise NotImplementedMethodeError(self, self.dist)

View File

@ -31,6 +31,9 @@ class PointAC(Point):
def c(self, value):
self._c = float(value)
def dist(self, p2):
return PointAC.distance(self, p2)
@staticmethod
def distance(p1, p2):
"""Euclidean distance between p1 and p2.

View File

@ -50,6 +50,9 @@ class PointXYZ(Point):
isna(self.y) or
isna(self.z))
def dist(self, p2):
return PointXYZ.distance(self, p2)
@staticmethod
def distance(p1, p2):
"""Euclidean distance between p1 and p2.

View File

@ -20,6 +20,7 @@ from View.Geometry import qtableview_reach
from View.Geometry import window_profileXYZ
from View.ASubWindow import WindowToolKit
_translate = QCoreApplication.translate
class GeometryWindow(QMainWindow, WindowToolKit):