mirror of https://gitlab.com/pamhyr/pamhyr2
Exception: Add exception with message box for not implement method.
parent
726921af6a
commit
52c4eec72a
|
|
@ -1,9 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QCoreApplication,
|
||||||
|
)
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QApplication, QMessageBox,
|
QApplication, QMessageBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# Message Box for python exception #
|
# Message Box for python exception #
|
||||||
####################################
|
####################################
|
||||||
|
|
@ -27,13 +34,13 @@ class ExeceptionWithMessageBox(Exception):
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
def header(self):
|
def header(self):
|
||||||
return "Generic error message"
|
return _translate("Exception", "Generic error message")
|
||||||
|
|
||||||
def short_message(self):
|
def short_message(self):
|
||||||
return "Undefined error message"
|
return _translate("Exception", "Undefined error message")
|
||||||
|
|
||||||
def message(self):
|
def message(self):
|
||||||
return "Undefined error message"
|
return _translate("Exception", "Undefined error message")
|
||||||
|
|
||||||
def alert(self):
|
def alert(self):
|
||||||
msg = QMessageBox()
|
msg = QMessageBox()
|
||||||
|
|
@ -46,21 +53,66 @@ class ExeceptionWithMessageBox(Exception):
|
||||||
msg.exec_()
|
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):
|
class FileFormatError(ExeceptionWithMessageBox):
|
||||||
def __init__(self, filename, reason):
|
def __init__(self, filename, reason):
|
||||||
super(FileFormatError, self).__init__(title = "FileFormatError")
|
super(FileFormatError, self).__init__(
|
||||||
|
title = _translate("Exception", "FileFormatError")
|
||||||
|
)
|
||||||
|
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
def __str__(self):
|
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):
|
def header(self):
|
||||||
return "File format error"
|
return _translate("Exception", "File format error")
|
||||||
|
|
||||||
def short_message(self):
|
def short_message(self):
|
||||||
return "Invalid file format"
|
return _translate("Exception", "Invalid file format")
|
||||||
|
|
||||||
def message(self):
|
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}'"
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
class Point(object):
|
class Point(object):
|
||||||
def __init__(self, name:str = ""):
|
def __init__(self, name:str = ""):
|
||||||
super(Point, self).__init__()
|
super(Point, self).__init__()
|
||||||
|
|
@ -20,3 +22,9 @@ class Point(object):
|
||||||
True if the point is named.
|
True if the point is named.
|
||||||
"""
|
"""
|
||||||
return self._name.strip() != ""
|
return self._name.strip() != ""
|
||||||
|
|
||||||
|
def is_nan(self):
|
||||||
|
raise NotImplementedMethodeError(self, self.is_nan)
|
||||||
|
|
||||||
|
def dist(self, p2):
|
||||||
|
raise NotImplementedMethodeError(self, self.dist)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@ class PointAC(Point):
|
||||||
def c(self, value):
|
def c(self, value):
|
||||||
self._c = float(value)
|
self._c = float(value)
|
||||||
|
|
||||||
|
def dist(self, p2):
|
||||||
|
return PointAC.distance(self, p2)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def distance(p1, p2):
|
def distance(p1, p2):
|
||||||
"""Euclidean distance between p1 and p2.
|
"""Euclidean distance between p1 and p2.
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ class PointXYZ(Point):
|
||||||
isna(self.y) or
|
isna(self.y) or
|
||||||
isna(self.z))
|
isna(self.z))
|
||||||
|
|
||||||
|
def dist(self, p2):
|
||||||
|
return PointXYZ.distance(self, p2)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def distance(p1, p2):
|
def distance(p1, p2):
|
||||||
"""Euclidean distance between p1 and p2.
|
"""Euclidean distance between p1 and p2.
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ from View.Geometry import qtableview_reach
|
||||||
from View.Geometry import window_profileXYZ
|
from View.Geometry import window_profileXYZ
|
||||||
from View.ASubWindow import WindowToolKit
|
from View.ASubWindow import WindowToolKit
|
||||||
|
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
class GeometryWindow(QMainWindow, WindowToolKit):
|
class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue