Add properties to Jupyter.notebook after it is sealed?

19 views
Skip to first unread message

Adam Rule

unread,
Jan 9, 2018, 2:33:37 PM1/9/18
to Project Jupyter
I am creating a Jupyter Notebook extension for research purposes that creates a sidebar where users can "hide" cells with implementation details until they wish to see them. I am doing something similar to Min's old Scratchpad extension by creating a persistent Sidebar element for rendering these "hidden" cells on demand.

I was attempting to assign my Sidebar element to Jupyter.notebook.sidebar so I can reference it later, but it seems Jupyter.notebook is sealed so I cannot add new properties. Is there a way for me to get around this or is the sealing permanent? For now I am assigning the Sidebar element to Jupyter.notebook.session.sidebar but am not sure if code manipulating the notebook session may delete this reference. Alternatively I tried assigning it to Jupyter.sidebar, but think this will cause problems if a user has multiple notebooks open.

Matthias Bussonnier

unread,
Jan 9, 2018, 3:28:07 PM1/9/18
to jup...@googlegroups.com
HI Adam, 

The seal() was added to avoid mistyped property that at some point was hard to track on the codebase. It is not possible to unseal an object unfortunately. 
Assigning to Jupyter.sidebar should  be ok, the context is not shared between tabs or windows, and Jupyter.notebook mostly refer to the the current notebook frontend application more than the actual document.

IIRC Jupyter should also be accessible if you require('base/js/namespace',...), or alternatively you can attach your element to `window` I guess. 

More generally, I _believe_  (but I may be wrong) that if you are using define/require, I believe modules are singleton so  requiring the same path or library return you the sam instance.  So it might work without having to attach sidebar to any global variable. A bit like you would attach something to numpy, or matplotlib.

The extension looks really cool in the gif !
-- 
M

On 9 January 2018 at 20:33, Adam Rule <acr...@gmail.com> wrote:
I am creating a Jupyter Notebook extension for research purposes that creates a sidebar where users can "hide" cells with implementation details until they wish to see them. I am doing something similar to Min's old Scratchpad extension by creating a persistent Sidebar element for rendering these "hidden" cells on demand.

I was attempting to assign my Sidebar element to Jupyter.notebook.sidebar so I can reference it later, but it seems Jupyter.notebook is sealed so I cannot add new properties. Is there a way for me to get around this or is the sealing permanent? For now I am assigning the Sidebar element to Jupyter.notebook.session.sidebar but am not sure if code manipulating the notebook session may delete this reference. Alternatively I tried assigning it to Jupyter.sidebar, but think this will cause problems if a user has multiple notebooks open.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/e7365c65-ddd5-4720-844e-275778a8ab31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Rule

unread,
Jan 9, 2018, 4:49:18 PM1/9/18
to Project Jupyter
Thanks for the insights. Lot's of options but I'll just go with Jupyter.sidebar then.


On Tuesday, January 9, 2018 at 12:28:07 PM UTC-8, Matthias Bussonnier wrote:
HI Adam, 

The seal() was added to avoid mistyped property that at some point was hard to track on the codebase. It is not possible to unseal an object unfortunately. 
Assigning to Jupyter.sidebar should  be ok, the context is not shared between tabs or windows, and Jupyter.notebook mostly refer to the the current notebook frontend application more than the actual document.

IIRC Jupyter should also be accessible if you require('base/js/namespace',...), or alternatively you can attach your element to `window` I guess. 

More generally, I _believe_  (but I may be wrong) that if you are using define/require, I believe modules are singleton so  requiring the same path or library return you the sam instance.  So it might work without having to attach sidebar to any global variable. A bit like you would attach something to numpy, or matplotlib.

The extension looks really cool in the gif !
-- 
M
On 9 January 2018 at 20:33, Adam Rule <acr...@gmail.com> wrote:
I am creating a Jupyter Notebook extension for research purposes that creates a sidebar where users can "hide" cells with implementation details until they wish to see them. I am doing something similar to Min's old Scratchpad extension by creating a persistent Sidebar element for rendering these "hidden" cells on demand.

I was attempting to assign my Sidebar element to Jupyter.notebook.sidebar so I can reference it later, but it seems Jupyter.notebook is sealed so I cannot add new properties. Is there a way for me to get around this or is the sealing permanent? For now I am assigning the Sidebar element to Jupyter.notebook.session.sidebar but am not sure if code manipulating the notebook session may delete this reference. Alternatively I tried assigning it to Jupyter.sidebar, but think this will cause problems if a user has multiple notebooks open.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages