示例#1
0
    def evaluate_action(self, *args):
        """ Evaluate the expression in the input console """
        output_file = open('interpreter_output', 'w+')
        original_stdout = sys.stdout
        sys.stdout = output_file
        expr = self.input_console.get()
        # while expr and (expr[0] == "\n"):
        #     expr = expr[1:]
        local_interpreter = False
        if self.interpreter is None:
            self.interpreter = PyInterpreter(self.app.mode, "<<console>>", expr)
            local_interpreter = True
        ok, report = self.interpreter.run_evaluation(expr)

        if ok:
            self.input_history.record(expr)

        self.input_console.delete(0, END)
        #self.input_console.config(height=1)

        self.write_report(ok, report)

        sys.stdout = original_stdout
        output_file.close()

        if local_interpreter:
            self.interpreter = None
示例#2
0
    def run(self, filename):
        """ Run the program in the current editor : execute, print results """
        # Reset the output first
        self.reset_output()
        # A new PyInterpreter is created each time code is run
        # It is then kept for other actions, like evaluation
        self.interpreter = PyInterpreter(self.app.mode, filename)
        # Change the output during execution
        output_file = open('interpreter_output', 'w+')
        original_stdout = sys.stdout
        sys.stdout = output_file
        ok, report = self.interpreter.execute()

        self.write_report(ok, report)

        sys.stdout = original_stdout
        output_file.close()
        # Enable or disable the evaluation bar according to the execution status
        if ok:
            pass
            #self.switch_input_status(True)
        else:
            pass