-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdecorators.py
More file actions
61 lines (51 loc) · 1.98 KB
/
decorators.py
File metadata and controls
61 lines (51 loc) · 1.98 KB
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
"""
=========================================================================
Decorators for various functions
=========================================================================
"""
# author : AC Chamberlain <[email protected]>
# copyright: AC Chamberlain (c) 2023-2026
# SPDX-License-Identifier: Licence.txt:
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QApplication
def show_wait_cursor(function):
def new_function(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
QApplication.processEvents()
try:
return function(self)
except Exception as e:
print("Error {}".format(e.args[0]))
raise e
finally:
QApplication.restoreOverrideCursor()
QApplication.processEvents()
return new_function
def check_valid_image(function):
# check if the imager has been created
def _valid_image(self):
if (self.imager is not None) and hasattr(self.imager, "values") and (self.imager.values is not None):
try:
return function(self)
except Exception as e:
self.ui.statusbar.status_error(f"Could not analyze image(s). Reason: {repr(e)}")
else:
self.ui.statusbar.status_error("No image open. Please open an image!")
return _valid_image
def check_values_exist(function):
# check if image pixel values exist
def _values_exist(*args, **kwargs):
self = args[0]
if hasattr(self, "values") and self.values is not None:
return function(*args, **kwargs)
return _values_exist
def catch_nm_type_error(function):
# display error if image is not nuclear medicine (NM or PET)
def _catch_nm_error(*args, **kwargs):
self = args[0]
try:
return function(*args, **kwargs)
except TypeError:
self.ui.statusbar.status_error('The file is not a nuclear medicine or PET image.')
return _catch_nm_error