-
Notifications
You must be signed in to change notification settings - Fork 949
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
Feature: save additional mime bundles in notebook #3107
base: main
Are you sure you want to change the base?
Changes from all commits
a7b69ef
883bbd3
4f3f57b
e1c5ab1
ffd91d2
84a1574
f4c89fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,49 @@ export class WidgetManager extends ManagerBase { | |
*/ | ||
_init_actions() { | ||
var notifier = Jupyter.notification_area.widget('widgets'); | ||
this.notebook.events.on('before_save.Notebook', async () => { | ||
var cells = Jupyter.notebook.get_cells(); | ||
// notebook.js save_notebook doesn't want for this promise, we are simply lucky when this | ||
// finishes before saving. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems very weak :S There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think this means it will be a lab feature only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about not making it a Promise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we to await the model, and making `generateMimeBundle async also makes sense, since it will involve async cases in bqplot at least. |
||
await Promise.all( | ||
cells.map(async (cell) => { | ||
if (!cell.output_area) { | ||
return; | ||
} | ||
|
||
var widget_output = cell.output_area.outputs.find((output) => { | ||
return ( | ||
(output.data && output.data[MIME_TYPE]) || | ||
(output.metadata && output.metadata[MIME_TYPE]) | ||
); | ||
}); | ||
if (widget_output) { | ||
var model_id = widget_output.data[MIME_TYPE] | ||
? widget_output.data[MIME_TYPE].model_id | ||
: widget_output.metadata[MIME_TYPE].model_id; | ||
var model = await this.get_model(model_id); | ||
if (model) { | ||
var bundle = await model.generateMimeBundle(); | ||
|
||
if ( | ||
widget_output.data[MIME_TYPE] && | ||
model.shouldOverwriteMimeBundle() | ||
) { | ||
widget_output.metadata[MIME_TYPE] = | ||
widget_output.data[MIME_TYPE]; | ||
widget_output.metadata['text/plain'] = | ||
widget_output.data['text/plain']; | ||
|
||
delete widget_output.data[MIME_TYPE]; | ||
delete widget_output.data['text/plain']; | ||
} | ||
|
||
_.extend(widget_output.data, bundle); | ||
} | ||
} | ||
}) | ||
); | ||
}); | ||
this.saveWidgetsAction = { | ||
handler: function () { | ||
this.get_state({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about generateMimeBundle making the default mimebundle (with the widget in it).
subclases can then do:
depending on if they want to overwrite it. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!