Package gui :: Package user_functions :: Module script
[hide private]
[frames] | no frames]

Source Code for Module gui.user_functions.script

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2010-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  """The script user functions.""" 
25   
26  # Python module imports. 
27  import thread 
28  import wx 
29   
30  # relax module imports. 
31  from status import Status; status = Status() 
32   
33  # GUI module imports. 
34  from base import UF_base 
35  from gui.filedialog import RelaxFileDialog 
36  from gui.interpreter import Interpreter; interpreter = Interpreter() 
37   
38   
39 -class Script(UF_base):
40 """The script user function GUI class.""" 41
42 - def run(self, file=None):
43 """The script user function GUI element. 44 45 @param file: The path of the script to execute, if already known. If not given, a file selection dialog will appear. 46 @type file: str 47 """ 48 49 # User selection of the file. 50 if not file: 51 dialog = RelaxFileDialog(parent=None, message='Select the relax script to execute', wildcard='relax scripts (*.py)|*.py', style=wx.FD_OPEN) 52 53 # Show the dialog and catch if no file has been selected. 54 if status.show_gui and dialog.ShowModal() != wx.ID_OK: 55 # Don't do anything. 56 return 57 58 # The file. 59 file = dialog.get_file() 60 61 # Show the relax controller. 62 if status.show_gui: 63 app = wx.GetApp() 64 app.gui.controller.Show() 65 66 # Execute the script in a thread. 67 id = thread.start_new_thread(self.script_exec, (file,))
68 69
70 - def script_exec(self, file):
71 """Execute the script in a thread. 72 73 @param file: The script file name. 74 @type file: str 75 """ 76 77 # Execute the user function. 78 interpreter.apply('script', str(file))
79