<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
I don’t really understand what you are trying to achieve, but the ‘user_ns’ dictionary isn’t an isolated namespace - it’s the namespace that is used by the console, and I would have thought you would have to do some kind of injection to add other objects from
 within the application. The following code is added shortly after the example I gave in the MainWindow class:
<div><br>
</div>
<div>
<div>        self.user_ns['plotview'] = self.plotview</div>
<div>        self.user_ns['treeview'] = self.treeview</div>
<div>        self.user_ns['mainwindow'] = self</div>
<div><br>
</div>
<div>so that other parts of the application are accessible within the console. You could add all the items in the globals() dictionary if you wanted:</div>
<div><br>
</div>
<div>
<div>        for k, v in globals().items():</div>
<div>            self.user_ns[k] = v</div>
</div>
<div><br>
</div>
<div>which is presumably equivalent to what Matthias suggested, but you would still have to inject new variables as they are created. </div>
<div><br>
</div>
<div>Ray</div>
<div><br>
<div>
<div>On Dec 27, 2014, at 5:24 PM, Darren Dale <<a href="mailto:dsdale24@gmail.com">dsdale24@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">I passed None because <a href="http://ipython.org/ipython-doc/stable/api/generated/IPython.terminal.embed.html?highlight=embed#IPython.terminal.embed.InteractiveShellEmbed">
http://ipython.org/ipython-doc/stable/api/generated/IPython.terminal.embed.html?highlight=embed#IPython.terminal.embed.InteractiveShellEmbed</a> states: "If given as None, they are automatically taken from the scope where the shell was called, so that program
 variables become visible." That is precisely what I want, but can't figure out how to do it with the Qt console.
<div><br>
</div>
<div>I don't want to inject variables to an isolated namespace, I want the console to share the application's namespace.</div>
<br>
<div class="gmail_quote">On Sat Dec 27 2014 at 6:02:54 PM Matthias Bussonnier <<a href="mailto:bussonniermatthias@gmail.com">bussonniermatthias@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br>
<div>Le 27 déc. 2014 à 23:43, Darren Dale <<a href="mailto:dsdale24@gmail.com" target="_blank">dsdale24@gmail.com</a>> a écrit :</div>
</div>
<div style="word-wrap:break-word"><br>
<blockquote type="cite">Thanks Ray. Unfortunately, I want the ipython console's namespace to reflect that of the application in which it is embedded, not a specific widget. There is an example that appears to do this at <a href="https://github.com/ipython/ipython/blob/master/examples/Embedding/embed_function.py" target="_blank">https://github.com/ipython/ipython/blob/master/examples/Embedding/embed_function.py</a>
 , but I'm trying to do the same with the Qt widget. At the top of my main gui module, I do:<br>
<div><br>
</div>
<div>
<div>try:</div>
<div>    from IPython.qt.console.rich_ipython_widget import RichIPythonWidget</div>
<div>    from IPython.qt.inprocess import QtInProcessKernelManager</div>
<div><br>
</div>
<div>    # Create an in-process kernel</div>
<div>    kernel_manager = QtInProcessKernelManager(user_ns=None)</div>
</div>
</blockquote>
<div><br>
</div>
</div>
<div style="word-wrap:break-word">
<div>Don't you want to just pass `globals()` instead of `None` here? </div>
<div>user_ns kwarg here is **the mutable namespace** (i.e. a dict) you want your kernel to work on.  If you pass None, </div>
<div>it will create a new empty object for you. If you pass `{"a":1}` then your kernel will see a variable `a` with a value of 1 (mutable) </div>
<div><br>
</div>
<div>So I guess what you want to pass here is either globals(), locals(), or a dict you constructed yourself, </div>
<div>from the bit you want available. </div>
<div><br>
</div>
<div>You can also do as raymond said, and inject things into user_ns after getting the reference to it. </div>
</div>
<div style="word-wrap:break-word">
<div>-- </div>
<div>M</div>
<div><br>
</div>
</div>
______________________________<u></u>_________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/<u></u>listinfo/ipython-dev</a><br>
</blockquote>
</div>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
http://mail.scipy.org/mailman/listinfo/ipython-dev<br>
</blockquote>
</div>
<br>
<div apple-content-edited="true">-- <br>
Ray Osborn, Senior Scientist<br>
Materials Science Division<br>
Argonne National Laboratory<br>
Argonne, IL 60439, USA<br>
Phone: +1 (630) 252-9011<br>
Email: <a href="mailto:ROsborn@anl.gov">ROsborn@anl.gov</a><br>
<br>
</div>
<br>
</div>
</div>
</body>
</html>