diff --git a/Project.toml b/Project.toml index 6567331..a291bf5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JolinPluto" uuid = "5b0b4ef8-f4e6-4363-b674-3f031f7b9530" authors = ["Stephan Sahm and contributors"] -version = "0.1.85" +version = "0.1.86" [deps] AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150" diff --git a/ext/PythonCallExt.jl b/ext/PythonCallExt.jl index 409dbb8..b2b919d 100644 --- a/ext/PythonCallExt.jl +++ b/ext/PythonCallExt.jl @@ -72,13 +72,16 @@ end # ipywidgets support # ================== -# global initialization needed for ipywidgets +# global initialization needed for ipywidgets - this is now also included in Pluto base, so no need for this here any longer +# the downside was that on reload, this was not really executed in the correct order. +# still somewhen it would be nice for a package like this to create a __pluto_init__ hook or similar to ingest this in a more modular way + """ IPyWidget_init() Initialize javascript for ipywidgets to work inside Pluto. """ -JolinPluto.IPyWidget_init() = @htl """ +IPyWidget_init() = @htl """ + """ -function Base.show(io::IO, m::MIME"text/html", w::JolinPluto.IPyWidget) +# Python specific stuff + +""" Wrap an ipywidget to be used in Pluto """ +struct IPyWidget + wi +end + +function Base.show(io::IO, m::MIME"text/html", w::IPyWidget) e = PythonCall.pyimport("ipywidgets.embed") data = e.embed_data(views=[w.wi], state=e.dependency_state([w.wi])) show(io, m, @htl """ @@ -124,7 +135,7 @@ function Base.show(io::IO, m::MIME"text/html", w::JolinPluto.IPyWidget) div.value = $(pyconvert(Any, w.wi.value)) if((window.require == null) || window.specified){ - div.innerHTML = '

⚠️ Activate ipywidgets by running the following once inside Pluto ⚠️

from juliacall import Main as jl
jl.seval("using Jolin")
jl.IPyWidget_init() # <-- this is important

' + div.innerHTML = '

Couldn't find ipywidgets javascript dependencies. This should not happen, please contact hello@jolin.io.

' } // TODO renderWidgets(div) has the advantage that no duplicates appear @@ -160,7 +171,7 @@ function Base.show(io::IO, m::MIME"text/html", w::JolinPluto.IPyWidget) """) end -function AbstractPlutoDingetjes.Bonds.initial_value(w::JolinPluto.IPyWidget) +function AbstractPlutoDingetjes.Bonds.initial_value(w::IPyWidget) return pyconvert(Any, w.wi.value) end @@ -168,7 +179,7 @@ function pyshow_rule_ipywidgets(io::IO, mime::String, x::Py) mime == "text/html" || return false pyissubclass(pytype(x), @pyconst(pyimport("ipywidgets").widgets.ValueWidget)) || return false try - show(io, mime, JolinPluto.IPyWidget(x)) + show(io, mime, IPyWidget(x)) return true catch exc if exc isa PyException @@ -183,7 +194,7 @@ end JolinPluto.viewof(def::AbstractString, ui::Py) = JolinPluto.viewof(Symbol(def), ui) function JolinPluto.viewof(def::Symbol, ui::Py) if pyissubclass(pytype(ui), @pyconst(pyimport("ipywidgets").widgets.ValueWidget)) - JolinPluto.viewof(def, JolinPluto.IPyWidget(ui)) + JolinPluto.viewof(def, IPyWidget(ui)) else @invoke JolinPluto.viewof(def::Symbol, ui::Any) end @@ -202,7 +213,7 @@ end # Here an alternative implementation which unfortunately does not really work because if the same is used multiple times, on the first load it will actually # interfere with one another so that all widgets are duplicated 3 to 10 times, depending on how many widgets load the common dependency in parallel. -# function Base.show(io::IO, m::MIME"text/html", w::JolinPluto.IPyWidget) +# function Base.show(io::IO, m::MIME"text/html", w::IPyWidget) # e = PythonCall.pyimport("ipywidgets.embed") # data = e.embed_data(views=[w.wi], state=e.dependency_state([w.wi])) # show(io, m, @htl """ diff --git a/src/JolinPluto.jl b/src/JolinPluto.jl index ebd7aa5..fbc407a 100644 --- a/src/JolinPluto.jl +++ b/src/JolinPluto.jl @@ -7,7 +7,6 @@ export Setter, @get, @cell_ids_create_wrapper, @cell_ids_push! export cell_ids_create_wrapper, cell_ids_push!, cell_ids_push export MD, format_html, _HTML export viewof -export IPyWidget, IPyWidget_init using Dates, HTTP, JSON3, Git, JWTs, UUIDs, Base64 using HypertextLiteral, Continuables diff --git a/src/languages.jl b/src/languages.jl index 5f1c92a..c652ec5 100644 --- a/src/languages.jl +++ b/src/languages.jl @@ -20,14 +20,3 @@ function lang_set_global end Gets the given variable from the respective language side. """ function lang_get_global end - - - -# Python specific stuff - -function IPyWidget_init end - -""" Wrap an ipywidget to be used in Pluto """ -struct IPyWidget - wi -end \ No newline at end of file