def __init__(self, show_script=True, quit=True, raise_relax_error=False): """The interpreter class. @param show_script: If true, the relax will print the script contents prior to executing the script. @type show_script: bool @param quit: If true, the default, then relax will exit after running the run() method. @type quit: bool @param raise_relax_error: If false, the default, then relax will print a nice error message to STDERR, without a traceback, when a RelaxError occurs. This is to make things nicer for the user. @type raise_relax_error: bool """ # Place the arguments in the class namespace. self.__show_script = show_script self.__quit_flag = quit self.__raise_relax_error = raise_relax_error # Build the intro string. info = Info_box() self.__intro_string = info.intro_text() # The prompts (change the Python prompt, as well as the function printouts). if ansi.enable_control_chars(stream=1): self.prompt_colour_on() else: self.prompt_colour_off() # Set up the interpreter objects. self._locals = self._setup()
def __init__(self, show_script=True, raise_relax_error=False): """The interpreter class. @param show_script: If true, the relax will print the script contents prior to executing the script. @type show_script: bool @param raise_relax_error: If false, the default, then relax will print a nice error message to STDERR, without a traceback, when a RelaxError occurs. This is to make things nicer for the user. @type raise_relax_error: bool """ # Place the arguments in the class namespace. self.__show_script = show_script self.__raise_relax_error = raise_relax_error # Build the intro string. info = Info_box() self.__intro_string = info.intro_text() # The prompts (change the Python prompt, as well as the function printouts). if ansi.enable_control_chars(stream=1) and not status.show_gui: self.prompt_colour_on() else: self.prompt_colour_off() # Set up the interpreter objects. self._locals = self._setup()
def __init__(self, locals=None, rawin=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, showInterpIntro=True): """Redefine the interpreter.""" # Execute the base class __init__() method. wx.py.interpreter.Interpreter.__init__(self, locals=locals, rawin=rawin, stdin=stdin, stdout=stdout, stderr=stderr, showInterpIntro=showInterpIntro) # The introductory text. info = Info_box() self.introText = info.intro_text() # The relax interpreter. interp = interpreter.Interpreter(show_script=False, raise_relax_error=True) # The locals. self.locals = interp._locals
def __init__(self, locals=None, rawin=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, showInterpIntro=True): """Redefine the interpreter.""" # Execute the base class __init__() method. wx.py.interpreter.Interpreter.__init__(self, locals=locals, rawin=rawin, stdin=stdin, stdout=stdout, stderr=stderr, showInterpIntro=showInterpIntro) # The introductory text. info = Info_box() self.introText = info.intro_text() # The relax interpreter. interp = interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True) # The locals. self.locals = interp._locals
def run(self): """Execute relax. This is the application callback method executed by the multi-processor framework. """ # Set up the warning system. lib.warnings.setup() # Logging. if self.log_file: io_streams_log(self.log_file) # Tee. elif self.tee_file: io_streams_tee(self.tee_file) # Show the version number and exit. if self.mode == 'version': print('relax ' + version.version_full()) return # Show the relax info and exit. if self.mode == 'info': # Initialise the information box. info = Info_box() # Print the program intro. print(info.intro_text()) # Print the system info. print(info.sys_info()) # Stop execution. return # Run the interpreter for the prompt or script modes. if self.mode == 'prompt' or self.mode == 'script': # Run the interpreter. self.interpreter = interpreter.Interpreter() self.interpreter.run(self.script_file) # Execute the relax GUI. elif self.mode == 'gui': # Dependency check. if not dep_check.wx_module: sys.stderr.write("Please install the wx Python module to access the relax GUI.\n\n") return # Only import the module in this mode (to improve program start up speeds). import gui # Set the GUI flag in the status object. status.show_gui = True # Start the relax GUI wx application. app = gui.App(script_file=self.script_file) app.MainLoop() # Execute the relax test suite elif self.mode == 'test suite': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Load the interpreter and turn intros on. self.interpreter = interpreter.Interpreter(show_script=False, raise_relax_error=True) self.interpreter.on() # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_all_tests() # Execute the relax system tests. elif self.mode == 'system tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Load the interpreter and turn intros on. self.interpreter = interpreter.Interpreter(show_script=False, raise_relax_error=True) self.interpreter.on() # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_system_tests() # Execute the relax unit tests. elif self.mode == 'unit tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_unit_tests() # Execute the relax GUI tests. elif self.mode == 'GUI tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_gui_tests() # Execute the relax verification tests. elif self.mode == 'verification tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_verification_tests() # Test mode. elif self.mode == 'test': self.test_mode() # Licence mode. elif self.mode == 'licence': self.licence() # Unknown mode. else: raise lib.errors.RelaxError("The '%s' mode is unknown." % self.mode)
def run(self): """Execute relax. This is the application callback method executed by the multi-processor framework. """ # Set up the warning system. lib.warnings.setup() # Logging. if self.log_file: io_streams_log(self.log_file) # Tee. elif self.tee_file: io_streams_tee(self.tee_file) # Show the version number and exit. if self.mode == 'version': print('relax ' + version.version_full()) return # Show the relax info and exit. if self.mode == 'info': # Initialise the information box. info = Info_box() # Print the program intro. print(info.intro_text()) # Print the system info. print(info.sys_info()) # Stop execution. return # Run the interpreter for the prompt or script modes. if self.mode == 'prompt' or self.mode == 'script': # Run the interpreter. self.interpreter = interpreter.Interpreter() self.interpreter.run(self.script_file) # Execute the relax GUI. elif self.mode == 'gui': # Dependency check. if not dep_check.wx_module: sys.stderr.write( "Please install the wx Python module to access the relax GUI.\n\n" ) return # Only import the module in this mode (to improve program start up speeds). import gui # Set the GUI flag in the status object. status.show_gui = True # Start the relax GUI wx application. app = gui.App(script_file=self.script_file) app.MainLoop() # Execute the relax test suite elif self.mode == 'test suite': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Load the interpreter and turn intros on. self.interpreter = interpreter.Interpreter(show_script=False, raise_relax_error=True) self.interpreter.on() # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_all_tests() # Execute the relax system tests. elif self.mode == 'system tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Load the interpreter and turn intros on. self.interpreter = interpreter.Interpreter(show_script=False, raise_relax_error=True) self.interpreter.on() # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_system_tests() # Execute the relax unit tests. elif self.mode == 'unit tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_unit_tests() # Execute the relax GUI tests. elif self.mode == 'GUI tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_gui_tests() # Execute the relax verification tests. elif self.mode == 'verification tests': # Only import the module in the test modes (to improve program start up speeds). from test_suite.test_suite_runner import Test_suite_runner # Run the tests. runner = Test_suite_runner(self.tests, timing=self.test_timings) runner.run_verification_tests() # Test mode. elif self.mode == 'test': self.test_mode() # Licence mode. elif self.mode == 'licence': self.licence() # Unknown mode. else: raise lib.errors.RelaxError("The '%s' mode is unknown." % self.mode)
def __init__(self, gui): """Set up the relax controller frame. @param gui: The GUI object. @type gui: wx.Frame instance """ # Store the args. self.gui = gui # Initialise the base class. super(Controller, self).__init__(self.gui, -1, style=wx.DEFAULT_FRAME_STYLE) # Some default values. self.size_x = 800 self.size_y = 700 self.border = 5 self.spacer = 10 # Set up the frame. sizer = self.setup_frame() # Add the relax logo. self.add_relax_logo(sizer) # Spacing. sizer.AddSpacer(20) # Add the current analysis info. self.name = self.add_text(self.main_panel, sizer, "Current GUI analysis:") # Add the current data pipe info. self.cdp = self.add_text(self.main_panel, sizer, "Current data pipe:") # Create the relaxation curve-fitting specific panel. self.create_rx(sizer) # Create the model-free specific panel. self.create_mf(sizer) # Add the main execution gauge. self.main_gauge = self.add_gauge( self.main_panel, sizer, "Execution progress:", tooltip= "This gauge will pulse while relax is executing an auto-analysis (when the execution lock is turned on) and will be set to 100% once the analysis is complete." ) # Initialise a queue for log messages. self.log_queue = Queue() # Add the log panel. self.log_panel = LogCtrl(self.main_panel, self, log_queue=self.log_queue, id=-1) sizer.Add(self.log_panel, 1, wx.EXPAND | wx.ALL, 0) # IO redirection for STDOUT (with splitting if logging or teeing modes are set). out = Redirect_text(self.log_panel, self.log_queue, orig_io=sys.stdout, stream=0) if sys.stdout == sys.__stdout__ or status.relax_mode in [ 'test suite', 'system tests', 'unit tests', 'GUI tests' ]: sys.stdout = out else: split_stdout = SplitIO() split_stdout.split(sys.stdout, out) sys.stdout = split_stdout # IO redirection for STDERR (with splitting if logging or teeing modes are set). err = Redirect_text(self.log_panel, self.log_queue, orig_io=sys.stderr, stream=1) if sys.stderr == sys.__stderr__ or status.relax_mode in [ 'test suite', 'system tests', 'unit tests', 'GUI tests' ]: sys.stderr = err else: split_stderr = SplitIO() split_stderr.split(sys.stderr, err) sys.stderr = split_stderr # Initial update of the controller. self.update_controller() # Create a timer for updating the controller elements. self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.handler_timer, self.timer) # The relax intro printout, to mimic the prompt/script interface. if not status.test_mode: info = Info_box() sys.stdout.write(info.intro_text()) sys.stdout.write("\n") sys.stdout.flush() # Set the focus on the log control. self.log_panel.SetFocus() # Register functions with the observer objects. status.observers.pipe_alteration.register( 'controller', self.update_controller, method_name='update_controller') status.observers.auto_analyses.register( 'controller', self.update_controller, method_name='update_controller') status.observers.gui_analysis.register('controller', self.update_controller, method_name='update_controller') status.observers.exec_lock.register('controller', self.update_gauge, method_name='update_gauge')
def __init__(self, gui): """Set up the relax controller frame. @param gui: The GUI object. @type gui: wx.Frame instance """ # Store the args. self.gui = gui # Initialise the base class. super(Controller, self).__init__(self.gui, -1, style=wx.DEFAULT_FRAME_STYLE) # Some default values. self.size_x = 800 self.size_y = 700 self.border = 5 self.spacer = 10 # Set up the frame. sizer = self.setup_frame() # Add the relax logo. self.add_relax_logo(sizer) # Spacing. sizer.AddSpacer(20) # Add the current analysis info. self.name = self.add_text(self.main_panel, sizer, "Current GUI analysis:") # Add the current data pipe info. self.cdp = self.add_text(self.main_panel, sizer, "Current data pipe:") # Create the relaxation curve-fitting specific panel. self.create_rx(sizer) # Create the model-free specific panel. self.create_mf(sizer) # Add the main execution gauge. self.main_gauge = self.add_gauge(self.main_panel, sizer, "Execution progress:", tooltip="This gauge will pulse while relax is executing an auto-analysis (when the execution lock is turned on) and will be set to 100% once the analysis is complete.") # Initialise a queue for log messages. self.log_queue = Queue() # Add the log panel. self.log_panel = LogCtrl(self.main_panel, self, log_queue=self.log_queue, id=-1) sizer.Add(self.log_panel, 1, wx.EXPAND|wx.ALL, 0) # IO redirection for STDOUT (with splitting if logging or teeing modes are set). out = Redirect_text(self.log_panel, self.log_queue, orig_io=sys.stdout, stream=0) if sys.stdout == sys.__stdout__ or status.relax_mode in ['test suite', 'system tests', 'unit tests', 'GUI tests']: sys.stdout = out else: split_stdout = SplitIO() split_stdout.split(sys.stdout, out) sys.stdout = split_stdout # IO redirection for STDERR (with splitting if logging or teeing modes are set). err = Redirect_text(self.log_panel, self.log_queue, orig_io=sys.stderr, stream=1) if sys.stderr == sys.__stderr__ or status.relax_mode in ['test suite', 'system tests', 'unit tests', 'GUI tests']: sys.stderr = err else: split_stderr = SplitIO() split_stderr.split(sys.stderr, err) sys.stderr = split_stderr # Initial update of the controller. self.update_controller() # Create a timer for updating the gauges. self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.handler_timer, self.timer) # The relax intro printout, to mimic the prompt/script interface. if not status.test_mode: info = Info_box() print(info.intro_text()) # Register functions with the observer objects. status.observers.pipe_alteration.register('controller', self.update_controller, method_name='update_controller') status.observers.auto_analyses.register('controller', self.update_controller, method_name='update_controller') status.observers.gui_analysis.register('controller', self.update_controller, method_name='update_controller') status.observers.exec_lock.register('controller', self.update_gauge, method_name='update_gauge')