diff --git a/measureSequences/Sequence_editor.py b/measureSequences/Sequence_editor.py index ffdd071..c2a10b7 100644 --- a/measureSequences/Sequence_editor.py +++ b/measureSequences/Sequence_editor.py @@ -23,6 +23,7 @@ import threading from .util import Window_ui +from .util import ExceptionHandling from .Sequence_parsing import Sequence_parser from .qlistmodel import SequenceListModel @@ -279,12 +280,14 @@ class Sequence_builder(Window_ui, Sequence_parser): sig_runSequence = pyqtSignal(list) sig_abortSequence = pyqtSignal() + sig_assertion = pyqtSignal(str) def __init__(self, parent=None, **kwargs): super().__init__( ui_file=pkg_resources.resource_filename(__name__, "configurations\\sequence.ui"), **kwargs) # self.listSequence.sig_dropped.connect(lambda value: self.dropreact(value)) + self.__name__ = 'Sequence_builder' QTimer.singleShot(0, self.initialize_all_windows) # QTimer.singleShot( @@ -317,10 +320,12 @@ def __init__(self, parent=None, **kwargs): def init_data(self): self.data = [] + @ExceptionHandling def running_sequence(self): self.data = self.model.pass_data() self.sig_runSequence.emit(deepcopy(self.data)) + @ExceptionHandling def addItem_toSequence(self, text): """ depending on the Item clicked, add the correct Item to the model, @@ -354,6 +359,7 @@ def addItem_toSequence(self, text): if text.text(0) == 'Shutdown Temperature Control': raise NotImplementedError + @ExceptionHandling def addWaiting(self, data): string = self.displaytext_waiting(data) data.update(dict(DisplayText=string)) @@ -362,6 +368,7 @@ def addWaiting(self, data): QTimer.singleShot(1, lambda: self.listSequence.repaint()) # QTimer.singleShot(10, self.model.) + @ExceptionHandling def addTscan(self, data): string = self.displaytext_scan_T(data) data.update(dict(DisplayText=string)) @@ -381,6 +388,7 @@ def printing(self, data): # with open(self.sequence_file_json, 'w') as output: # output.write(json.dumps(self.data)) + @ExceptionHandling def initialize_all_windows(self): self.initialise_window_waiting() self.initialise_window_Tscan() @@ -401,6 +409,7 @@ def initialise_window_ChangeDataFile(self): self.Window_ChangeDataFile.sig_accept.connect( lambda value: self.addChangeDataFile(value)) + @ExceptionHandling def window_FileDialogSave(self): self.sequence_file_json, __ = QtWidgets.QFileDialog.getSaveFileName(self, 'Save As', 'c:\\', "Serialised (*.json)") @@ -409,12 +418,14 @@ def window_FileDialogSave(self): self.sequence_file_p = self.sequence_file_json[:-4] + 'pkl' # self.sequence_file_json = self.sequence_file[:-3] + 'json' + # @ExceptionHandling def window_FileDialogOpen(self): self.sequence_file, __ = QtWidgets.QFileDialog.getOpenFileName(self, 'Save As', 'c:\\', "Sequence files (*.seq)") self.lineFileLocation.setText(self.sequence_file) self.initialize_sequence(self.sequence_file) + @ExceptionHandling def initialize_sequence(self, sequence_file): """build & run the sequence parsing, add items to the display model""" super().initialize_sequence(sequence_file) diff --git a/measureSequences/util.py b/measureSequences/util.py index 4791946..bf7efc0 100644 --- a/measureSequences/util.py +++ b/measureSequences/util.py @@ -28,6 +28,52 @@ from PyQt5 import QtWidgets from PyQt5.uic import loadUi +import functools +import inspect + + +def ExceptionSignal(thread, func, e_type, err): + """Emit assertion-signal with relevant information""" + thread.sig_assertion.emit('{}: {}: {}: {}'.format( + thread.__name__, + func.__name__, + e_type, + err.args[0])) + + +def ExceptionHandling(func): + @functools.wraps(func) + def wrapper_ExceptionHandling(*args, **kwargs): + if inspect.isclass(type(args[0])): + try: + return func(*args, **kwargs) + except AssertionError as e_ass: + ExceptionSignal(args[0], func, 'Assertion', e_ass) + + except TypeError as e_type: + ExceptionSignal(args[0], func, 'Type', e_type) + + except KeyError as e_key: + ExceptionSignal(args[0], func, 'Key', e_key) + + except ValueError as e_val: + ExceptionSignal(args[0], func, 'Value', e_val) + + except AttributeError as e_attr: + ExceptionSignal(args[0], func, 'Attribute', e_attr) + + except NotImplementedError as e_implement: + ExceptionSignal(args[0], func, 'NotImplemented', e_implement) + + except OSError as e: + ExceptionSignal(args[0], func, 'OSError', e) + + except IndexError as e: + ExceptionSignal(args[0], func, 'IndexError', e) + else: + print('There is a bug!! ' + func.__name__) + return wrapper_ExceptionHandling + def ScanningN(start, end, N): """utility function for building linspaced number-sequences""" diff --git a/requirements.txt b/requirements.txt index bb61c44..504bddc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ numpy -PyQt5 \ No newline at end of file +PyQt5 +functools \ No newline at end of file diff --git a/setup.py b/setup.py index e9f63d6..d6a0713 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ download_url='https://github.com/bklebel/measureSequences/archive/0.1.6.tar.gz', # packages=setuptools.find_packages(), packages=['measureSequences'], - install_requires=['numpy', 'PyQt5'], + install_requires=['numpy', 'PyQt5', 'functools'], include_package_data=True, classifiers=[ "Programming Language :: Python :: 3",