Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable "save widget state automatically" via notebook command? #137

Open
kolibril13 opened this issue Feb 11, 2024 · 3 comments
Open

Disable "save widget state automatically" via notebook command? #137

kolibril13 opened this issue Feb 11, 2024 · 3 comments

Comments

@kolibril13
Copy link

I'm looking for a snippet similar to

from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
app.commands.execute('notebook:insert-cell-below')

but instead of insert-cell-below, I would like to disable "save widget state automatically".
That way, I could enable "save widget state automatically" by default for all my notebooks, and exclude some notebooks where I don't want to save widget states.
Here's a list of notebook commands that I found, but I don't know which one is right for disabling saving the widget state
https://github.com/jupyterlab/jupyterlab/blob/49f6ec28b738243a53a947d544bebafafcbd4a73/packages/notebook-extension/src/index.ts#L136-L325

Looking forward to suggestions and ideas!

@jtpio
Copy link
Owner

jtpio commented Feb 12, 2024

Looks like the command id should be: @jupyter-widgets/jupyterlab-manager:saveWidgetState.

It's not part of core JupyterLab, it comes from the ipywidgets extension.

For reference you can use app.commands.list_commands() to get a list of available commands as in this example notebook: https://github.com/jtpio/ipylab/blob/main/examples/commands.ipynb

image

@kolibril13
Copy link
Author

Ohh, that's amazing, thanks for these great snippets!
I've tried

from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
app.commands.execute('@jupyter-widgets/jupyterlab-manager:saveWidgetState')

and indeed, this toggles the saveWidgetState. If it was off before, it's on afterward.

That's great, however this is not very useful in a real live scenario.
It would be amazing to explicitly turn saveWidgetState on or respectively off.
Would that be possible as well?

@jtpio
Copy link
Owner

jtpio commented Feb 12, 2024

Maybe the best would be to add commands for saving and clearing the state to ipywidgets directly, like it was the case in the classic notebook.

There is an issue tracking this: jupyter-widgets/ipywidgets#3672

To have 3 commands:

  • Save Widget State Automatically (toggle)
  • Save Widget State
  • Clear Widget State

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants