@@ -3,7 +3,8 @@ export slider, togglebutton, button,
3
3
checkbox, textbox, textarea,
4
4
radiobuttons, dropdown, selection,
5
5
togglebuttons, html, latex, hbox, vbox,
6
- progress, widget, selection_slider
6
+ progress, widget, selection_slider,
7
+ set!
7
8
8
9
const Empty = VERSION < v " 0.4.0-dev" ? Nothing : Void
9
10
@@ -339,30 +340,23 @@ Options(view::Symbol, options::OptionDict;
339
340
ow
340
341
end
341
342
342
- addoption! (opts, v:: NTuple{2} ) = opts[string (v[1 ])] = v[2 ]
343
- addoption! (opts, v) = opts[string (v)] = v
344
343
function Options (view:: Symbol ,
345
- options:: AbstractArray ;
344
+ options:: Union{Associative, AbstractArray} ;
346
345
kwargs... )
347
- opts = OrderedDict ()
348
- for v in options
349
- addoption! (opts, v)
350
- end
351
- optdict = OptionDict (opts)
352
- Options (view, optdict; kwargs... )
346
+ Options (view, getoptions (options); kwargs... )
353
347
end
354
348
355
- function Options (view:: Symbol ,
356
- options:: Associative ;
357
- kwargs... )
349
+ function getoptions (options)
358
350
opts = OrderedDict ()
359
- for (k, v) in options
360
- opts[ string (k)] = v
351
+ for el in options
352
+ addoption! (opts, el)
361
353
end
362
354
optdict = OptionDict (opts)
363
- Options (view, optdict; kwargs... )
364
355
end
365
356
357
+ addoption! (opts, v:: NTuple{2} ) = opts[string (v[1 ])] = v[2 ]
358
+ addoption! (opts, v) = opts[string (v)] = v
359
+
366
360
"""
367
361
dropdown(choices; label="", value, typ, icons, tooltips, signal)
368
362
@@ -481,3 +475,30 @@ widget(x::Associative, label="") = togglebuttons(x, label=label)
481
475
widget (x:: Bool , label= " " ) = checkbox (x, label= label)
482
476
widget (x:: AbstractString , label= " " ) = textbox (x, label= label, typ= AbstractString)
483
477
widget {T <: Number} (x:: T , label= " " ) = textbox (typ= T, value= x, label= label)
478
+
479
+ # ## Set!
480
+
481
+ """
482
+ `set!(w::Widget, fld::Symbol, val)`
483
+
484
+ Set the value of a widget property and update all displayed instances of the
485
+ widget. If `val` is a `Signal`, then updates to that signal will be reflected in
486
+ widget instances/views.
487
+
488
+ If `fld` is `:value`, `val` is also `push!`ed to `signal(w)`
489
+ """
490
+ function set! (w:: Widget , fld:: Symbol , val)
491
+ fld == :value && push! (signal (w), val)
492
+ setfield! (w, fld, val)
493
+ update_view (w)
494
+ w
495
+ end
496
+
497
+ set! (w:: Widget , fld:: Symbol , valsig:: Signal ) = begin
498
+ map (val -> set! (w, fld, val), valsig) |> preserve
499
+ end
500
+
501
+ set! {T<:Options} (w:: T , fld:: Symbol , val:: Union{Signal,Any} ) = begin
502
+ fld == :options && (val = getoptions (val))
503
+ invoke (set!, (Widget, Symbol, typeof (val)), w, fld, val)
504
+ end
0 commit comments