好的,这段代码似乎可以解决问题(即,它在Qt小部件中放置了非阻塞的ipython解释器,可以将其嵌入到其他小部件中)。传递来
terminal_widget添加到小部件名称空间的关键字
import atexitfrom IPython.zmq.ipkernel import IPKernelAppfrom IPython.lib.kernel import find_connection_filefrom IPython.frontend.qt.kernelmanager import QtKernelManagerfrom IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidgetfrom IPython.utils.traitlets import TraitErrorfrom PyQt4 import QtGui, QtCoredef event_loop(kernel): kernel.timer = QtCore.QTimer() kernel.timer.timeout.connect(kernel.do_one_iteration) kernel.timer.start(1000*kernel._poll_interval)def default_kernel_app(): app = IPKernelApp.instance() app.initialize(['python', '--pylab=qt']) app.kernel.eventloop = event_loop return appdef default_manager(kernel): connection_file = find_connection_file(kernel.connection_file) manager = QtKernelManager(connection_file=connection_file) manager.load_connection_file() manager.start_channels() atexit.register(manager.cleanup_connection_file) return managerdef console_widget(manager): try: # Ipython v0.13 widget = RichIPythonWidget(gui_completion='droplist') except TraitError: # IPython v0.12 widget = RichIPythonWidget(gui_completion=True) widget.kernel_manager = manager return widgetdef terminal_widget(**kwargs): kernel_app = default_kernel_app() manager = default_manager(kernel_app) widget = console_widget(manager) #update namespace kernel_app.shell.user_ns.update(kwargs) kernel_app.start() return widgetapp = QtGui.QApplication([])widget = terminal_widget(testing=123)widget.show()app.exec_()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)