[IPython-dev] embedding ipython, namespace question

Osborn, Raymond rosborn at anl.gov
Sat Dec 27 16:42:32 EST 2014


We synchronize an IPython shell to a PySide QTreeView in NeXpy, an application for viewing and analyzing HDF5 files (http://nexpy.github.io/nexpy/). If it’s any help, you can find the source code at https://github.com/nexpy/nexpy, which was, I think, based on the same example you cite. The application is initialized in nexpy/gui/consoleapp.py, which subclasses IPythonConsoleApp, but the main PySide windows are defined in mainwindow.py.

Here are some of the critical lines in mainwindow.py:

class MainWindow(QtGui.QMainWindow):

    def __init__(self, app, tree, config=None):

        self.console = RichIPythonWidget(config=self.config, parent=rightpane)
        self.console.kernel_manager = QtInProcessKernelManager(config=self.config)
        self.console.kernel_manager.start_kernel()
        self.console.kernel_manager.kernel.gui = 'qt4'
        self.console.kernel_client = self.console.kernel_manager.client()
        self.console.kernel_client.start_channels()

        self.shell = self.console.kernel_manager.kernel.shell
        self.user_ns = self.console.kernel_manager.kernel.shell.user_ns

The last line makes the dictionary of the IPython shell, i.e., user_ns, available to the rest of the GUI. That must be what the “pass a user_ns” refers to.

Best regards,
Ray

On Dec 27, 2014, at 2:31 PM, Darren Dale <dsdale24 at gmail.com<mailto:dsdale24 at gmail.com>> wrote:

Hello,

(sorry for double-posting on ipython-user. I was advised to post here instead.)

I'm working on embedding an ipython qtconsole in my applilcation as a dock widget. The https://github.com/ipython/ipython/blob/master/examples/Embedding/inprocess_qtconsole.py example was a helpful first step. As variables are created or updated in the main application, I'd like to be able to inspect them in the qtconsole. Is it possible for the qtconsole's namespace to be shared or linked with that of the main application? It seems like this should be possible, based on the documentation for http://ipython.org/ipython-doc/1/api/generated/IPython.terminal.embed.html#IPython.terminal.embed.InteractiveShellEmbed . I'm creating my kernel and client at the beginning of my module, and then wiring up the widget when my application's main window is about to show. But if I run `dir()` in the embedded ipython qt console, the list is identical to what I get if I run `dir()` in the standalone `ipython qtconsole` program.

I've seen some comments along the lines of "pass a user_ns", but I have no idea what this means, or specifically how to do it.

Thanks,
Darren
_______________________________________________
IPython-dev mailing list
IPython-dev at scipy.org<mailto:IPython-dev at scipy.org>
http://mail.scipy.org/mailman/listinfo/ipython-dev

--
Ray Osborn, Senior Scientist
Materials Science Division
Argonne National Laboratory
Argonne, IL 60439, USA
Phone: +1 (630) 252-9011
Email: ROsborn at anl.gov<mailto:ROsborn at anl.gov>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141227/895860ce/attachment.html>


More information about the IPython-dev mailing list