[IPython-dev] Embed wxIPython/WxController in own app: How to access variables?

Gael Varoquaux gael.varoquaux@normalesup....
Thu Sep 25 06:33:48 CDT 2008


On Thu, Sep 25, 2008 at 12:55:40PM +0200, Fabian Wenzel wrote:
> today, I played a little bit with embedding the wxIPython and WxController shell into an own wxPySimpleApp as a widget in order to add some interaction/scripting techniques. In both shells I do not have access to the variables of my app, so I cannot control/script it. Using the shell that comes with wx.py.shell.Shell (the old PyCrust-shell) does not provide all the nice features IPython brings along, but variable access is possible.

> Does anybody have some information on how to accomplish this?

Yes. Well, I am not too sure what you are trying to accomplish. If you
simply want to access the namespace, it is the
wx_controller.shell.user_ns attribute: a dictionary object with the local
namespace.

Now if you want to pass in your own namespace (say it is a reference to a
shared dictionnary that you are using some place else in your
application), the WxController accepts an interpreter as a keyword
argument in its constructor. The interpreter also accepts a keyword
argument to the namespace, so you can have something like this:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
namespace = dict()

from IPython.frontend.wx.wx_frontend import WxController
from IPython.kernel.core.interpreter import Interpreter

interp = Interpreter(user_ns=namespace)

# Here you can play with your interpreter, eg evaluate commands in it,
# without an UI. This is your model, in the MVC pattern

# ...

my_widget = WxController(parent, size, ..., shell=interp)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Does this answer your question?

One remark: the Wx frontend code is pretty much a first cut
implementation. It has some rough edges, and I am very unhappy about some
design decisions. Hopefully I'll find time to improve it. I might break
some downstream code when fixing this code (specifically, I am not happy
at all with the poor MVC separation of the code, and the fact that the
representation model is not well-defined outside the view). Please do
consider this as a technology preview: it can be useful, but it is still
code in movement.

HTH,

Gaël


More information about the IPython-dev mailing list