Author: bugman Date: Wed Jun 29 17:21:00 2011 New Revision: 13313 URL: http://svn.gna.org/viewcvs/relax?rev=13313&view=rev Log: Modified the threading execution of the GUI analyses. The class gui.analyses.execute.Execute has been created to be a base class for all the analysis threads. The specific analyses then only need to derive from this by providing the run() method. All of the threaded vs. non-threaded, exception handling, and other threaded properties will then be handed by this class. Added: branches/gui_testing/gui/analyses/execute.py Modified: branches/gui_testing/gui/analyses/auto_noe.py branches/gui_testing/gui/analyses/auto_rx_base.py Modified: branches/gui_testing/gui/analyses/auto_noe.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/auto_noe.py?rev=13313&r1=13312&r2=13313&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/auto_noe.py (original) +++ branches/gui_testing/gui/analyses/auto_noe.py Wed Jun 29 17:21:00 2011 @@ -29,7 +29,6 @@ from os.path import dirname from string import replace import sys -from threading import Thread import time import wx @@ -41,6 +40,7 @@ # relaxGUI module imports. from gui.analyses.base import Base_frame +from gui.analyses.execute import Execute from gui.analyses.results_analysis import color_code_noe from gui.base_classes import Container from gui.controller import Redirect_text @@ -285,12 +285,14 @@ if not status.debug: self.gui.controller.Show() - # Start the thread (if not debugging). + # Threading flag. + thread = True if status.debug: - self.thread = Execute(self.gui, data, self.data_index) - else: - self.thread = Execute_thread(self.gui, data, self.data_index) - self.thread.start() + thread = False + + # Start the thread. + self.thread = Execute_noe(self.gui, data, self.data_index, thread=thread) + self.thread.start() # Terminate the event. event.Skip() @@ -468,28 +470,8 @@ -class Execute: +class Execute_noe(Execute): """The NOE analysis execution object.""" - - def __init__(self, gui, data, data_index): - """Set up the NOE analysis execution object. - - @param gui: The GUI object. - @type gui: wx object - @param data: The data container with all data for the analysis. - @type data: class instance - @param data_index: The index of the analysis in the relax data store. - @type data_index: int - """ - - # Store the args. - self.gui = gui - self.data = data - self.data_index = data_index - - # Execute. - self.run() - def run(self): """Execute the calculation.""" @@ -521,27 +503,3 @@ # Add the macro to the results list. data.results_list.append(data.save_dir+sep+'noe.pml') - - - -class Execute_thread(Execute, Thread): - """The NOE analysis thread execution object.""" - - def __init__(self, gui, data, data_index): - """Set up the NOE analysis thread execution object. - - @param gui: The GUI object. - @type gui: wx object - @param data: The data container with all data for the analysis. - @type data: class instance - @param data_index: The index of the analysis in the relax data store. - @type data_index: int - """ - - # Store the args. - self.gui = gui - self.data = data - self.data_index = data_index - - # Set up the thread object. - Thread.__init__(self) Modified: branches/gui_testing/gui/analyses/auto_rx_base.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/auto_rx_base.py?rev=13313&r1=13312&r2=13313&view=diff ============================================================================== --- branches/gui_testing/gui/analyses/auto_rx_base.py (original) +++ branches/gui_testing/gui/analyses/auto_rx_base.py Wed Jun 29 17:21:00 2011 @@ -28,7 +28,6 @@ from os import sep from string import replace import sys -from threading import Thread import time import wx @@ -40,6 +39,7 @@ # relaxGUI module imports. from gui.analyses.base import Base_frame +from gui.analyses.execute import Execute from gui.base_classes import Container from gui.components.spectrum import Peak_intensity from gui.controller import Redirect_text @@ -268,11 +268,15 @@ if not status.debug: self.gui.controller.Show() + # Threading flag. + thread = True + if status.debug: + thread = False + # Start the thread. - if status.debug: - self.thread = Execute(self.gui, data, self.data_index) + self.thread = Execute_rx(self.gui, data, self.data_index, thread=False) else: - self.thread = Execute_thread(self.gui, data, self.data_index) + self.thread = Execute_rx(self.gui, data, self.data_index) self.thread.start() @@ -364,28 +368,8 @@ -class Execute: +class Execute_rx(Execute): """The Rx analysis execution object.""" - - def __init__(self, gui, data, data_index): - """Set up the Rx analysis execution object. - - @param gui: The GUI object. - @type gui: wx object - @param data: The data container with all data for the analysis. - @type data: class instance - @param data_index: The index of the analysis in the relax data store. - @type data_index: int - """ - - # Store the args. - self.gui = gui - self.data = data - self.data_index = data_index - - # Execute. - self.run() - def run(self): """Execute the calculation.""" @@ -410,27 +394,3 @@ # Add Rx grace plot to the results list. data.results_list.append(data.save_dir+sep+'grace'+sep+self.filename+'.agr') data.results_list.append(data.save_dir+sep+'grace'+sep+'intensities_norm.agr') - - - -class Execute_thread(Execute, Thread): - """The NOE analysis thread execution object.""" - - def __init__(self, gui, data, data_index): - """Set up the NOE analysis thread execution object. - - @param gui: The GUI object. - @type gui: wx object - @param data: The data container with all data for the analysis. - @type data: class instance - @param data_index: The index of the analysis in the relax data store. - @type data_index: int - """ - - # Store the args. - self.gui = gui - self.data = data - self.data_index = data_index - - # Set up the thread object. - Thread.__init__(self) Added: branches/gui_testing/gui/analyses/execute.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/execute.py?rev=13313&view=auto ============================================================================== --- branches/gui_testing/gui/analyses/execute.py (added) +++ branches/gui_testing/gui/analyses/execute.py Wed Jun 29 17:21:00 2011 @@ -1,0 +1,68 @@ +############################################################################### +# # +# Copyright (C) 2011 Edward d'Auvergne # +# # +# This file is part of the program relax. # +# # +# relax is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# relax is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with relax; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +############################################################################### + +# Module docstring. +"""Module containing the class for threaded and non-threaded analysis execution.""" + + +# Python module imports. +from threading import Thread + + + +class Execute(Thread): + """The analysis execution object.""" + + def __init__(self, gui, data, data_index, thread=True): + """Set up the NOE analysis execution object. + + @param gui: The GUI object. + @type gui: wx object + @param data: The data container with all data for the analysis. + @type data: class instance + @param data_index: The index of the analysis in the relax data store. + @type data_index: int + @keyword thread: The flag for turning threading on and off. + @type thread: bool + """ + + # Store the args. + self.gui = gui + self.data = data + self.data_index = data_index + + # Threaded execution. + if thread: + # Set up the thread object. + Thread.__init__(self) + + # No treaded execution. + else: + # Alias the start method. + self.start = self._start + + + def _start(self): + """Replacement start() method for when execution is not threaded.""" + + # Execute the run() method. + self.run()