Package gui :: Module errors
[hide private]
[frames] | no frames]

Source Code for Module gui.errors

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2011-2012 Edward d'Auvergne                                   # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Module for handling errors in the GUI.""" 
24   
25  # Python module imports. 
26  import sys 
27  import wx 
28   
29  # relax module imports. 
30  from status import Status; status = Status() 
31   
32   
33 -def gui_raise(relax_error, raise_flag=False):
34 """Handle errors in the GUI to be reported to the user. 35 36 @param relax_error: The error object. 37 @type relax_error: RelaxError instance 38 @keyword raise_flag: A flag which if True will cause the error to be raised, terminating execution. 39 @type raise_flag: bool 40 @raises RelaxError: This raises all RelaxErrors, if the raise flag is given. 41 """ 42 43 # Turn off the busy cursor if needed. 44 if wx.IsBusy(): 45 wx.EndBusyCursor() 46 47 # Non-fatal - the error is not raised so just send the text to STDERR. 48 if not raise_flag: 49 sys.stderr.write(relax_error.__str__()) 50 sys.stderr.write("\n") 51 52 # Show the relax controller (so that the window doesn't hide the dialog). 53 app = wx.GetApp() 54 app.gui.show_controller(None) 55 app.Yield(True) 56 57 # Show a dialog explaining the error. 58 dlg = wx.MessageDialog(None, relax_error.text, caption="RelaxError", style=wx.OK|wx.ICON_ERROR) 59 if status.show_gui: 60 dlg.ShowModal() 61 62 # Throw the error to terminate execution. 63 if raise_flag: 64 raise relax_error
65