コード例 #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
ファイル: python_console_ipython.py プロジェクト: hlamer/kate
def init_ipython():
    """
    Encapsulate Kernel creation logic: Only the kernel client, manager and shell are exposed
    This is in order to ensure interoperability between major IPython changes
    """
    if ipython_1:
        manager = QtInProcessKernelManager()
        manager.start_kernel()
        manager.kernel.gui = 'qt4'
        shell = manager.kernel.shell
        shell.run_cell('%pylab inline')
        client = manager.client()
        client.start_channels()
    else:
        def event_loop(kernel):
            kernel.timer = QTimer()
            kernel.timer.timeout.connect(kernel.do_one_iteration)
            kernel.timer.start(1000 * kernel._poll_interval)

        kernel_app = IPKernelApp.instance()
        kernel_app.initialize(['python', '--pylab=qt'])     # at this point, print() won’t work anymore
        kernel_app.kernel.eventloop = event_loop

        connection_file = find_connection_file(kernel_app.connection_file)
        manager = QtKernelManager(connection_file=connection_file)
        manager.load_connection_file()
        manager.start_channels()

        kernel_app.start()

        client = None
        shell = kernel_app.shell

    return client, manager, shell