Exemple #1
0
def execute_script_async(script, error_cb=None):
    # Cannot define this code in execute_script as Python 2.7.5 generates an error:
    # SyntaxError: unqualified exec is not allowed in function 'execute_script' it
    # contains a nested function with free variables

    # this is intentionally imported lazily to avoid a Qt dependency
    # in the framework
    from mantidqt.widgets.codeeditor.execution import PythonCodeExecution

    def on_error(arg):
        Logger('scripter').error('Failed to execute script: {}'.format(arg))

    executioner = PythonCodeExecution()
    if error_cb is None:
        executioner.sig_exec_error.connect(on_error)
    else:
        executioner.sig_exec_error.connect(error_cb)
    executioner.execute_async(script, '<string>')
    def _run_async_code(self, code, filename=None, line_no=0):
        executor = PythonCodeExecution()
        recv = Receiver()
        executor.sig_exec_success.connect(recv.on_success)
        executor.sig_exec_error.connect(recv.on_error)
        task = executor.execute_async(code, line_no, filename)
        task.join()
        QCoreApplication.sendPostedEvents()

        return executor, recv
    def _run_async_code(self, code, with_progress=False, filename=None):
        executor = PythonCodeExecution()
        if with_progress:
            recv = ReceiverWithProgress()
            executor.sig_exec_progress.connect(recv.on_progess_update)
        else:
            recv = Receiver()
        executor.sig_exec_success.connect(recv.on_success)
        executor.sig_exec_error.connect(recv.on_error)
        task = executor.execute_async(code, filename)
        task.join()
        QCoreApplication.processEvents()

        return executor, recv
Exemple #4
0
    def _run_async_code(self, code, with_progress=False, filename=None):
        executor = PythonCodeExecution()
        if with_progress:
            recv = ReceiverWithProgress()
            executor.sig_exec_progress.connect(recv.on_progess_update)
        else:
            recv = Receiver()
        executor.sig_exec_success.connect(recv.on_success)
        executor.sig_exec_error.connect(recv.on_error)
        task = executor.execute_async(code, filename)
        task.join()
        QCoreApplication.processEvents()

        return executor, recv
 def _verify_async_execution_successful(self, code):
     executor = PythonCodeExecution()
     task = executor.execute_async(code)
     task.join()
     return executor.globals_ns
 def _verify_async_execution_successful(self, code, line_offset=0):
     executor = PythonCodeExecution()
     task = executor.execute_async(code, line_offset)
     task.join()
     return executor.globals_ns