예제 #1
0
    def __init__(self, **kwargs):

        MetaKernel.__init__(self, **kwargs)
        setStyle()
        self.ioHandler = GetIOHandler()
        self.Executor = GetExecutor()
        self.Declarer = GetDeclarer()  #required for %%cpp -d magic
        self.ACLiC = invokeAclic
        self.magicloader = MagicLoader(self)
        self.completer = CppCompleter()
        self.completer.activate()
예제 #2
0
    def __init__(self, **kwargs):

        MetaKernel.__init__(self, **kwargs)
        setStyle()
        self.ioHandler = GetIOHandler()
        self.Executor = GetExecutor()
        self.Declarer = GetDeclarer()  #required for %%cpp -d magic
        self.ACLiC = invokeAclic
        self.magicloader = MagicLoader(self)
        self.parser = Parser(self.identifier_regex, self.func_call_regex,
                             self.magic_prefixes, self.help_suffix)
        self.completer = CppCompleter()
        self.completer.activate()
예제 #3
0
파일: rootkernel.py 프로젝트: lihe8811/root
    def __init__(self,**kwargs):

        MetaKernel.__init__(self,**kwargs)
        LoadDrawer()
        setStyle()
        self.ioHandler = GetIOHandler()
        self.Executor  = GetExecutor()
        self.Declarer  = GetDeclarer()#required for %%cpp -d magic
        self.ACLiC     = invokeAclic
        self.magicloader = MagicLoader(self)
        self.parser = Parser(self.identifier_regex, self.func_call_regex,
                             self.magic_prefixes, self.help_suffix)
        self.completer = CppCompleter()
        self.completer.activate()
예제 #4
0
class ROOTKernel(MetaKernel):
    # These two regexes are considered by the parser of the metakernel
    # there is no need to create one explicitly
    identifier_regex = r'(?:\w(?:\w|\.|->|::|\d)*)'
    func_call_regex = r'(?:\w(?:(?:\w|\.|->|::|\d))*)\([^\)\()]*\Z'

    implementation = 'ROOT'
    implementation_version = '1.0'
    language = 'c++'
    language_version = '0.1'
    language_info = {
        'name': 'c++',
        'codemirror_mode': 'text/x-c++src',
        'mimetype': ' text/x-c++src',
        'file_extension': '.C'
    }
    banner = "ROOT Kernel"

    def __init__(self, **kwargs):

        MetaKernel.__init__(self, **kwargs)
        setStyle()
        self.ioHandler = GetIOHandler()
        self.Executor = GetExecutor()
        self.Declarer = GetDeclarer()  #required for %%cpp -d magic
        self.ACLiC = invokeAclic
        self.magicloader = MagicLoader(self)
        self.completer = CppCompleter()
        self.completer.activate()

    def __del__(self):
        self.Executor.Stop()
        self.Declarer.Stop()

    def get_completions(self, info):
        return self.completer._completeImpl(info['code'])

    def print_output(self, handler):
        streamDicts = handler.GetStreamsDicts()
        for streamDict in filter(lambda d: None != d, streamDicts):
            self.send_response(self.iopub_socket, 'stream', streamDict)

    def do_execute_direct(self, code, silent=False):

        if not code.strip():
            return

        status = 'ok'
        try:
            RunAsyncAndPrint(self.Executor, code.encode('utf8'),
                             self.ioHandler, self.print_output, silent, .1)

            drawers = GetDrawers()
            for drawer in drawers:
                for dobj in drawer.GetDrawableObjects():
                    self.Display(dobj)

        except KeyboardInterrupt:
            ROOT.gROOT.SetInterrupt()
            status = 'interrupted'
            self.ioHandler.EndCapture()
        if not silent:
            self.print_output(self.ioHandler)

        traceback = None
        reply = {
            'status': status,
            'execution_count': self.execution_count,
            'payload': [],
            'user_expressions': {},
        }

        if status == 'interrupted':
            pass
        elif status == 'error':
            err = {
                'ename': 'ename',
                'evalue': 'evalue',
                'traceback': traceback,
            }
            self.send_response(self.iopub_socket, 'error', err)
            reply.update(err)
        elif status == 'ok':
            pass
        else:
            raise ValueError("Invalid status: %r" % status)
예제 #5
0
파일: rootkernel.py 프로젝트: lihe8811/root
class ROOTKernel(MetaKernel):
    implementation = 'ROOT'
    implementation_version = '1.0'
    language = 'c++'
    language_version = '0.1'
    language_info = {'name': 'c++',
                     'codemirror_mode': 'text/x-c++src',
                     'mimetype': ' text/x-c++src',
                     'file_extension': '.C'}
    banner = "CERN ROOT Kernel %s" % ROOT.gROOT.GetVersion()

    def __init__(self,**kwargs):

        MetaKernel.__init__(self,**kwargs)
        LoadDrawer()
        setStyle()
        self.ioHandler = GetIOHandler()
        self.Executor  = GetExecutor()
        self.Declarer  = GetDeclarer()#required for %%cpp -d magic
        self.ACLiC     = invokeAclic
        self.magicloader = MagicLoader(self)
        self.parser = Parser(self.identifier_regex, self.func_call_regex,
                             self.magic_prefixes, self.help_suffix)
        self.completer = CppCompleter()
        self.completer.activate()


    def get_completions(self, info):
        if _debug :Debug(info)
        return self.completer._completeImpl(info['code'])

    def do_execute_direct(self, code, silent=False):

        if not code.strip():
            return

        status = 'ok'
        traceback = None
        std_out=""
        std_err=""
        try:
            self.ioHandler.clear()
            self.ioHandler.InitCapture()
            root_status = self.Executor(str(code))
            self.ioHandler.EndCapture()

            std_out = self.ioHandler.getStdout()
            std_err = self.ioHandler.getStderr()

            canvaslist = ROOT.gROOT.GetListOfCanvases()
            if canvaslist:
                for canvas in canvaslist:
                    if canvas.IsDrawn():
                        self.drawer = CanvasDrawer(canvas)
                        if self.drawer._canJsDisplay():
                            self.Display(HTML(self.drawer.getJsCode()))
                        else:
                            self.Display(self.drawer.getPngImage())
                        canvas.ResetDrawn()


        except KeyboardInterrupt:
            self.interpreter.gROOT.SetInterrupt()
            status = 'interrupted'
            self.ioHandler.EndCapture()
            std_out = self.ioHandler.getStdout()
            std_err = self.ioHandler.getStderr()
        if not silent:
            ## Send output on stdout
            stream_content_stdout = {'name': 'stdout', 'text': std_out}
            self.send_response(self.iopub_socket, 'stream', stream_content_stdout)
            if std_err != "":
                stream_content_stderr = {'name': 'stderr', 'text': std_err}
                self.send_response(self.iopub_socket, 'stream', stream_content_stderr)

        reply = {'status': status,
                'execution_count': self.execution_count,
                'payload': [],
                'user_expressions': {},
                }

        if status == 'interrupted':
            pass
        elif status == 'error':
            err = {
                'ename': 'ename',
                'evalue': 'evalue',
                'traceback': traceback,
            }
            self.send_response(self.iopub_socket, 'error', err)
            reply.update(err)
        elif status == 'ok':
            pass
        else:
            raise ValueError("Invalid status: %r" % status)