Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashi Gowda committed Apr 25, 2018
2 parents 4b24a0c + ce52c14 commit 58adbff
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.*~
.*sw?
.ipynb_checkpoints
ipywidgets_version
widgets_version
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
email: false
script:
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
julia 0.6
JSON 0.7
Compat 0.17
Reactive 0.3.7
Expand Down
61 changes: 47 additions & 14 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
using Compat

const widgver_file = joinpath(dirname(@__FILE__), "widgets_version")

function main()
info("Enabling widgetsnbextension")
try
run(`$(IJulia.jupyter) nbextension enable --py widgetsnbextension`)
catch err
warn("Could not enable widgetsnbextension")
if IJulia.notebook_cmd[1] == IJulia.jupyter
nbextension_cmd = [IJulia.jupyter, "nbextension"]
else
if endswith(IJulia.notebook_cmd[1], "python.exe")
nbextension_cmd = IJulia.notebook_cmd[1:2]
else
nbextension_cmd = IJulia.notebook_cmd[1:1]
end
n = nbextension_cmd[end]
ni = rsearch(n, "notebook")
nbextension_cmd[end] = n[1:prevind(n,first(ni))] * "nbextension" * n[nextind(n,last(ni)):end]
end
run(`$nbextension_cmd install --py widgetsnbextension`)
run(`$nbextension_cmd enable --py widgetsnbextension`)
catch
warn("Could not enable widgetsnbextension.")
end

if is_linux() || is_apple()
python = strip(readline(readstring(`which $(IJulia.jupyter)`)|>strip), ['\n',' ', '#','!'])
elseif is_windows()
warn("cannot determine jupyter's python path in Windows, bailing.")
return
if endswith(IJulia.notebook_cmd[1], "python.exe")
python = IJulia.notebook_cmd[1]
elseif startswith(IJulia.jupyter, Pkg.dir("Conda")) # using the Conda Python
python = joinpath(eval(Main, :(using Conda; Conda.PYTHONDIR)), "python.exe")
elseif haskey(ENV,"PYTHON") && !isempty(ENV["PYTHON"])
python = ENV["PYTHON"]
else
vers = isfile(widgver_file) ? readline(widgver_file)*" (found in $widgver_file)" : ">= 3.0.0"
warn("""Cannot determine Jupyter's python.exe, will guess that you have
widgetsnbextension $vers. Otherwise, set ENV["PYTHON"] to the path of your
python.exe and re-run Pkg.build("Interact"), or manually edit $widgver_file to
the value of widgetsnbextension.__version__, or set e.g.
ENV["WIDGETS_VERSION"]="2.0.0" before you run `using Interact` """)
return
end
end

try
ipywver = readstring(`$python -c 'import ipywidgets; print(ipywidgets.__version__)'`) |> strip |> VersionNumber
write("ipywidgets_version", string(ipywver))
rm(widgver_file, force=true) # remove old version, if any
widgver = readstring(`$python -c 'import widgetsnbextension; print(widgetsnbextension.__version__)'`) |> strip |> VersionNumber
write(widgver_file, string(widgver))

info("ipywidgets version found: $ipywver")
if ipywver < v"5.0.0"
warn("""This version of Interact requires ipywidgets > 5.0 to work correctly.
If you have ipywidgets version 4.x, run Pkg.checkout("Interact", "ipywidgets-4").""")
info("widgetsnbextension version found: $widgver")
if widgver < v"1.0.0"
warn("""This version of Interact requires widgetsnbextension >= 1.0.0 to work correctly.
If you have widgetsnbextension version 0.x, run Pkg.checkout("Interact", "ipywidgets-4").""")
else
info("A compatible version of ipywidgets was found. All good.")
info("A compatible version of widgetsnbextension was found. All good.")
end
catch err
warn("Could not determine ipywidgets version.")
catch
warn("""Could not determine widgetsnbextension version from $python, will guess that you
have ≥ 3.0. If widgets do not display, manually edit $widgver_file to 2.0.0 (or
the value of widgetsnbextension.__version__ ), or set
ENV["WIDGETS_VERSION"]="2.0.0" before you run `using Interact`""")
write(widgver_file, "3.0.0")
end
end

