Beispiel #1
0
    def __init__(self, app, imports=None, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)

        self.app = app
        qtapp = self.app.getApp()
        kernel = InProcessKernel(gui='qt5')
        self.kernel = kernel
        self.shell = kernel.shell

        # Populate the kernel's namespace.
        kernel.shell.push({'api': self.app.api, 'self': self.app, 'shell': kernel.shell})

        for plugin in self.app.pm.plugins:
            self.shell.push({plugin.name: plugin})

        self.push = kernel.shell.push
        self.ex = kernel.shell.ex


        # Create a kernel manager for the frontend and register it with the kernel.
        km = QtInProcessKernelManager(kernel=kernel)
        km.start_channels()
        kernel.frontends.append(km)

        # Create the Qt console frontend.
        control = RichIPythonWidget()
        control.exit_requested.connect(qtapp.quit)
        control.kernel_manager = km
        control.show()

        self.widget = control

        self.imports = [
            'from PyQt4.QtCore import *',
            'from PyQt4.QtGui import *',
            'import json',
            'import os, sys'
        ]
        if imports is not None and type(imports) is list:
            self.imports.extend(imports)
        for import_line in self.imports:
            kernel.shell.ex(import_line)



        self.setLayout(QVBoxLayout())
        self.layout().addWidget(control)
#        self.addTab(control, 'Main')

        control.clear()

        self.app.api.echo = self.echo
        self.app.api.echoServerOutput = self.echoServerOutput
        self.app.api.setIPInput = self.set_input
        self.app.api.pushToIP = self.shell.push
        self.app.api.setIPCursor = self.setCursorPos
Beispiel #2
0
def main():
    """Start kernel manager, create window, run app event loop, auto execute some code
    in user namespace. Adapted from IPython example in:
    docs/examples/frontend/inprocess_qtconsole.py"""
    app = guisupport.get_app_qt4()

    if INPROCESS:
        from IPython.kernel.inprocess.ipkernel import InProcessKernel
        from IPython.frontend.qt.inprocess_kernelmanager import QtInProcessKernelManager
        kernel = InProcessKernel(gui='qt4')
        km = QtInProcessKernelManager(kernel=kernel)
        kernel.frontends.append(km)
    else:
        from IPython.frontend.qt.kernelmanager import QtKernelManager
        km = QtKernelManager()
        km.start_kernel()
    km.start_channels()

    neuropywindow = NeuropyWindow()
    ipw = neuropywindow.ipw
    config_ipw(ipw)
    ipw.exit_requested.connect(app.quit)
    ipw.kernel_manager = km
    neuropywindow.show()

    # execute some code directly, note the output appears at the system command line:
    #kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)')
    # execute some code through the frontend (once the event loop is
    # running). The output appears in the ipw:
    do_later(ipw.execute_file, 'startup.py', hidden=True)
    # import division in startup.py doesn't seem to work, execute directly:
    do_later(ipw.execute, "from __future__ import division", hidden=True)
    do_later(ipw.execute_file, 'globals.py', hidden=True)

    guisupport.start_event_loop_qt4(app)
def main():
    app = guisupport.get_app_qt4()

    # Create a kernel. 
    #
    # Setting the GUI is not necessary for the normal operation of the kernel,
    # but it is used for IPython GUI's integration, particularly in pylab. By
    # default, the inline backend is used, which is safe under all toolkits.
    #
    # WARNING: Under no circumstances should another GUI toolkit, like wx, be
    # used when running a Qt application. This will lead to unexpected behavior,
    # including segfaults.
    kernel = InProcessKernel(gui='qt4')

    # Populate the kernel's namespace.
    kernel.shell.push({'x': 0, 'y': 1, 'z': 2})

    # Create a kernel manager for the frontend and register it with the kernel.
    km = QtInProcessKernelManager(kernel=kernel)
    km.start_channels()
    kernel.frontends.append(km)

    # Create the Qt console frontend.
    control = RichIPythonWidget()
    control.exit_requested.connect(app.quit)
    control.kernel_manager = km
    control.show()

    # Execute some code directly. Note where the output appears.
    kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)')

    # Execute some code through the frontend (once the event loop is
    # running). Again, note where the output appears.
    do_later(control.execute, '%who')

    guisupport.start_event_loop_qt4(app)