-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyvizzu-story.py
40 lines (30 loc) · 1.12 KB
/
pyvizzu-story.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import html
from textwrap import dedent
from pyscript import Plugin, js
from pyodide.ffi import to_js
from js import Object
import json
js.console.warn(
"WARNING: This plugin is still in a very experimental phase and will likely change"
" and potentially break in the future releases. Use it with caution."
)
class MyPlugin(Plugin):
def configure(self, config):
js.console.log(f"configuration received: {config}")
def afterStartup(self, runtime):
js.console.log(f"runtime received: {runtime}")
plugin = MyPlugin("pyVizzuStory")
@plugin.register_custom_element("py-vizzu-story")
class PyVizzu:
def __init__(self, element):
self.element = element
def connect(self):
print("CONNECTED----->")
self.html = dedent(self.element.innerHTML)
story = self.html
json_story = json.loads(story)
js_story = to_js(json_story, dict_converter=Object.fromEntries)
self.element.innerHTML = "<vizzu-player controller></vizzu-player>"
self.element.firstElementChild.slides = js_story;
self.element.style.display = "block"
print(self.html)