1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
3
# MAUS is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# MAUS is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
24
from gui.window import GuiError
26
#pylint: disable=E1101
28
class MessageWindow: #pylint: disable=R0903
30
Make a window that just holds a label with a given message
32
def __init__(self, message):
34
Initialise; parent will always be main_frame
36
_message = str(message)
38
"type":"transient_frame",
42
"label_length":len(_message)+5,
50
self.window = gui.window.Window(ROOT.gClient.GetRoot(),
51
ROOT.gClient.GetRoot(),
53
self.window.set_button_action("&Okay", self.okay_action)
55
def okay_action(self):
57
Pressing Okay just closes the window
59
self.window.close_window()
62
SYS_EXCEPTHOOK = sys.excepthook
64
def set_error_level(error_level):
66
Set the error level that will be handled by the exception handler
67
- error_level: string or corresponding integer error level that will cause
68
the exception handler to respond. Options are "errors", "exceptions",
69
"gui_exceptions", "nothing"
71
Also calls set_excepthook()
73
global ERROR_LEVEL # pylint: disable=W0603
74
my_error_levels = ["errors", "exceptions", "gui_exceptions", "nothing"]
75
if error_level in my_error_levels:
76
ERROR_LEVEL = my_error_levels.index(error_level)
77
elif error_level in range(4):
78
ERROR_LEVEL = error_level
80
raise ValueError("Did not recognise error_level "+str(error_level))
85
Set the excepthook to gui_exception_handler excepthook
87
sys.excepthook = _excepthook
89
def reset_excepthook():
91
Reset the excepthook to sys.excepthook
93
sys.excepthook = SYS_EXCEPTHOOK
95
def _excepthook(_type, _value, _traceback):
97
GuiExceptionHandler excepthook
100
MessageWindow(str(_value))
101
elif ERROR_LEVEL == 1 and isinstance(_value, Exception):
102
MessageWindow(str(_value))
103
elif ERROR_LEVEL == 2 and isinstance(_value, GuiError):
104
MessageWindow(str(_value))
105
SYS_EXCEPTHOOK(_type, _value, _traceback)