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

feat: include state to reproduce the visual state #207

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions glue_jupyter/widgets/disconnect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ipyvue
import ipyvuetify as v
import traitlets
import ipywidgets as widgets
from traitlets import Unicode, Dict, List
import ipywidgets as w

class Disconnect(v.VuetifyTemplate):
main = traitlets.Instance(widgets.Widget).tag(sync=True, **widgets.widget_serialization)
broken = traitlets.Instance(widgets.Widget).tag(sync=True, **widgets.widget_serialization)
connected = traitlets.Bool(True).tag(sync=True)
template = Unicode("""
<template>
<view-context-wrapper :widget="connected ? main : broken"></view-context-wrapper>
</template>
""").tag(sync=True)

# we need to put our code in a component, otherwise inject: ['viewCtx'] does not work
components = Dict({
'view-context-wrapper': """
<template>
<jupyter-widget :widget="widget"></jupyter-widget>
</template>
<script>
module.exports = {
props: ["widget"],
inject: ['viewCtx'],
created() {
const model = this.viewCtx.getView().model;
model.set('connected', Boolean(model.comm_live));
model.on('comm_live_update', () => {
const connected = Boolean(model.comm_live)
model.set('connected', connected);
model.save_changes()
})
},
};
</script>
"""
}).tag(sync=True)