Expand Down
15 changes: 5 additions & 10 deletions src/IJulia/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ JSON.lower(s::Signal) = s.value
# Interact -> IJulia view names
widget_class(::HTML) = "HTML"
widget_class(::Layout) = "Layout"
widget_class(::Box) = "Box"
widget_class(b::Box) = b.vert ? "VBox" : "Box"
widget_class(::Latex) = "Label"
widget_class(::Progress) = "Progress"
widget_class(::Progress) = "FloatProgress"
widget_class{T<:Integer}(::Slider{T}) = "IntSlider"
widget_class(::Button) = "Button"
widget_class(::Textarea) = "Textarea"
Expand All @@ -174,13 +174,8 @@ widget_class(w, suffix) = widget_class(w) * suffix
view_name(w) = widget_class(w, "View")
model_name(w) = widget_class(w, "Model")

"""
Update output widgets
"""
update!(p::Progress, val) = begin
p.value = val;
update_view(p)
end
# Special cases
view_name(w::Progress) = "ProgressView"

function metadata(x::Widget)
display_widget(x)
Expand Down Expand Up @@ -320,4 +315,4 @@ end
include("statedict.jl")
include("handle_msg.jl")

end
end
12 changes: 2 additions & 10 deletions src/IJulia/setup_old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Interact: update_view, Slider, Widget, InputWidget, Latex, HTML, recv_msg
statedict, viewdict, Layout, Box,
Progress, Checkbox, Button, ToggleButton, Textarea, Textbox, Options

export mimewritable
export mimewritable

const ijulia_js = readstring(joinpath(dirname(@__FILE__), "ijulia.js"))

Expand Down Expand Up @@ -174,14 +174,6 @@ widget_class(w, suffix) = widget_class(w) * suffix
view_name(w) = widget_class(w, "View")
model_name(w) = widget_class(w, "Model")

"""
Update output widgets
"""
update!(p::Progress, val) = begin
p.value = val;
update_view(p)
end

function metadata(x::Widget)
display_widget(x)
Dict()
Expand Down Expand Up @@ -311,4 +303,4 @@ end
include("statedict_old.jl")
include("handle_msg_old.jl")

end
end
3 changes: 3 additions & 0 deletions src/IJulia/statedict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ end
:_model_name => "FloatSliderModel",
:readout => s.readout,
:readout_format => s.readout_format,
:orientation => s.orientation,
:continuous_update=>s.continuous_update,
)

Expand Down Expand Up @@ -47,6 +48,8 @@ statedict{view, T}(d::Options{view, T}) =
:icons=>d.icons,
:tooltips=>d.tooltips,
:readout => d.readout,
:continuous_update=>d.continuous_update,
:orientation => d.orientation,
:_options_labels=>collect(keys(d.options)))

statedict(w::Widget) = begin
Expand Down
16 changes: 9 additions & 7 deletions src/Interact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,21 @@ include("manipulate.jl")

const ijulia_setup_path = joinpath(dirname(@__FILE__), "IJulia", "setup.jl")
const ijulia_setup_path_old = joinpath(dirname(@__FILE__), "IJulia", "setup_old.jl")
const ipywidgets_version = joinpath(dirname(@__FILE__), "..", "deps", "ipywidgets_version")
const ipywidgets_version = joinpath(dirname(@__FILE__), "..", "deps", "widgets_version")

function __init__()
if isdefined(Main, :IJulia)
if isfile(ipywidgets_version)
if haskey(ENV, "WIDGETS_VERSION")
v = VersionNumber(ENV["WIDGETS_VERSION"])
elseif isfile(ipywidgets_version)
v = VersionNumber(strip(readline(ipywidgets_version)))
if v >= v"6.0.0"
include(ijulia_setup_path)
else
include(ijulia_setup_path_old)
end
else
v = v"3.0.0"
end
if v >= v"3.0.0"
include(ijulia_setup_path)
else
include(ijulia_setup_path_old)
end
end
end
Expand Down
25 changes: 18 additions & 7 deletions src/widgets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export slider, vslider, togglebutton, button,
radiobuttons, dropdown, selection,
togglebuttons, html, latex, hbox, vbox,
progress, widget, selection_slider, vselection_slider,
set!
set!, update!

