summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-07 22:24:30 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-07 22:24:30 -0500
commit68326c0a5c242c22be81428c0bcd50b0cc32bf72 (patch)
treefcb819a804efef573c62ccdcf46e2b8a01bac2ee
parentf1940dcf474eec60c0459ad29ba9df2590209657 (diff)
downloadcmd2-git-68326c0a5c242c22be81428c0bcd50b0cc32bf72.tar.gz
Added ability to use ipy for embedded IPython to submenus.py example
This is simply to allow introspection on self for debug and development
-rw-r--r--examples/submenus.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/examples/submenus.py b/examples/submenus.py
index 6fcbb307..52f26e08 100644
--- a/examples/submenus.py
+++ b/examples/submenus.py
@@ -10,9 +10,11 @@ of the submenu. Nesting of the submenus is done with the cmd2.AddSubmenu() decor
"""
-
from __future__ import print_function
+import sys
+
import cmd2
+from IPython import embed
class ThirdLevel(cmd2.Cmd):
@@ -48,6 +50,16 @@ class SecondLevel(cmd2.Cmd):
self.top_level_attr = None
self.second_level_attr = 987654321
+ def do_ipy(self, arg):
+ """Enters an interactive IPython shell.
+
+ Run python code from external files with ``run filename.py``
+ End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``.
+ """
+ banner = 'Entering an embedded IPython shell type quit() or <Ctrl>-d to exit ...'
+ exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0])
+ embed(banner1=banner, exit_msg=exit_msg)
+
def do_say(self, line):
print("You called a command in SecondLevel with '%s'. "
"It has access to top_level_attr: %s" % (line, self.top_level_attr))
@@ -72,6 +84,16 @@ class TopLevel(cmd2.Cmd):
self.prompt = 'TopLevel '
self.top_level_attr = 123456789
+ def do_ipy(self, arg):
+ """Enters an interactive IPython shell.
+
+ Run python code from external files with ``run filename.py``
+ End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``.
+ """
+ banner = 'Entering an embedded IPython shell type quit() or <Ctrl>-d to exit ...'
+ exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0])
+ embed(banner1=banner, exit_msg=exit_msg)
+
def do_say(self, line):
print("You called a command in TopLevel with '%s'. "
"TopLevel has attribute top_level_attr=%s" % (line, self.top_level_attr))