Skip to content

Commit 58adbff

Browse files
author
Shashi Gowda
committed
Merge remote-tracking branch 'origin/master'
2 parents 4b24a0c + ce52c14 commit 58adbff

File tree

11 files changed

+110
-52
lines changed

11 files changed

+110
-52
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.*~
22
.*sw?
33
.ipynb_checkpoints
4-
ipywidgets_version
4+
widgets_version

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.5
76
- 0.6
8-
- nightly
97
notifications:
108
email: false
119
script:

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.5
1+
julia 0.6
22
JSON 0.7
33
Compat 0.17
44
Reactive 0.3.7

deps/build.jl

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,66 @@
11
using Compat
22

3+
const widgver_file = joinpath(dirname(@__FILE__), "widgets_version")
4+
35
function main()
46
info("Enabling widgetsnbextension")
57
try
6-
run(`$(IJulia.jupyter) nbextension enable --py widgetsnbextension`)
7-
catch err
8-
warn("Could not enable widgetsnbextension")
8+
if IJulia.notebook_cmd[1] == IJulia.jupyter
9+
nbextension_cmd = [IJulia.jupyter, "nbextension"]
10+
else
11+
if endswith(IJulia.notebook_cmd[1], "python.exe")
12+
nbextension_cmd = IJulia.notebook_cmd[1:2]
13+
else
14+
nbextension_cmd = IJulia.notebook_cmd[1:1]
15+
end
16+
n = nbextension_cmd[end]
17+
ni = rsearch(n, "notebook")
18+
nbextension_cmd[end] = n[1:prevind(n,first(ni))] * "nbextension" * n[nextind(n,last(ni)):end]
19+
end
20+
run(`$nbextension_cmd install --py widgetsnbextension`)
21+
run(`$nbextension_cmd enable --py widgetsnbextension`)
22+
catch
23+
warn("Could not enable widgetsnbextension.")
924
end
1025

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

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

22-
info("ipywidgets version found: $ipywver")
23-
if ipywver < v"5.0.0"
24-
warn("""This version of Interact requires ipywidgets > 5.0 to work correctly.
25-
If you have ipywidgets version 4.x, run Pkg.checkout("Interact", "ipywidgets-4").""")
51+
info("widgetsnbextension version found: $widgver")
52+
if widgver < v"1.0.0"
53+
warn("""This version of Interact requires widgetsnbextension >= 1.0.0 to work correctly.
54+
If you have widgetsnbextension version 0.x, run Pkg.checkout("Interact", "ipywidgets-4").""")
2655
else
27-
info("A compatible version of ipywidgets was found. All good.")
56+
info("A compatible version of widgetsnbextension was found. All good.")
2857
end
29-
catch err
30-
warn("Could not determine ipywidgets version.")
58+
catch
59+
warn("""Could not determine widgetsnbextension version from $python, will guess that you
60+
have ≥ 3.0. If widgets do not display, manually edit $widgver_file to 2.0.0 (or
61+
the value of widgetsnbextension.__version__ ), or set
62+
ENV["WIDGETS_VERSION"]="2.0.0" before you run `using Interact`""")
63+
write(widgver_file, "3.0.0")
3164
end
3265
end
3366

src/IJulia/setup.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ JSON.lower(s::Signal) = s.value
157157
# Interact -> IJulia view names
158158
widget_class(::HTML) = "HTML"
159159
widget_class(::Layout) = "Layout"
160-
widget_class(::Box) = "Box"
160+
widget_class(b::Box) = b.vert ? "VBox" : "Box"
161161
widget_class(::Latex) = "Label"
162-
widget_class(::Progress) = "Progress"
162+
widget_class(::Progress) = "FloatProgress"
163163
widget_class{T<:Integer}(::Slider{T}) = "IntSlider"
164164
widget_class(::Button) = "Button"
165165
widget_class(::Textarea) = "Textarea"
@@ -174,13 +174,8 @@ widget_class(w, suffix) = widget_class(w) * suffix
174174
view_name(w) = widget_class(w, "View")
175175
model_name(w) = widget_class(w, "Model")
176176

