[IPython-dev] Embed wxIPython/WxController in own app: How to access variables?
Thu Sep 25 08:39:44 CDT 2008
thanks for your fast reply - I tried the code you posted in your answer but still could not get access to variables. So I believe I did not understand all details of your answer, and that may very well be because you were not sure what I was trying to accomplish. So here is some "dummy" example code:
# Some class here...
self.member = "SOMETHING"
# Some function here...
instance.member = "SOMETHINGELSE"
# Main program
if __name__ == "__main__":
from IPython.frontend.wx.wx_frontend import WxController
from IPython.kernel.core.interpreter import Interpreter
# These variable should be accessible from the shell below
testinstance = Testclass()
# Generate frame
app = wx.PySimpleApp()
frame = wx.Frame(None,wx.ID_ANY)
# Generate shell child
shell = WxController(frame,wx.ID_ANY)
I did not check the code for errors, also some things are definitely missing
(sizers etc., I just typed it into this e-mail), but the idea is that
in the shell that I create above, I would like to type something like
as both, the function and the instance of Testclass() have been defined before. In PyCrust, this is possible.
Maybe I just did not get the meaning of the namespace and dictionary?
> 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
> 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.
Psssst! Schon vom neuen WEB.DE MultiMessenger gehört?
Der kann`s mit allen: http://www.produkte.web.de/messenger/?did=3123
More information about the IPython-dev