### Layout Widgets
type Layout <: Widget
Expand Down Expand Up @@ -303,6 +303,7 @@ type Options{view, T} <: InputWidget{T}
tooltips::AbstractArray
readout::Bool
orientation::AbstractString
continuous_update::Bool
end

labels2idxs(d::OptionDict, labels) = findin(keys(d), labels)
Expand All @@ -320,13 +321,14 @@ Options(view::Symbol, options::OptionDict;
orientation="horizontal",
syncsig=true,
syncnearest=true,
continuous_update=true,
sel_mid_idx=0) = begin
#sel_mid_idx set in selection_slider(...) so default value_label is middle of range
sel_mid_idx != 0 && (value_label = collect(keys(options.dict))[sel_mid_idx])
signal, value = init_wsigval(signal, value; typ=typ, default=options[value_label])
typ = eltype(signal)
ow = Options{view, typ}(signal, label, value, value_label, index,
options, icons, tooltips, readout, orientation)
options, icons, tooltips, readout, orientation, continuous_update)
if syncsig
syncselnearest = view == :SelectionSlider && typ <: Real && syncnearest
if view != :SelectMultiple
Expand All @@ -340,8 +342,7 @@ Options(view::Symbol, options::OptionDict;
if syncselnearest
val = nearest_val(keys(ow.options.invdict), val)
end
if haskey(ow.options.invdict, val) &&
ow.value_label != ow.options.invdict[val]
if haskey(ow.options.invdict, val)
ow.value_label = ow.options.invdict[val]
ow.index = labels2idxs(ow.options, [ow.value_label]) |> first
update_view(ow)
Expand All @@ -361,8 +362,10 @@ function Options(view::Symbol,
Options(view, getoptions(options); kwargs...)
end

getoptions(options::AbstractArray{<:Union{Pair, Tuple}}) = getoptions(Dict(options))

function getoptions(options)
opts = OrderedDict()
opts = OrderedDict{String, eltype(values(options))}()
for el in options
addoption!(opts, el)
end
Expand Down Expand Up @@ -477,7 +480,7 @@ latex(value; label="") = Latex(label, mimewritable("application/x-latex", value)

type Progress <: Widget
label::AbstractString
value::Int
value::Float64
range::Range
orientation::String
readout::Bool
Expand All @@ -486,10 +489,18 @@ type Progress <: Widget
end

progress(args...) = Progress(args...)
progress(;label="", value=0, range=0:100, orientation="horizontal",
progress(;label="", range=0.0:0.1:100, value=first(range), orientation="horizontal",
readout=true, readout_format="d", continuous_update=true) =
Progress(label, value, range, orientation, readout, readout_format, continuous_update)

"""
Update output widgets
"""
function update!(p::Progress, val)
p.value = val;
update_view(p)
end

# Make a widget out of a domain
widget(x::Signal, label="") = x
widget(x::Widget, label="") = x
Expand Down
3 changes: 3 additions & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ julia 0.4
Compat 0.8.0
BaseTestNext
IJulia
NBInclude
Colors
Compose
21 changes: 21 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ module HygieneTest2
2 * i, j * " hello"
end
end

# Notebooks
# notebookdirs = [joinpath(@__DIR__, "notebooks"), joinpath(@__DIR__, "..", "doc", "notebooks")]
notebookdirs = [joinpath(@__DIR__, "..", "doc", "notebooks")] # Interact Manual Tests.ipynb is broken (flatten call)
excludes = [joinpath(@__DIR__, "..", "doc", "notebooks", "03-Interactive Diagrams and Plots.ipynb")]
for notebookdir in notebookdirs
for file in readdir(notebookdir)
path = joinpath(notebookdir, file)
path in excludes && continue
name, ext = splitext(file)
lowercase(ext) == ".ipynb" || continue
@eval module $(gensym()) # Each notebook is run in its own module.
using Base.Test
using NBInclude
@testset "$($name)" begin
nbinclude($path, regex = r"^((?!\#NBSKIP).)*$"s) # Use #NBSKIP in a cell to skip it during tests.
end
end # module
end
end

0 comments on commit 58adbff

Please sign in to comment.