Violit Drawable Konva
Violit widget wrapping the same Konva canvas used by
streamlit-drawable-konva
(0.3.0 tracks Streamlit 0.6.x standalone).
Requires Violit ≥ 0.8.29 (app.register_js_widget).
Features
vl_canvas— drawable Konva canvas (same tools asst_canvas)- In-canvas tool picker —
tools=[…]+display_tool_picker=True vl_image_comparison— before/after slider companion (same asst_image_comparison)- Background color / image (upload or sample)
- Scene
json_datawith coordinates (x/y/width/height/points) - Spline helpers:
splines_from_json,sample_spline, …
Demo uses dark theme. Pass Violit State / callables into vl_canvas
(not .value) so drawing mode and stroke update live. With
display_tool_picker=True, tools can also be switched on the canvas itself.
Install (editable)
cd /devel/dev/cvrlab/violit-drawable-konva
uv venv .venv
source .venv/bin/activate
uv pip install -e ".[dev]"
Sync the browser IIFE from the Streamlit sibling build (required before demo / packaging):
# ensure standalone.js exists in streamlit-drawable-konva first
bash scripts/sync_standalone.sh
Until you sync, the package falls back to:
../streamlit-drawable-konva/streamlit_drawable_konva/frontend/build/standalone.js
Demo
source .venv/bin/activate
.venv/bin/violit run demo/app.py --reload --localhost --port 8031
# → http://localhost:8031
demo/app.py must end with app.run() (Violit does not auto-start the server).
Tests
pytest -q
Usage
import violit as vl
from violit_drawable_konva import ensure_registered, vl_canvas, vl_image_comparison
app = vl.App(title="Canvas", theme="dark")
ensure_registered(app) # optional; also called by vl_canvas / vl_image_comparison
drawing_mode = app.state("polygon", key="drawing_mode")
stroke_width = app.state(3, key="stroke_width")
stroke_color = app.state("#111", key="stroke_color")
bg_file = app.state(None, key="bg_file")
payload = app.state({"image_data_url": None, "json_data": None}, key="c1")
app.file_uploader("Background", type=[".png", ".jpg"], bind=bg_file)
result = vl_canvas(
app,
drawing_mode=drawing_mode, # State, not .value
stroke_width=stroke_width,
stroke_color=stroke_color,
background_image=bg_file, # UploadedFile / PIL / State / callable
height=400,
width=600,
tools=["freedraw", "line", "rect", "polygon", "transform", "pan"],
display_tool_picker=True,
key="c1",
bind=payload,
)
# result.json_data / result.image_data
vl_image_comparison(app, img_before, img_after, width=600, key="cmp")
Helpers mirror the Streamlit package: crop_box_from_json, objects_by_group,
splines_from_json, spline_control_points, sample_spline, sample_catmull_rom.
Layout
violit_drawable_konva/
api.py # ensure_registered, vl_canvas, vl_image_comparison
payload.py / spline.py / helpers.py
static/standalone.js # synced IIFE (mount + mountImageComparison)
demo/app.py
tests/
scripts/sync_standalone.sh
Publish (PyPI)
cd /devel/dev/cvrlab/violit-drawable-konva
# 1) Sync JS from Streamlit build (after streamlit 0.6.x is built)
bash scripts/sync_standalone.sh
# 2) Tests
.venv/bin/python -m pytest -q
# 3) Commit & push
git add -A
git status
git commit -m "Release 0.3.0: in-canvas tool picker and tools allow-list."
git push -u origin main
git tag v0.3.0 && git push origin v0.3.0
# 4) Build & publish
uv build
uv publish # needs UV_PUBLISH_TOKEN or interactive PyPI token
Verify: https://pypi.org/project/violit-drawable-konva/
Bump version in pyproject.toml before each new upload (PyPI versions are immutable).
Quick PyPI update (0.2.0 → 0.3.0)
bash scripts/sync_standalone.sh
uv build && uv publish
pip install -U violit-drawable-konva # expect 0.3.0
Manual port checklist
- Build Streamlit frontend (
npm run build) sostandalone.jsexists. bash scripts/sync_standalone.shuv pip install -e ".[dev]"(violit>=0.8.29)pytest -qviolit run demo/app.py --reload --localhost --port 8031- Commit / tag /
uv publish(see above)
Metadata
Release files for violit-drawable-konva 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| violit_drawable_konva-0.3.0.tar.gz | 159.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| violit_drawable_konva-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 318.2 kB
Release files / violit_drawable_konva-0.3.0.tar.gz
| Download URL | violit_drawable_konva-0.3.0.tar.gz |
|---|---|
| Size | 159.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
456f0ca1809cba0dc4daa81353dffae47d23cc5f9ce80b54579673de9bbfeb1f
|
|
BLAKE2b-256 checksum How to use checksums |
266f8c73b85d307ed521fe5f2b7203478c0e88f8027ce0926c55efb6e8a274f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / violit_drawable_konva-0.3.0-py3-none-any.whl
| Download URL | violit_drawable_konva-0.3.0-py3-none-any.whl |
|---|---|
| Size | 158.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eee66d5b5a429dd9445cd495e217a0eef5b335d6020fc6c0269d18414da0848d
|
|
BLAKE2b-256 checksum How to use checksums |
3f9c0a56390c842740a23f65550e5dd084e7a7757ec7eda16d122741a2d5bb33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|