Esempio n. 1
0
 def _exec_code(self, code):
     """执行代码并重定向代码的 stdout/stderr"""
     output = io.StringIO()
     sys.stderr = output
     sys.stdout = output
     try:
         obj = compile(code, '<string>', 'single')
         fuoexec(obj)
     except Exception as e:
         print(str(e))
     finally:
         sys.stderr = sys.__stderr__
         sys.stdout = sys.__stdout__
     self.show_msg(output.getvalue() or 'No output.', force=True)
Esempio n. 2
0
    def _exec_code(self, code):
        """执行代码并重定向代码的 stdout/stderr"""
        output = io.StringIO()
        sys.stderr = output
        sys.stdout = output
        try:
            obj = compile(code, '<string>', 'single')
            fuoexec(obj)
        except Exception as e:
            print(str(e))
        finally:
            sys.stderr = sys.__stderr__
            sys.stdout = sys.__stdout__

        text = output.getvalue() or 'No output.'
        if not text:
            return
        self._set_mode('msg')
        self.setText(text)
        self._timer.start(1000)
        self._app.show_msg(text)
Esempio n. 3
0
 def exec_(self, code):
     obj = compile(code, '<string>', 'exec')
     fuoexec(obj)