177-
"""
178-
Update output widgets
179-
"""
180-
update!(p::Progress, val) = begin
181-
p.value = val;
182-
update_view(p)
183-
end
177+
# Special cases
178+
view_name(w::Progress) = "ProgressView"
184179

185180
function metadata(x::Widget)
186181
display_widget(x)
@@ -320,4 +315,4 @@ end
320315
include("statedict.jl")
321316
include("handle_msg.jl")
322317

323-
end
318+
end

src/IJulia/setup_old.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Interact: update_view, Slider, Widget, InputWidget, Latex, HTML, recv_msg
1010
statedict, viewdict, Layout, Box,
1111
Progress, Checkbox, Button, ToggleButton, Textarea, Textbox, Options
1212

13-
export mimewritable
13+
export mimewritable
1414

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

@@ -174,14 +174,6 @@ widget_class(w, suffix) = widget_class(w) * suffix
174174
view_name(w) = widget_class(w, "View")
175175
model_name(w) = widget_class(w, "Model")
176176

177-
"""
178-
Update output widgets
179-
"""
180-
update!(p::Progress, val) = begin
181-
p.value = val;
182-
update_view(p)
183-
end
184-
185177
function metadata(x::Widget)
186178
display_widget(x)
187179
Dict()
@@ -311,4 +303,4 @@ end
311303
include("statedict_old.jl")
312304
include("handle_msg_old.jl")
313305

314-
end
306+
end

src/IJulia/statedict.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818
:_model_name => "FloatSliderModel",
1919
:readout => s.readout,
2020
:readout_format => s.readout_format,
21+
:orientation => s.orientation,
2122
:continuous_update=>s.continuous_update,
2223
)
2324

@@ -47,6 +48,8 @@ statedict{view, T}(d::Options{view, T}) =
4748
:icons=>d.icons,
4849
:tooltips=>d.tooltips,
4950
:readout => d.readout,
51+
:continuous_update=>d.continuous_update,
52+
:orientation => d.orientation,
5053
:_options_labels=>collect(keys(d.options)))
5154

5255
statedict(w::Widget) = begin

src/Interact.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ include("manipulate.jl")
9292

9393
const ijulia_setup_path = joinpath(dirname(@__FILE__), "IJulia", "setup.jl")
9494
const ijulia_setup_path_old = joinpath(dirname(@__FILE__), "IJulia", "setup_old.jl")
95-
const ipywidgets_version = joinpath(dirname(@__FILE__), "..", "deps", "ipywidgets_version")
95+
const ipywidgets_version = joinpath(dirname(@__FILE__), "..", "deps", "widgets_version")
9696

9797
function __init__()
9898
if isdefined(Main, :IJulia)
99-
if isfile(ipywidgets_version)
99+
if haskey(ENV, "WIDGETS_VERSION")
100+
v = VersionNumber(ENV["WIDGETS_VERSION"])
101+
elseif isfile(ipywidgets_version)
100102
v = VersionNumber(strip(readline(ipywidgets_version)))
101-
if v >= v"6.0.0"
102-
include(ijulia_setup_path)
103-
else
104-
include(ijulia_setup_path_old)
105-
end
106103
else
104+
v = v"3.0.0"
105+
end
106+
if v >= v"3.0.0"
107107
include(ijulia_setup_path)
108+
else
109+
include(ijulia_setup_path_old)
108110
end
109111
end
110112
end

src/widgets.jl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export slider, vslider, togglebutton, button,
44
radiobuttons, dropdown, selection,
55
togglebuttons, html, latex, hbox, vbox,
66
progress, widget, selection_slider, vselection_slider,
7-
set!
7+
set!, update!
88

99
### Layout Widgets
1010
type Layout <: Widget
@@ -303,6 +303,7 @@ type Options{view, T} <: InputWidget{T}
303303
tooltips::AbstractArray
304304
readout::Bool
305305
orientation::AbstractString
306+
continuous_update::Bool
306307
end
307308

