[IPython-dev] Notebook: Retaining mouse events when destroying elements with JS

Phil Elson pelson.pub at gmail.com
Mon Sep 22 05:43:05 EDT 2014


Thanks for the pointer Thomas,

Simply adding *IPython.keyboard_manager.enable()* to the event fixed the
problem.


On 19 September 2014 23:12, Thomas Kluyver <takowl at gmail.com> wrote:

> When you display output, clicking in there disables all of IPython's
> shortcuts, so that you can type normally if your output includes a text
> widget or something. Normally, when the focus leaves the output element,
> the shortcuts are enabled again. I guess that because you're deleting the
> element, the 'focus left' event isn't firing properly.
>
> This section of our code should illustrate how to work around it:
>
> https://github.com/ipython/ipython/blob/50ab9a900d617e41ecca11093e4bed2c2bb5ac03/IPython/html/static/notebook/js/keyboardmanager.js#L550
>
> Thomas
>
>
> On 19 September 2014 08:55, Phil Elson <pelson.pub at gmail.com> wrote:
>
>> I've got a case where I'm implementing a button which removes some output
>> via JS when clicked.
>> The removal is working as expected, but IPython's keyboard events are no
>> longer firing after the button has been clicked.
>>
>> Essentially I have a single cell with the following:
>>
>> from IPython.display import HTML
>>
>> HTML("""
>> <button id="my_button" text="Click me to remove!">Click me</button>
>>
>> <script>
>> $("#my_button").click(function() {
>>     $("#my_button").remove()
>> });
>> </script>
>> """)
>>
>> This is part of a more complex system which cannot currently make use of
>> the widget infrastructure, so wonder if anybody can give me any clues as to
>> how to prevent the IPython keyboard short-cuts from disappearing once the
>> button is pressed?
>>
>> Thanks!
>>
>> Phil
>>
>>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140922/34a63f24/attachment.html>


More information about the IPython-dev mailing list