-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathipywidgets.py
3536 lines (2922 loc) · 138 KB
/
ipywidgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import datetime
import typing
from typing import Any, Callable, Dict, Sequence, Union
import ipywidgets
import ipywidgets as widgets
import ipywidgets.widgets.widget_description
import ipywidgets.widgets.widget_int
import reacton
from reacton.core import Element, ValueElement, _event_handler_exception_wrapper
from .utils import implements
# def use_on_click(on_click):
# def add_event_handler(button: widgets.Button):
# def handler(change):
# on_click()
# def cleanup():
# button.on_click(handler, remove=True)
# button.on_click(handler)
# return cleanup
# reacton.use_effect(add_event_handler)
def slider_int(value=1, description="", min=0, max=100, key=None, **kwargs):
key = key or str(value) + str(description)
value, set_value = reacton.use_state(value, key)
IntSlider(value=value, description=description, min=min, max=max, on_value=set_value, **kwargs)
return value
def text_int(value=1, description="", key=None, **kwargs):
key = key or str(value) + str(description)
value, set_value = reacton.use_state(value, key)
IntText(value=value, description=description, on_value=set_value, **kwargs)
return value
def slider_float(value=1, description="", min=0, max=100, key=None, **kwargs):
key = key or str(value) + str(description)
value, set_value = reacton.use_state(value, key)
FloatSlider(value=value, description=description, min=min, max=max, on_value=set_value, **kwargs)
return value
def checkbox(value=True, description="", key=None, **kwargs):
key = key or str(value) + str(description)
value, set_value = reacton.use_state(value, key)
Checkbox(value=value, description=description, on_value=set_value)
return value
def color(value="red", description="", key=None, **kwargs):
key = key or str(value) + str(description)
value, set_value = reacton.use_state(value, key)
ColorPicker(value=value, description=description, on_value=set_value)
return value
def text(value="Hi there", description="", key=None, **kwargs):
key = key or str(value) + str(description)
value, set_value = reacton.use_state(value, key)
Text(value=value, description=description, on_value=set_value)
return value
def dropdown(value="foo", options=["foo", "bar"], description="", key=None, **kwargs):
key = key or str(value) + str(description) + str(options)
value, set_value = reacton.use_state(value, key)
def set_index(index):
set_value(options[index])
Dropdown(value=value, description=description, options=options, on_index=set_index)
return value
# @reacton.component
# def ButtonWithClick(on_click=None, **kwargs):
# if on_click is not None:
# # TODO: in react, we cannot do this conditionally, we can appearently
# use_on_click(on_click)
# return Button(**kwargs)
class ButtonElement(reacton.core.Element):
def _add_widget_event_listener(self, widget: widgets.Widget, name: str, callback: Callable):
if name == "on_click":
callback_exception_safe = _event_handler_exception_wrapper(callback)
def on_click(change):
callback_exception_safe()
key = (widget.model_id, name, callback)
self._callback_wrappers[key] = on_click
widget.on_click(on_click)
else:
super()._add_widget_event_listener(widget, name, callback)
def _remove_widget_event_listener(self, widget: widgets.Widget, name: str, callback: Callable):
if name == "on_click":
key = (widget.model_id, name, callback)
on_click = self._callback_wrappers[key]
del self._callback_wrappers[key]
widget.on_click(on_click, remove=True)
else:
super()._remove_widget_event_listener(widget, name, callback)
if __name__ == "__main__":
from . import generate
class CodeGen(generate.CodeGen):
element_classes = {ipywidgets.Button: ButtonElement}
def get_extra_argument(self, cls):
return {ipywidgets.Button: [("on_click", None, typing.Callable[[], Any])]}.get(cls, [])
current_module = __import__(__name__)
CodeGen([widgets, ipywidgets.widgets.widget_description, ipywidgets.widgets.widget_int]).generate(__file__)
def ViewcountVBox(on_view_count) -> Element[ipywidgets.widgets.widget_box.VBox]:
"""Exposes the Widget._view_count throught a VBox, which is not exposed in any widget"""
widget_cls = ipywidgets.widgets.widget_box.VBox
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs={"_view_count": 0, "on__view_count": on_view_count})
# generated code:
def _Accordion(
box_style: str = "",
children: Sequence[Element[ipywidgets.Widget]] = (),
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
selected_index: int = 0,
on_box_style: typing.Callable[[str], Any] = None,
on_children: typing.Callable[[Sequence[Element[ipywidgets.Widget]]], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_selected_index: typing.Callable[[int], Any] = None,
) -> Element[ipywidgets.widgets.widget_selectioncontainer.Accordion]:
"""Displays children each on a separate accordion page.
:param box_style: Use a predefined styling for the box.
:param children: List of widget children
:param selected_index: The index of the selected page. This is either an integer selecting a particular sub-widget, or None to have no widgets selected.
"""
...
@implements(_Accordion)
def Accordion(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
widget_cls = ipywidgets.widgets.widget_selectioncontainer.Accordion
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _Accordion
def _AppLayout(
align_items: str = None,
box_style: str = "",
center: Element[ipywidgets.Widget] = None,
children: Sequence[Element[ipywidgets.Widget]] = (),
footer: Element[ipywidgets.Widget] = None,
grid_gap: str = None,
header: Element[ipywidgets.Widget] = None,
height: str = None,
justify_content: str = None,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
left_sidebar: Element[ipywidgets.Widget] = None,
merge: bool = True,
pane_heights: tuple = ("1fr", "3fr", "1fr"),
pane_widths: tuple = ("1fr", "2fr", "1fr"),
right_sidebar: Element[ipywidgets.Widget] = None,
width: str = None,
on_align_items: typing.Callable[[str], Any] = None,
on_box_style: typing.Callable[[str], Any] = None,
on_center: typing.Callable[[Element[ipywidgets.Widget]], Any] = None,
on_children: typing.Callable[[Sequence[Element[ipywidgets.Widget]]], Any] = None,
on_footer: typing.Callable[[Element[ipywidgets.Widget]], Any] = None,
on_grid_gap: typing.Callable[[str], Any] = None,
on_header: typing.Callable[[Element[ipywidgets.Widget]], Any] = None,
on_height: typing.Callable[[str], Any] = None,
on_justify_content: typing.Callable[[str], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_left_sidebar: typing.Callable[[Element[ipywidgets.Widget]], Any] = None,
on_merge: typing.Callable[[bool], Any] = None,
on_pane_heights: typing.Callable[[tuple], Any] = None,
on_pane_widths: typing.Callable[[tuple], Any] = None,
on_right_sidebar: typing.Callable[[Element[ipywidgets.Widget]], Any] = None,
on_width: typing.Callable[[str], Any] = None,
) -> Element[ipywidgets.widgets.widget_templates.AppLayout]:
"""Define an application like layout of widgets.
Parameters
----------
header: instance of Widget
left_sidebar: instance of Widget
center: instance of Widget
right_sidebar: instance of Widget
footer: instance of Widget
widgets to fill the positions in the layout
merge: bool
flag to say whether the empty positions should be automatically merged
pane_widths: list of numbers/strings
the fraction of the total layout width each of the central panes should occupy
(left_sidebar,
center, right_sidebar)
pane_heights: list of numbers/strings
the fraction of the width the vertical space that the panes should occupy
(left_sidebar, center, right_sidebar)
grid_gap : str
CSS attribute used to set the gap between the grid cells
justify_content : str, in ['flex-start', 'flex-end', 'center', 'space-between', 'space-around']
CSS attribute used to align widgets vertically
align_items : str, in ['top', 'bottom', 'center', 'flex-start', 'flex-end', 'baseline', 'stretch']
CSS attribute used to align widgets horizontally
width : str
height : str
width and height
Examples
--------
:param align_items: The align-items CSS attribute.
:param box_style: Use a predefined styling for the box.
:param children: List of widget children
:param grid_gap: The grid-gap CSS attribute.
:param height: The width CSS attribute.
:param justify_content: The justify-content CSS attribute.
:param width: The width CSS attribute.
"""
...
@implements(_AppLayout)
def AppLayout(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
widget_cls = ipywidgets.widgets.widget_templates.AppLayout
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _AppLayout
def _Audio(
autoplay: bool = True,
controls: bool = True,
format: str = "mp3",
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
loop: bool = True,
value: bytes = b"",
on_autoplay: typing.Callable[[bool], Any] = None,
on_controls: typing.Callable[[bool], Any] = None,
on_format: typing.Callable[[str], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_loop: typing.Callable[[bool], Any] = None,
on_value: typing.Callable[[bytes], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_media.Audio, bytes]:
"""Displays a audio as a widget.
The `value` of this widget accepts a byte string. The byte string is the
raw audio data that you want the browser to display. You can explicitly
define the format of the byte string using the `format` trait (which
defaults to "mp3").
If you pass `"url"` to the `"format"` trait, `value` will be interpreted
as a URL as bytes encoded in UTF-8.
:param autoplay: When true, the audio starts when it's displayed
:param controls: Specifies that audio controls should be displayed (such as a play/pause button etc)
:param format: The format of the audio.
:param loop: When true, the audio will start from the beginning after finishing
:param value: The media data as a byte string.
"""
...
@implements(_Audio)
def Audio(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
widget_cls = ipywidgets.widgets.widget_media.Audio
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _Audio
def _BoundedFloatText(
continuous_update: bool = False,
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
max: float = 100.0,
min: float = 0.0,
step: float = None,
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: float = 0.0,
on_continuous_update: typing.Callable[[bool], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_max: typing.Callable[[float], Any] = None,
on_min: typing.Callable[[float], Any] = None,
on_step: typing.Callable[[float], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[float], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_float.BoundedFloatText, float]:
"""Displays a float value within a textbox. Value must be within the range specified.
For a textbox in which the value doesn't need to be within a specific range, use FloatText.
Parameters
----------
value : float
value displayed
min : float
minimal value of the range of possible values displayed
max : float
maximal value of the range of possible values displayed
step : float
step of the increment (if None, any step is allowed)
description : str
description displayed next to the textbox
:param continuous_update: Update the value as the user types. If False, update on submission, e.g., pressing Enter or navigating away.
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes
:param max: Max value
:param min: Min value
:param step: Minimum step to increment the value
:param style: Styling customizations
:param value: Float value
"""
...
@implements(_BoundedFloatText)
def BoundedFloatText(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_float.BoundedFloatText
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _BoundedFloatText
def _BoundedIntText(
continuous_update: bool = False,
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
max: int = 100,
min: int = 0,
step: int = 1,
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: int = 0,
on_continuous_update: typing.Callable[[bool], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_max: typing.Callable[[int], Any] = None,
on_min: typing.Callable[[int], Any] = None,
on_step: typing.Callable[[int], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[int], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_int.BoundedIntText, int]:
"""Textbox widget that represents an integer bounded from above and below.
:param continuous_update: Update the value as the user types. If False, update on submission, e.g., pressing Enter or navigating away.
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes
:param max: Max value
:param min: Min value
:param step: Minimum step to increment the value
:param style: Styling customizations
:param value: Int value
"""
...
@implements(_BoundedIntText)
def BoundedIntText(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_int.BoundedIntText
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _BoundedIntText
def _Box(
box_style: str = "",
children: Sequence[Element[ipywidgets.Widget]] = (),
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
on_box_style: typing.Callable[[str], Any] = None,
on_children: typing.Callable[[Sequence[Element[ipywidgets.Widget]]], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
) -> Element[ipywidgets.widgets.widget_box.Box]:
"""Displays multiple widgets in a group.
The widgets are laid out horizontally.
Parameters
----------
children: iterable of Widget instances
list of widgets to display
box_style: str
one of 'success', 'info', 'warning' or 'danger', or ''.
Applies a predefined style to the box. Defaults to '',
which applies no pre-defined style.
Examples
--------
>>> import ipywidgets as widgets
>>> title_widget = widgets.HTML('<em>Box Example</em>')
>>> slider = widgets.IntSlider()
>>> widgets.Box([title_widget, slider])
:param box_style: Use a predefined styling for the box.
:param children: List of widget children
"""
...
@implements(_Box)
def Box(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
widget_cls = ipywidgets.widgets.widget_box.Box
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _Box
def _Button(
button_style: str = "",
description: str = "",
disabled: bool = False,
icon: str = "",
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_button.ButtonStyle]] = {},
tooltip: str = "",
on_button_style: typing.Callable[[str], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_icon: typing.Callable[[str], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_button.ButtonStyle]]], Any] = None,
on_tooltip: typing.Callable[[str], Any] = None,
on_click: typing.Callable[[], typing.Any] = None,
) -> Element[ipywidgets.widgets.widget_button.Button]:
"""Button widget.
This widget has an `on_click` method that allows you to listen for the
user clicking on the button. The click event itself is stateless.
Parameters
----------
description: str
description displayed next to the button
tooltip: str
tooltip caption of the toggle button
icon: str
font-awesome icon name
disabled: bool
whether user interaction is enabled
:param button_style: Use a predefined styling for the button.
:param description: Button label.
:param disabled: Enable or disable user changes.
:param icon: Font-awesome icon name, without the 'fa-' prefix.
:param tooltip: Tooltip caption of the button.
"""
...
@implements(_Button)
def Button(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = ButtonStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_button.Button
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ButtonElement(comp, kwargs=kwargs)
del _Button
def _ButtonStyle(
button_color: str = None,
font_weight: str = "",
on_button_color: typing.Callable[[str], Any] = None,
on_font_weight: typing.Callable[[str], Any] = None,
) -> Element[ipywidgets.widgets.widget_button.ButtonStyle]:
"""Button style widget.
:param button_color: Color of the button
:param font_weight: Button text font weight.
"""
...
@implements(_ButtonStyle)
def ButtonStyle(**kwargs):
widget_cls = ipywidgets.widgets.widget_button.ButtonStyle
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _ButtonStyle
def _Checkbox(
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
indent: bool = True,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: bool = False,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_indent: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[bool], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_bool.Checkbox, bool]:
"""Displays a boolean `value` in the form of a checkbox.
Parameters
----------
value : {True,False}
value of the checkbox: True-checked, False-unchecked
description : str
description displayed next to the checkbox
indent : {True,False}
indent the control to align with other controls with a description. The style.description_width attribute controls this width for consistence with other controls.
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes.
:param indent: Indent the control to align with other controls with a description.
:param style: Styling customizations
:param value: Bool value
"""
...
@implements(_Checkbox)
def Checkbox(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_bool.Checkbox
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _Checkbox
def _ColorPicker(
concise: bool = False,
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: str = "black",
on_concise: typing.Callable[[bool], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[str], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_color.ColorPicker, str]:
"""
:param concise: Display short version with just a color selector.
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes.
:param style: Styling customizations
:param value: The color value.
"""
...
@implements(_ColorPicker)
def ColorPicker(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_color.ColorPicker
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _ColorPicker
def _Combobox(
continuous_update: bool = True,
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
ensure_option: bool = False,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
options: Sequence[str] = (),
placeholder: str = "\u200b",
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: str = "",
on_continuous_update: typing.Callable[[bool], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_ensure_option: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_options: typing.Callable[[Sequence[str]], Any] = None,
on_placeholder: typing.Callable[[str], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[str], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_string.Combobox, str]:
"""Single line textbox widget with a dropdown and autocompletion.
:param continuous_update: Update the value as the user types. If False, update on submission, e.g., pressing Enter or navigating away.
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes
:param ensure_option: If set, ensure value is in options. Implies continuous_update=False.
:param options: Dropdown options for the combobox
:param placeholder: Placeholder text to display when nothing has been typed
:param style: Styling customizations
:param value: String value
"""
...
@implements(_Combobox)
def Combobox(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_string.Combobox
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _Combobox
def _Controller(
axes: Sequence[Element[ipywidgets.widgets.widget_controller.Axis]] = (),
buttons: Sequence[Element[ipywidgets.widgets.widget_controller.Button]] = (),
connected: bool = False,
index: int = 0,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
mapping: str = "",
name: str = "",
timestamp: float = 0.0,
on_axes: typing.Callable[[Sequence[Element[ipywidgets.widgets.widget_controller.Axis]]], Any] = None,
on_buttons: typing.Callable[[Sequence[Element[ipywidgets.widgets.widget_controller.Button]]], Any] = None,
on_connected: typing.Callable[[bool], Any] = None,
on_index: typing.Callable[[int], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_mapping: typing.Callable[[str], Any] = None,
on_name: typing.Callable[[str], Any] = None,
on_timestamp: typing.Callable[[float], Any] = None,
) -> Element[ipywidgets.widgets.widget_controller.Controller]:
"""Represents a game controller.
:param axes: The axes on the gamepad.
:param buttons: The buttons on the gamepad.
:param connected: Whether the gamepad is connected.
:param index: The id number of the controller.
:param mapping: The name of the control mapping.
:param name: The name of the controller.
:param timestamp: The last time the data from this gamepad was updated.
"""
...
@implements(_Controller)
def Controller(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
widget_cls = ipywidgets.widgets.widget_controller.Controller
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _Controller
def _CoreWidget() -> Element[ipywidgets.widgets.widget_core.CoreWidget]:
""" """
...
@implements(_CoreWidget)
def CoreWidget(**kwargs):
widget_cls = ipywidgets.widgets.widget_core.CoreWidget
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _CoreWidget
def _DOMWidget(
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
) -> Element[ipywidgets.widgets.domwidget.DOMWidget]:
"""Widget that can be inserted into the DOM"""
...
@implements(_DOMWidget)
def DOMWidget(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
widget_cls = ipywidgets.widgets.domwidget.DOMWidget
comp = reacton.core.ComponentWidget(widget=widget_cls)
return Element(comp, kwargs=kwargs)
del _DOMWidget
def _DatePicker(
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: datetime.date = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[datetime.date], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_date.DatePicker, datetime.date]:
"""
Display a widget for picking dates.
Parameters
----------
value: datetime.date
The current value of the widget.
disabled: bool
Whether to disable user changes.
Examples
--------
>>> import datetime
>>> import ipywidgets as widgets
>>> date_pick = widgets.DatePicker()
>>> date_pick.value = datetime.date(2019, 7, 9)
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes.
:param style: Styling customizations
"""
...
@implements(_DatePicker)
def DatePicker(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_date.DatePicker
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _DatePicker
def _Dropdown(
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
index: int = None,
label: str = None,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
options: Any = (),
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]] = {},
value: Any = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_index: typing.Callable[[int], Any] = None,
on_label: typing.Callable[[str], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_options: typing.Callable[[Any], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_description.DescriptionStyle]]], Any] = None,
on_value: typing.Callable[[Any], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_selection.Dropdown, Any]:
"""Allows you to select a single item from a dropdown.
Parameters
----------
options: list
The options for the dropdown. This can either be a list of values, e.g.
``['Galileo', 'Brahe', 'Hubble']`` or ``[0, 1, 2]``, or a list of
(label, value) pairs, e.g.
``[('Galileo', 0), ('Brahe', 1), ('Hubble', 2)]``.
index: int
The index of the current selection.
value: any
The value of the current selection. When programmatically setting the
value, a reverse lookup is performed among the options to check that
the value is valid. The reverse lookup uses the equality operator by
default, but another predicate may be provided via the ``equals``
keyword argument. For example, when dealing with numpy arrays, one may
set ``equals=np.array_equal``.
label: str
The label corresponding to the selected value.
disabled: bool
Whether to disable user changes.
description: str
Label for this input group. This should be a string
describing the widget.
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable user changes
:param index: Selected index
:param label: Selected label
:param options: Iterable of values, (label, value) pairs, or a mapping of {label: value} pairs that the user can select.
The labels are the strings that will be displayed in the UI, representing the
actual Python choices, and should be unique.
:param style: Styling customizations
:param value: Selected value
"""
...
@implements(_Dropdown)
def Dropdown(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = DescriptionStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_selection.Dropdown
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _Dropdown
def _FileUpload(
accept: str = "",
button_style: str = "",
data: list = [],
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
error: str = "",
icon: str = "upload",
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
metadata: list = [],
multiple: bool = False,
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_button.ButtonStyle]] = {},
value: dict = {},
on_accept: typing.Callable[[str], Any] = None,
on_button_style: typing.Callable[[str], Any] = None,
on_data: typing.Callable[[list], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_error: typing.Callable[[str], Any] = None,
on_icon: typing.Callable[[str], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_metadata: typing.Callable[[list], Any] = None,
on_multiple: typing.Callable[[bool], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_button.ButtonStyle]]], Any] = None,
on_value: typing.Callable[[dict], Any] = None,
) -> ValueElement[ipywidgets.widgets.widget_upload.FileUpload, dict]:
"""
Upload file(s) from browser to Python kernel as bytes
:param accept: File types to accept, empty string for all
:param button_style: Use a predefined styling for the button.
:param data: List of file content (bytes)
:param description: Description of the control.
:param description_tooltip: Tooltip for the description (defaults to description).
:param disabled: Enable or disable button
:param error: Error message
:param icon: Font-awesome icon name, without the 'fa-' prefix.
:param metadata: List of file metadata
:param multiple: If True, allow for multiple files upload
"""
...
@implements(_FileUpload)
def FileUpload(**kwargs):
if isinstance(kwargs.get("layout"), dict):
kwargs["layout"] = Layout(**kwargs["layout"])
if isinstance(kwargs.get("style"), dict):
kwargs["style"] = ButtonStyle(**kwargs["style"])
widget_cls = ipywidgets.widgets.widget_upload.FileUpload
comp = reacton.core.ComponentWidget(widget=widget_cls)
return ValueElement("value", comp, kwargs=kwargs)
del _FileUpload
def _FloatLogSlider(
base: float = 10.0,
continuous_update: bool = True,
description: str = "",
description_tooltip: str = None,
disabled: bool = False,
layout: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]] = {},
max: float = 4.0,
min: float = 0.0,
orientation: str = "horizontal",
readout: bool = True,
readout_format: str = ".3g",
step: float = 0.1,
style: Union[Dict[str, Any], Element[ipywidgets.widgets.widget_int.SliderStyle]] = {},
value: float = 1.0,
on_base: typing.Callable[[float], Any] = None,
on_continuous_update: typing.Callable[[bool], Any] = None,
on_description: typing.Callable[[str], Any] = None,
on_description_tooltip: typing.Callable[[str], Any] = None,
on_disabled: typing.Callable[[bool], Any] = None,
on_layout: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_layout.Layout]]], Any] = None,
on_max: typing.Callable[[float], Any] = None,
on_min: typing.Callable[[float], Any] = None,
on_orientation: typing.Callable[[str], Any] = None,
on_readout: typing.Callable[[bool], Any] = None,
on_readout_format: typing.Callable[[str], Any] = None,
on_step: typing.Callable[[float], Any] = None,
on_style: typing.Callable[[Union[Dict[str, Any], Element[ipywidgets.widgets.widget_int.SliderStyle]]], Any] = None,
on_value: typing.Callable[[float], Any] = None,