Skip to content
Snippets Groups Projects
Commit 5c4a4cb2 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Allow additional messeages on the IPython banner.

Refs #21251
parent b00baee7
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,15 @@ from mantidqt.utils.async import blocking_async_task
class InProcessIPythonConsole(RichIPythonWidget):
def __init__(self, *args, **kwargs):
"""
A constructor matching that of RichIPythonWidget
:param args: Positional arguments passed directly to RichIPythonWidget
:param kwargs: Keyword arguments. The following are used by this
widget:
- banner_extra: An additinal string to append to the default banner
"""
# remove our arguments
banner_extra = kwargs.pop("banner_extra", "")
super(InProcessIPythonConsole, self).__init__(*args, **kwargs)
# create an in-process kernel
......@@ -51,6 +60,10 @@ class InProcessIPythonConsole(RichIPythonWidget):
shell = kernel.shell
shell.run_code = async_wrapper(shell.run_code, shell)
# custom banner
if banner_extra:
self.banner += "\n" + banner_extra
# attach channels and start kenel
kernel_client = kernel_manager.client()
kernel_client.start_channels()
......
......@@ -34,6 +34,11 @@ class InProcessIPythonConsoleTest(unittest.TestCase):
self.assertTrue(hasattr(widget, "kernel_manager"))
self.assertTrue(hasattr(widget, "kernel_client"))
def test_banner_extra_updates_banner(self):
widget = InProcessIPythonConsole(banner_extra="foo")
self.assertTrue(widget.banner.endswith("foo"))
self.assertTrue(widget.banner.startswith("Python"))
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment