From 99135de0ef8171c482d72f7ad1edb2b04ab969d3 Mon Sep 17 00:00:00 2001 From: Stephan Sahm Date: Thu, 11 Jul 2024 14:15:04 +0200 Subject: [PATCH] bind is renamed to bond --- Project.toml | 2 +- ext/PythonCallExt.jl | 25 ---------------------- ext/RCallExt.jl | 4 ++-- src/JolinPluto.jl | 2 +- src/languages.jl | 50 ++++++-------------------------------------- 5 files changed, 10 insertions(+), 73 deletions(-) diff --git a/Project.toml b/Project.toml index ef0c078..940d193 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.73" +version = "0.1.74" [deps] AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150" diff --git a/ext/PythonCallExt.jl b/ext/PythonCallExt.jl index b2c0340..f706172 100644 --- a/ext/PythonCallExt.jl +++ b/ext/PythonCallExt.jl @@ -75,29 +75,4 @@ end # _python_module_where_plutoscript_is_included[] = get!(PythonCall.pydict, PythonCall.Core.MODULE_GLOBALS, Main) # end -# """ -# bindpy("xyz", jl.Slider([1,2,3])) - -# Bind a UserInput to a variable from Python. Note that the first argument cannot -# be a variable, but necessarily needs to be a constant string. -# """ -# function JolinPluto.bindpy(name, ui) -# if !isdefined(Main, :PlutoRunner) -# initial_value_getter = try -# Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value -# catch -# b -> missing -# end -# initial_value = Core.applicable(Base.get, ui) ? Base.get(ui) : initial_value_getter(ui) -# pyglobals[name] = initial_value -# return ui -# else -# def = PythonCall.pyconvert(Symbol, name) -# initial_value = Core.applicable(Base.get, ui) ? Base.get(ui) : Main.PlutoRunner.initial_value_getter_ref[](ui) -# pyglobals[name] = initial_value -# # setglobal!(Main, def, initial_value) -# return PlutoRunner.create_bond(ui, def, Main.PlutoRunner.currently_running_cell_id[]) -# end -# end - end \ No newline at end of file diff --git a/ext/RCallExt.jl b/ext/RCallExt.jl index fea8baa..7e19bc9 100644 --- a/ext/RCallExt.jl +++ b/ext/RCallExt.jl @@ -34,8 +34,8 @@ function JolinPluto.init_jolin(r_environment::RCall.RObject{RCall.EnvSxp}) r_environment[:MD] = JolinPluto.MD r_environment[:HTML] = _HTML - r_environment[Symbol(".bind")] = JolinPluto.bind - RCall.reval("bind <- function(var, ui) .bind(sys.call()[[2]], ui)", r_environment) + r_environment[Symbol(".bond")] = JolinPluto.bond + RCall.reval("bond <- function(var, ui) .bond(sys.call()[[2]], ui)", r_environment) nothing end diff --git a/src/JolinPluto.jl b/src/JolinPluto.jl index 1340cad..c211e84 100644 --- a/src/JolinPluto.jl +++ b/src/JolinPluto.jl @@ -10,7 +10,7 @@ export output_below, clipboard_image_to_clipboard_html, embedLargeHTML, plotly_r 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 -export bindr, bindpy, bindjl +export bond export init_jolin using Dates, HTTP, JSON3, Git, JWTs, UUIDs, Base64 diff --git a/src/languages.jl b/src/languages.jl index 87b787b..4c628b0 100644 --- a/src/languages.jl +++ b/src/languages.jl @@ -23,8 +23,8 @@ end """ ```julia -bind(symbol, element) -bind("symbol", element) +bond(symbol, element) +bond("symbol", element) ``` Return the HTML `element`, and use its latest JavaScript value as the definition of `symbol`. @@ -32,7 +32,7 @@ Return the HTML `element`, and use its latest JavaScript value as the definition # Example ```julia -bind(:x, html"") +bond(:x, html"") ``` and in another cell: ```julia @@ -42,7 +42,7 @@ x^2 The first cell will show a slider as the cell's output, ranging from 0 until 100. The second cell will show the square of `x`, and is updated in real-time as the slider is moved. """ -function bind(def, ui) +function bond(def, ui) if !isa(def, Symbol) throw(ArgumentError("""\nMacro example usage: \n\n\t@bind my_number html""\n\n""")) elseif !isdefined(Main, :PlutoRunner) @@ -69,44 +69,6 @@ end # for python and R especially # (python strings are automatically transformed to Julia strings in JuliaCall when calling julia functions from python) # (same for R strings) -function bind(def::AbstractString, ui) - bind(Symbol(def), ui) +function bond(def::AbstractString, ui) + bond(Symbol(def), ui) end - - -# # TODO it looks difficult to relyably find out which language is currently used. -# # safest is probably a simple environment variable (while "_" looks kind of okay, it probably won't work everywhere) -# # TODO also pick the documentation dynamically? -# function bind(args...; kwargs...) -# fallback = :py # we fallback to python for now, as julia uses the macro definition -# lang = if isdefined(Main, :PlutoRunner) -# if isdefined(Main.PlutoRunner, :notebook_lang) -# Main.PlutoRunner.notebook_lang[] -# else -# fallback -# end -# elseif haskey(ENV, "_") -# # TODO I guess this does not work on windows -# original_executable = lowercase(basename(ENV["_"])) -# if contains(original_executable, "python") -# :py -# elseif contains(original_executable, "julia") -# :jl -# elseif original_executable == "r" -# :R -# else -# fallback -# end -# else -# error("Could not identify which language is currently used.") -# end -# # using PPID seems not work for PythonCall - the PPID from julia and python is the same, both referring to the shell - -# if lang == :jl -# return bindjl(args...; kwargs...) -# elseif lang == :py -# return bindpy(args...; kwargs...) -# elseif lang == :R -# return bindr(args...; kwargs...) -# end -# end \ No newline at end of file