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

Source Code for Module gui.errors

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2011 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax 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 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax 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 relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Module docstring. 
24  """Module for handling errors in the GUI.""" 
25   
26  # Python module imports. 
27  import sys 
28  import wx 
29   
30  # relax module imports. 
31  from status import Status; status = Status() 
32   
33   
34 -def gui_raise(relax_error, raise_flag=False):
35 """Handle errors in the GUI to be reported to the user. 36 37 @param relax_error: The error object. 38 @type relax_error: RelaxError instance 39 @keyword raise_flag: A flag which if True will cause the error to be raised, terminating execution. 40 @type raise_flag: bool 41 @raises RelaxError: This raises all RelaxErrors, if the raise flag is given. 42 """ 43 44 # Turn off the busy cursor if needed. 45 if wx.IsBusy(): 46 wx.EndBusyCursor() 47 48 # Non-fatal - the error is not raised so just send the text to STDERR. 49 if not raise_flag: 50 sys.stderr.write(relax_error.__str__()) 51 sys.stderr.write("\n") 52 53 # Show the relax controller (so that the window doesn't hide the dialog). 54 app = wx.GetApp() 55 app.gui.show_controller(None) 56 app.Yield(True) 57 58 # Show a dialog explaining the error. 59 dlg = wx.MessageDialog(None, relax_error.text, caption="RelaxError", style=wx.OK|wx.ICON_ERROR) 60 if status.show_gui: 61 dlg.ShowModal() 62 63 # Throw the error to terminate execution. 64 if raise_flag: 65 raise relax_error
66