-
Notifications
You must be signed in to change notification settings - Fork 947
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
added _view_count trait to Widget, to count the number of views #1232
added _view_count trait to Widget, to count the number of views #1232
Conversation
ipywidgets/widgets/widget.py
Outdated
@@ -247,6 +247,8 @@ def get_view_spec(self): | |||
help="Name of the view object.").tag(sync=True) | |||
_view_module_version = Unicode('*', | |||
help="A semver requirement for the view module version.").tag(sync=True) | |||
_view_count = Int(read_only=True, | |||
help="The number of views accociated to the model at the front-end").tag(sync=True) |
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.
"associated". Also, can we indicate this is experimental for now? Maybe "EXPERIMENTAL: The number of views of the model displayed in the frontend. This attribute is experimental and may change or be removed in the future."
jupyter-js-widgets/src/widget.ts
Outdated
@@ -623,6 +623,19 @@ abstract class WidgetView extends NativeView<WidgetModel> { | |||
this.listenTo(this.model, 'change', this.update); | |||
|
|||
this.options = parameters.options; | |||
|
|||
this.once('remove', () => { | |||
console.log("remove view count", this.model.get('_view_count'), this.model.get('_view_count') -1) |
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.
delete the console.log
jupyter-js-widgets/src/widget.ts
Outdated
}); | ||
|
||
this.once('displayed', () => { | ||
console.log("add view count", this.model.get('_view_count'), this.model.get('_view_count') +1) |
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.
delete the console.log
I assume you are ok with merging this, I'll add those comments and remove the logs. It would take some debugging to see why Output is misbehaving though, but that bug/feature can't be in this code I think. I hope to update this soon. |
Yes, I'm okay merging this as an experimental feature. |
Thanks again for pushing forward on things! |
Thanks! |
Looking forward to the next release ! :) |
added _view_count trait to Widget, to count the number of views in the backend, as discussed here: #1225
There seems to be an issue with the Output widget, it only sends it state once, subsequent calls to
OutputModel.save()
orOutputModel.save_changes()
do nothing. I'm not sure what is so different about OutputModel.I also noticed
WidgetView.remove()
was called twice, I'll submit an issue for that, I've worked around that by using.once(..)
.