예제 #1
0
def main():
    # Print the ID of the main process
    print_process_id()

    app = guisupport.get_app_qt4()

    # Create an in-process kernel
    # >>> print_process_id()
    # will print the same process ID as the main process
    kernel_manager = QtInProcessKernelManager()
    kernel_manager.start_kernel()
    kernel = kernel_manager.kernel
    kernel.gui = 'qt4'
    kernel.shell.push({'foo': 43, 'print_process_id': print_process_id})

    kernel_client = kernel_manager.client()
    kernel_client.start_channels()

    def stop():
        kernel_client.stop_channels()
        kernel_manager.shutdown_kernel()
        app.exit()

    control = RichIPythonWidget()
    control.kernel_manager = kernel_manager
    control.kernel_client = kernel_client
    control.exit_requested.connect(stop)
    control.show()

    guisupport.start_event_loop_qt4(app)
예제 #2
0
파일: terminal.py 프로젝트: averrin/demesne
    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
예제 #3
0
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)