简体   繁体   English

IPython qtconsole自定义横幅

[英]IPython qtconsole custom banner

I'm trying to set a custom banner for the IPython qtconsole (v3.0.0). 我正在尝试为IPython qtconsole(v3.0.0)设置自定义横幅。 In my profile configuration, I set c.IPythonWidget.banner = u'Custom Banner' , and then launch ipython qtconsole --profile=myprof . 在我的配置文件配置中,设置c.IPythonWidget.banner = u'Custom Banner' ,然后启动ipython qtconsole --profile=myprof What I get is my custom banner pre-pended to the regular banner: 我得到的是我的自定义横幅,前面是常规横幅:

Custom BannerPython 2.7.5 (default, Mar  9 2014, 22:15:05) 
Type "copyright", "credits" or "license" for more information.

IPython 3.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

IPython profile: myprof

In [1]: 

How can I get ONLY my banner to print, eg 我如何只能打印横幅广告,例如

Custom Banner

IPython profile: myprof

In [1]: 

Thanks. 谢谢。

It's not ideal, but I was able to suppress the default banner by setting default_gui_banner="" in the core/usage.py module in the IPython source. 这并不理想,但是我可以通过在IPython源代码的core/usage.py模块中设置default_gui_banner=""来抑制默认横幅。 I was not able to find any way to do this without modifying the source (which is ugly), so if anyone has a better way, I'm all ears. 如果不修改源代码,我将找不到任何方法(这很丑陋),因此,如果有人有更好的方法,我将不知所措。

The message you don't want is printed as part of the kernel's banner (which it gets from its shell). 不需要的消息被打印为内核横幅的一部分(从其外壳获取)。 I was able to avoid printing it by setting the shell's banner1 attribute to an empty string before using/connecting to the kernel elsewhere: 通过在其他地方使用/连接到内核之前,将shell的banner1属性设置为空字符串,可以避免打印它:

from IPython.qt.inprocess import QtInProcessKernelManager
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel_manager.kernel.shell.banner1 = ""

I've only worked with/tested this with the IPython Qt stuff, so this might not work for other kernels. 我只使用IPython Qt东西进行了测试,因此可能不适用于其他内核。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM