栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将IPython Qt控制台嵌入PyQt应用程序

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将IPython Qt控制台嵌入PyQt应用程序

好的,这段代码似乎可以解决问题(即,它在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_()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596351.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号