308309
labels2idxs(d::OptionDict, labels) = findin(keys(d), labels)
@@ -320,13 +321,14 @@ Options(view::Symbol, options::OptionDict;
320321
orientation="horizontal",
321322
syncsig=true,
322323
syncnearest=true,
324+
continuous_update=true,
323325
sel_mid_idx=0) = begin
324326
#sel_mid_idx set in selection_slider(...) so default value_label is middle of range
325327
sel_mid_idx != 0 && (value_label = collect(keys(options.dict))[sel_mid_idx])
326328
signal, value = init_wsigval(signal, value; typ=typ, default=options[value_label])
327329
typ = eltype(signal)
328330
ow = Options{view, typ}(signal, label, value, value_label, index,
329-
options, icons, tooltips, readout, orientation)
331+
options, icons, tooltips, readout, orientation, continuous_update)
330332
if syncsig
331333
syncselnearest = view == :SelectionSlider && typ <: Real && syncnearest
332334
if view != :SelectMultiple
@@ -340,8 +342,7 @@ Options(view::Symbol, options::OptionDict;
340342
if syncselnearest
341343
val = nearest_val(keys(ow.options.invdict), val)
342344
end
343-
if haskey(ow.options.invdict, val) &&
344-
ow.value_label != ow.options.invdict[val]
345+
if haskey(ow.options.invdict, val)
345346
ow.value_label = ow.options.invdict[val]
346347
ow.index = labels2idxs(ow.options, [ow.value_label]) |> first
347348
update_view(ow)
@@ -361,8 +362,10 @@ function Options(view::Symbol,
361362
Options(view, getoptions(options); kwargs...)
362363
end
363364

365+
getoptions(options::AbstractArray{<:Union{Pair, Tuple}}) = getoptions(Dict(options))
366+
364367
function getoptions(options)
365-
opts = OrderedDict()
368+
opts = OrderedDict{String, eltype(values(options))}()
366369
for el in options
367370
addoption!(opts, el)
368371
end
@@ -477,7 +480,7 @@ latex(value; label="") = Latex(label, mimewritable("application/x-latex", value)
477480

478481
type Progress <: Widget
479482
label::AbstractString
480-
value::Int
483+
value::Float64
481484
range::Range
482485
orientation::String
483486
readout::Bool
@@ -486,10 +489,18 @@ type Progress <: Widget
486489
end
487490

488491
progress(args...) = Progress(args...)
489-
progress(;label="", value=0, range=0:100, orientation="horizontal",
492+
progress(;label="", range=0.0:0.1:100, value=first(range), orientation="horizontal",
490493
readout=true, readout_format="d", continuous_update=true) =
491494
Progress(label, value, range, orientation, readout, readout_format, continuous_update)
492495

496+
"""
497+
Update output widgets
498+
"""
499+
function update!(p::Progress, val)
500+
p.value = val;
501+
update_view(p)
502+
end
503+
493504
# Make a widget out of a domain
494505
widget(x::Signal, label="") = x
495506
widget(x::Widget, label="") = x

test/REQUIRE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ julia 0.4
22
Compat 0.8.0
33
BaseTestNext
44
IJulia
5+
NBInclude
6+
Colors
7+
Compose

test/runtests.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,24 @@ module HygieneTest2
2828
2 * i, j * " hello"
2929
end
3030
end
31+
32+
# Notebooks
33+
# notebookdirs = [joinpath(@__DIR__, "notebooks"), joinpath(@__DIR__, "..", "doc", "notebooks")]
34+
notebookdirs = [joinpath(@__DIR__, "..", "doc", "notebooks")] # Interact Manual Tests.ipynb is broken (flatten call)
35+
excludes = [joinpath(@__DIR__, "..", "doc", "notebooks", "03-Interactive Diagrams and Plots.ipynb")]
36+
for notebookdir in notebookdirs
37+
for file in readdir(notebookdir)
38+
path = joinpath(notebookdir, file)
39+
path in excludes && continue
40+
name, ext = splitext(file)
41+
lowercase(ext) == ".ipynb" || continue
42+
@eval module $(gensym()) # Each notebook is run in its own module.
43+
using Base.Test
44+
using NBInclude
45+
@testset "$($name)" begin
46+
nbinclude($path, regex = r"^((?!\#NBSKIP).)*$"s) # Use #NBSKIP in a cell to skip it during tests.
47+
end
48+
end # module
49+
end
50+
end
51+

0 commit comments

Comments
 (0)