[IPython-dev] Status of IPython+GUI+Threads+PyOS_InputHook

Ville M. Vainio vivainio@gmail....
Sat Feb 7 12:37:12 CST 2009


On Sat, Feb 7, 2009 at 7:58 PM, Brian Granger <ellisonbg.net@gmail.com> wrote:

>>> If not, can we implement this ourselves?
>>
>> See above ;-).
>
> I don't see where "above" you talk about this.  For what it is worth,
> here is what I tried:

I was talking about the fact that wx is based on gtk on linux, so it
might get it "for free".

>>>> import readline
>>>> import ctypes
>>>> ctypes.pythonapi.PyOS_InputHook
> <_FuncPtr object at 0x76420>
>>>> def my_callback():
> ...   print "In am here"
> ...   return 0
> ...
>>>> cbf = ctypes.CFUNCTYPE(ctypes.c_int)(my_callback)
>>>> cbf
> <CFunctionType object at 0x769d0>
>>>> ctypes.pythonapi.PyOS_InputHook = cbf
>
> If I understand the python source code correctly, readline should now
> be calling my callback, but it doesn't seem to.  Am I misunderstanding

Perhaps trying to change the value of static C variable may be a bit
much for ctypes?

If so, perhaps a python extension whose sole purpose would be the
ability to set the input hook would be in order. Perhaps one of the
"ipython-friendly" projects (numpy?) that have C side stuff could
sneak it into their next release.. ;-).

Though really, wx should get it for free with new gtk in the future,
and for windows wx it should be just a matter of contributing a patch.

-- 
Ville M. Vainio
http://tinyurl.com/vainio


More information about the IPython-dev mailing list