[IPython-dev] Need help from Ipython guru...

Fernando Perez fperez.net at gmail.com
Wed Dec 5 12:46:58 EST 2007


Hey Laurent,

sorry for a rather curt reply right now.  I'm really happy to see you
doing this, so thanks a lot!  I'm extremely swamped with a python
workshop deadline fast approaching, so I won't be able to properly
help until next  week.  Very briefly...

On Dec 5, 2007 6:51 AM, Laurent Dufrechou <Laurent.Dufrechou at free.fr> wrote:
>
> Hi IPythoners,
>
> I'm trying to do a litttle wx widget for ipyton.(I've posted some version on
> the list last day)
> Currently all is working quite well, but I'm stuck to a bug that I can't
> handle.
> If I write:
> "import smtplib"
> "smtplib.re?"
> Then ipython shell call the ? magic function and because the text is too
> long, it is stuck to a getch inside genutils…
>  >Term.cout.write('---Return to continue, q to quit--- ')
>  > ans = msvcrt.getch()
>
> Too bad I can't do anything.
> Is there a way to say to ipython:
> "Hey guy! Give me the full text I will split it by myself and please don't
> ask me to push a key!"
> Perhaps there is a secret var to set the line before breaking text?
> Or pehaps I couls define my pager? But then how to say to ipython, that my
> pager is this one...?
> I've seen that previous guy set os.environ['TERM'] = 'dumb' if this the
> reason why dump_pager is called?

Yes, but you can define your own pager via environ['PAGER'].  That
should allow you to give ipython your own paging routine.  Look in
genutils for the pager code...

> Other question:
> When i go back in history, previous '?' key appears like this:
> ex: smtplib?
> appears as: "#?smtplib"
> Is the # ok? if yes, is there any reason why the history return that?
> (to get history I do: rv =
> self.IP.user_ns['In'][self.history_level].strip('\n'))

Look at the 'raw history' instead, which has exactly what was typed
without translation:

In [7]: print __IP.input_hist_raw
['\n', u'x=1\n', u'x?\n', u'In\n', u'__IP.raw_input\n',
u'__IP.*hist*?\n', u'__IP.input_hist_raw\n', u'print
__IP.input_hist_raw\n']


> Another question for gurus:
> Currently to embbed the Ipython shell, I've reused the code from gtk Ipython
> widget guy:
> "
> self.term = IPython.genutils.IOTerm(cin=cin, cout=cout, cerr=cerr)
> os.environ['TERM'] = 'dumb'
>  excepthook = sys.excepthook
>  self.IP = IPython.Shell.make_IPython(
>       argv,user_ns=user_ns,
>       user_global_ns=user_global_ns,
>       embedded=True,
>       shell_class=IPython.Shell.InteractiveShell)
>  self.IP.system = lambda cmd: self.shell(self.IP.var_expand(cmd),
>                                             header='IPython system call: ',
>
> verbose=self.IP.rc.system_verbose) "
>
> Is this the best way to embed ipython nowadays.
> I mean I've seen that there is some classes:
> IPShellEmbed for example.
> Currently the design of the widget is limited by the fact that the ipython
> shell is not in a different process or thread, so if it locks, it locks all
> the app…
> Is there a best way to do embed an ipython shell then my current way?

Yup, that's the stuff which is currently in raw, in-progress mode in
the ipython1 repo, that Gael mentioned.  I hope to have time to finish
it in a few months, but it won't be until early next year at best.
This end-of-year is already booked solid with a py4science workshop
and a numpy/scipy sprint.

In the meantime, it may be possible to finish up your current approach
to the point of usability, while we complete that work.

But again, many thanks for pitching in with this, and keep bugging us.
We'll reply :)

Cheers,

f



More information about the IPython-dev mailing list