Exemplo n.º 1
0
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Embed and start an IPython kernel in a given scope.
    
    Parameters
    ----------
    module : ModuleType, optional
        The module to load into IPython globals (default: caller)
    local_ns : dict, optional
        The namespace to load into IPython user namespace (default: caller)
    
    kwargs : various, optional
        Further keyword args are relayed to the KernelApp constructor,
        allowing configuration of the Kernel.  Will only have an effect
        on the first embed_kernel call for a given process.
    
    """
    # get the app if it exists, or set it up if it doesn't
    if IPKernelApp.initialized():
        app = IPKernelApp.instance()
    else:
        app = IPKernelApp.instance(**kwargs)
        app.initialize([])

    # load the calling scope if not given
    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals
    
    app.kernel.user_module = module
    app.kernel.user_ns = local_ns
    app.start()
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Embed and start an IPython kernel in a given scope.

    If you don't want the kernel to initialize the namespace
    from the scope of the surrounding function,
    and/or you want to load full IPython configuration,
    you probably want `IPython.start_kernel()` instead.

    Parameters
    ----------
    module : ModuleType, optional
        The module to load into IPython globals (default: caller)
    local_ns : dict, optional
        The namespace to load into IPython user namespace (default: caller)

    kwargs : various, optional
        Further keyword args are relayed to the IPKernelApp constructor,
        allowing configuration of the Kernel.  Will only have an effect
        on the first embed_kernel call for a given process.
    """

    global embed_kernel_done
    if embed_kernel_done:
        return
    embed_kernel_done = True

    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals

    # Only import .zmq when we really need it
    from .embed import embed_kernel as real_embed_kernel
    real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
Exemplo n.º 3
0
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Embed and start an IPython kernel in a given scope.
    
    Parameters
    ----------
    module : ModuleType, optional
        The module to load into IPython globals (default: caller)
    local_ns : dict, optional
        The namespace to load into IPython user namespace (default: caller)
    
    kwargs : various, optional
        Further keyword args are relayed to the KernelApp constructor,
        allowing configuration of the Kernel.  Will only have an effect
        on the first embed_kernel call for a given process.
    
    """
    # get the app if it exists, or set it up if it doesn't
    if IPKernelApp.initialized():
        app = IPKernelApp.instance()
    else:
        app = IPKernelApp.instance(**kwargs)
        app.initialize([])

    # load the calling scope if not given
    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals

    app.kernel.user_module = module
    app.kernel.user_ns = local_ns
    app.start()
Exemplo n.º 4
0
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Embed and start an IPython kernel in a given scope.

    This code is an exact copy of the IPython.embed.embed_kernel function,
    except it uses our IPythonKernelApp subclass of IPKernelApp (so that we can
    customize the start-up error message about Ctrl-C not working because of a
    technicality in how IPython works)
    """
    # get the app if it exists, or set it up if it doesn't
    if IPythonKernelApp.initialized():
        app = IPythonKernelApp.instance()
    else:
        app = IPythonKernelApp.instance(**kwargs)
        app.initialize([])
        # Undo unnecessary sys module mangling from init_sys_modules.
        # This would not be necessary if we could prevent it
        # in the first place by using a different InteractiveShell
        # subclass, as in the regular embed case.
        main = app.kernel.shell._orig_sys_modules_main_mod
        if main is not None:
            sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main

    # load the calling scope if not given
    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals

    app.kernel.user_module = module
    app.kernel.user_ns = local_ns
    app.shell.set_completer_frame()
    app.start()
Exemplo n.º 5
0
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Embed and start an IPython kernel in a given scope.

    If you don't want the kernel to initialize the namespace
    from the scope of the surrounding function,
    and/or you want to load full IPython configuration,
    you probably want `IPython.start_kernel()` instead.

    Parameters
    ----------
    module : ModuleType, optional
        The module to load into IPython globals (default: caller)
    local_ns : dict, optional
        The namespace to load into IPython user namespace (default: caller)

    kwargs : various, optional
        Further keyword args are relayed to the IPKernelApp constructor,
        allowing configuration of the Kernel.  Will only have an effect
        on the first embed_kernel call for a given process.
    """

    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals

    # Only import .zmq when we really need it
    from ipykernel.embed import embed_kernel as real_embed_kernel
    real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
Exemplo n.º 6
0
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Based on ipykernel.embed.embed_kernel."""

    # get the app if it exists, or set it up if it doesn't
    if CoconutKernelApp.initialized():
        app = CoconutKernelApp.instance()
    else:
        app = CoconutKernelApp.instance(**kwargs)
        app.initialize([])
        # Undo unnecessary sys module mangling from init_sys_modules.
        # This would not be necessary if we could prevent it
        # in the first place by using a different InteractiveShell
        # subclass, as in the regular embed case.
        main = app.kernel.shell._orig_sys_modules_main_mod
        if main is not None:
            sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main

    # load the calling scope if not given
    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals

    app.kernel.user_module = module
    app.kernel.user_ns = local_ns
    app.shell.set_completer_frame()
    app.start()
Exemplo n.º 7
0
 def apply(self, func, ctx=None, **kwargs):
     tmp = dict(globals())
     if ctx is None:
         _, ctx = extract_module_locals(1)
     tmp.update(ctx)
     tmp.update(kwargs)
     tmp.update(DataOp.__dict__)
     res = eval(func, tmp, self.__dict__)
     return self.make_new(str(func), y=res)
Exemplo n.º 8
0
def embed_kernel(module=None, local_ns=None, **kwargs):
    """Embed and start an IPython kernel in a given scope.

    Parameters
    ----------
    module : ModuleType, optional
        The module to load into IPython globals (default: caller)
    local_ns : dict, optional
        The namespace to load into IPython user namespace (default: caller)

    kwargs : various, optional
        Further keyword args are relayed to the IPKernelApp constructor,
        allowing configuration of the Kernel.  Will only have an effect
        on the first embed_kernel call for a given process.

    """
    # get the app if it exists, or set it up if it doesn't
    if IPKernelApp.initialized():
        app = IPKernelApp.instance()
    else:
        print "app"
        app = IPKernelApp.instance(**kwargs)
        #app.initialize([])
        # Undo unnecessary sys module mangling from init_sys_modules.
        # This would not be necessary if we could prevent it
        # in the first place by using a different InteractiveShell
        # subclass, as in the regular embed case.

    # load the calling scope if not given
    (caller_module, caller_locals) = extract_module_locals(1)
    if module is None:
        module = caller_module
    if local_ns is None:
        local_ns = caller_locals

    print "eventloops.enable_gui"
    #ipykernel.eventloops.enable_gui('slicer', kernel=app.kernel)
    loop_slicer(app.kernel)
    print "initi"
    app.initialize(['python', '--gui=slicer'])
    app.kernel.user_module = module
    app.kernel.user_ns = local_ns
    app.shell.set_completer_frame()
    #loop_slicer(app.kernel)

    main = app.kernel.shell._orig_sys_modules_main_mod
    if main is not None:
        sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main

    print "app.start"
    app.start()
    return app
Exemplo n.º 9
0
    def run(self):

        if self.run_in_jupyter:
            from IPython.lib.guisupport import start_event_loop_qt4
            start_event_loop_qt4(app)
            return

        #if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        if not is_interactive():
            if self.ipkernel is not None:
                self.ipkernel.user_module, self.ipkernel.user_ns = extract_module_locals(
                    1)
                self.ipkernel.shell.set_completer_frame()
                self.ipkernel.start()
            else:
                QtGui.QApplication.instance().exec_()
Exemplo n.º 10
0
    def embed_kernel(module=None, local_ns=None, **kwargs):
        """Embed and start an IPython kernel in a given scope.

        Parameters
        ----------
        module : ModuleType, optional
            The module to load into IPython globals (default: caller)
        local_ns : dict, optional
            The namespace to load into IPython user namespace (default: caller)

        kwargs : various, optional
            Further keyword args are relayed to the IPKernelApp constructor,
            allowing configuration of the Kernel.  Will only have an effect
            on the first embed_kernel call for a given process.

        """
        # get the app if it exists, or set it up if it doesn't
        if IPKernelApp.initialized():
            app = IPKernelApp.instance()
        else:
            app = IPKernelApp.instance(**kwargs)
            app.initialize(sys.argv)
            # Undo unnecessary sys module mangling from init_sys_modules.
            # This would not be necessary if we could prevent it
            # in the first place by using a different InteractiveShell
            # subclass, as in the regular embed case.
            main = app.kernel.shell._orig_sys_modules_main_mod
            if main is not None:
                sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main

        # load the calling scope if not given
        (caller_module, caller_locals) = extract_module_locals(1)
        if module is None:
            module = caller_module
        if local_ns is None:
            local_ns = caller_locals

        app.kernel.user_module = None
        app.kernel.user_ns = None
        app.shell.set_completer_frame()

        if app.poller is not None:
            app.poller.start()

        app.kernel.start()
        return app
Exemplo n.º 11
0
def create_kernel(runid=None, do_run_notebook=False, **kwargs):
    if runid is None: runid = app.flags.runid
    ipkernel = OpaKernelApp.instance()
    ipkernel.runid = runid

    kwargs.update(current_pid=os.getpid())
    if do_run_notebook:
        kwargs = dict(kwargs)
        kwargs['runid'] = app.flags.runid
        threading.Thread(target=run_notebook, kwargs=kwargs).start()

    ipkernel.initialize(['python', '--matplotlib=qt'])
    par_locals, par_globals = cmisc.get_n2_locals_and_globals()
    par_globals = dict(par_globals)
    par_globals.update(par_locals)

    ipkernel.user_module, _ = extract_module_locals(1)
    ipkernel.user_ns = par_globals
    ipkernel.shell.set_completer_frame()

    time.sleep(1)
    ipkernel.start()
Exemplo n.º 12
0
    from lantz.drivers.keysight.e8364b import E8364B
    from A_Lab.Others.LantzAddOns import generateLantzParams
    from lantz.log import log_to_screen, DEBUG, INFO, CRITICAL
    log_to_screen(DEBUG)

    # Create the network analyzer object
    na = E8364B('TCPIP0::192.168.1.106::5025::SOCKET')
    na.initialize()

    #Create the UI
    win = NA_Win(network_analyzer = na, autoSave=False, standardPlugins=True)


    # Create a console widget, add it to the window and push the current
    # current namespace to it
    (current_module, current_ns) = extract_module_locals(depth=0)
    win.console.push(current_ns)
    # ------------------------------------------------------------------------------

    # Kill the splash screen to indicate everything is done loading
    splash.finish(win)

    # Begin the UI event loop
    _sys.exit(app.exec_())