[IPython-dev] wxPython console
Thu Nov 3 09:27:31 CDT 2011
On 3 November 2011 13:51, Emmanuel Bacry <email@example.com>wrote:
> You mean use it directly within a wx main loop right ?
Yes - it's just Python methods that you call to run code and so on. I'm
assuming your widget takes care of actually letting the user type things in.
> Yes I got that already, however how do I redirect output ?
In Python, there are two kinds of output: firstly from "print x", for which
you can simply redirect stdout - replace sys.stdout with an object with a
.write() method, which will capture strings written to it and display them
in your console.
Secondly, if you simply enter "x" at a prompt, IPython displays the value
of x at an "Out [n]:" prompt. In such cases, Python calls sys.displayhook.
This is called with the object itself, rather than its repr, so you can
produce more complex displays. This is how we pretty-print datastructures,
and also how the notebook can display rich objects like youtube videos.
Have a look at IPython.core.displayhook to see our implementation of this.
If you replace the displayhook attribute of an InteractiveShell object, it
will take care of using that displayhook when you call run_cell.
> For complete : it actually does exactly what happens when I hit the tab key
> on the ipython console ?
It provides the machinery to find the completions for a given input. The
frontend has to take care of catching the tab key (or some other shortcut)
and applying or displaying the returned completion(s).
> How do I manage multiple lines command ?
You can use an InputSplitter to determine if another line is acceptable -
have a look at the code for the terminal frontend:
> Le me be clear : how do I know a command is not complete so I should print
> a prompt with a tab ?
> Is there a method that deals with managing all that for me ?
I'm not quite sure what you mean with this part, but hopefully what I've
described above will help.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev