Skip to content

Commit

Permalink
bind is renamed to bond
Browse files Browse the repository at this point in the history
schlichtanders committed Jul 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 975f6be commit 99135de
Showing 5 changed files with 10 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JolinPluto"
uuid = "5b0b4ef8-f4e6-4363-b674-3f031f7b9530"
authors = ["Stephan Sahm <[email protected]> and contributors"]
version = "0.1.73"
version = "0.1.74"

[deps]
AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150"
25 changes: 0 additions & 25 deletions ext/PythonCallExt.jl
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions ext/RCallExt.jl
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/JolinPluto.jl
Original file line number Diff line number Diff line change
@@ -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
50 changes: 6 additions & 44 deletions src/languages.jl
Original file line number Diff line number Diff line change
@@ -23,16 +23,16 @@ 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`.
# Example
```julia
bind(:x, html"<input type=range>")
bond(:x, html"<input type=range>")
```
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"<input type='range'>"\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

0 comments on commit 99135de

Please sign in to comment.