%run __init__.py
%load_ext lab_black
AutoVjsf
works in exactly the same way as AutoUi
, but instead of using ipywidgets
to render the JSON schema it uses ipyvuetify and vuetify-jsonschema-form.
:::{admonition} vuetify-jsonschema-form documentation is awesome! :class: tip See there docs and the Video below to see what you can do. Once you've created a schema based on those docs it ___should___ work with AutoVjsf :::
from IPython.display import IFrame
IFrame(
width="600",
height="500",
sandbox="allow-same-origin allow-scripts allow-popups",
frameborder="0",
src="https://videos.koumoul.com/videos/embed/29d12ba2-f694-4659-8027-e9386692d8b5",
)
{note}
when you're using pydantic to make the schema, __"-"__ cannot be used field names, use __"_"__ instead (e.g. "x_display") and AutoVjsf does the conversion.
from ipyautoui import AutoVjsf
import json
from pydantic import BaseModel, Field
from ipyautoui.constants import DIR_MODULE
from ipyautoui._utils import display_pydantic_json
So let's create a simple pydantic class. Here we have one text field.
ipyvuetify doesn't output to HTML when docs are being built so simply uncomment the code below when running in Binder
# create a pydantic model (or a json-schema) defining the fields of interest
class AutoUiExample(BaseModel):
text: str = Field(default="Test", description="This description is very important")
import pathlib
value = {"text": "this is a value"}
ui = AutoVjsf(schema=AutoUiExample, value=value, path=pathlib.Path("test.json"))
display(ui) # uncomment
both a value and a path given. value will be used.
AutoVjsf(children=(HBox(children=(ToggleButton(value=False, icon='code', layout=Layout(display='None', width='…
Let's define the save location.
import pathlib
save_path = pathlib.Path(".") / "test.simpleaui.json"
print(f"Save Location is: {save_path}")
Save Location is: test.simpleaui.json
ui.file(path=save_path)
AutoVjsfRenderer = AutoVjsf.create_autoui_renderer(
schema=AutoUiExample, fn_onsave=lambda: print("done")
)
ui_file = AutoVjsfRenderer(path=save_path)
display(ui_file)
pydantic validation failed
AutoRenderer(children=(HBox(children=(ToggleButton(value=False, icon='code', layout=Layout(display='None', wid…
Let's look at a complete pydantic model producing all of the possible widgets.
within import ipyautoui.demo_schemas
there is a class called CoreIpywidgets
that outlines what is possible.
Explore the python file below.
from ipyautoui.demo_schemas import CoreIpywidgets
ui = AutoVjsf(CoreIpywidgets)
ui.show_raw = True
ui
AutoVjsf(children=(HBox(children=(ToggleButton(value=False, icon='code', layout=Layout(display='', width='44px…