|
1 | 1 | import panel as pn |
2 | 2 | import param |
3 | | -#from dask.distributed import as_completed |
4 | 3 | from asyncio import as_completed |
5 | 4 | from panel.pane import HTML, Markdown |
6 | 5 | from panel.reactive import ReactiveHTML |
7 | | -from panel.util import as_unicode |
8 | | -from panel.widgets.input import _BkTextInput, StaticText |
9 | | -from panel.viewable import Viewer |
10 | | - |
11 | | -# todo remove |
12 | | -class NumericInput(pn.widgets.input.Widget): |
13 | | - """ |
14 | | - NumericInput allows input of floats with bounds |
15 | | - """ |
16 | | - |
17 | | - type = param.ClassSelector(default=None, class_=(type, tuple), is_instance=True) |
18 | | - |
19 | | - value = param.Number(default=None) |
20 | | - |
21 | | - start = param.Number(default=None, allow_None=True) |
22 | | - |
23 | | - end = param.Number(default=None, allow_None=True) |
24 | | - |
25 | | - _rename = { |
26 | | - "name": "title", |
27 | | - "type": None, |
28 | | - "serializer": None, |
29 | | - "start": None, |
30 | | - "end": None, |
31 | | - } |
32 | | - |
33 | | - _source_transforms = {"value": """JSON.parse(value.replace(/'/g, '"'))"""} |
34 | | - |
35 | | - _target_transforms = { |
36 | | - "value": """JSON.stringify(value).replace(/,/g, ", ").replace(/:/g, ": ")""" |
37 | | - } |
38 | | - |
39 | | - _widget_type = _BkTextInput |
40 | | - |
41 | | - def __init__(self, **params): |
42 | | - |
43 | | - super(NumericInput, self).__init__(**params) |
44 | | - self._state = "" |
45 | | - self._validate(None) |
46 | | - self._callbacks.append(self.param.watch(self._validate, "value")) |
47 | | - |
48 | | - def _validate(self, event): |
49 | | - if self.type is None: |
50 | | - return |
51 | | - new = self.value |
52 | | - if not isinstance(new, self.type) and new is not None: |
53 | | - if event: |
54 | | - self.value = event.old |
55 | | - types = ( |
56 | | - repr(self.type) if isinstance(self.type, tuple) else self.type.__name__ |
57 | | - ) |
58 | | - raise ValueError( |
59 | | - "LiteralInput expected %s type but value %s " |
60 | | - "is of type %s." % (types, new, type(new).__name__) |
61 | | - ) |
62 | | - |
63 | | - def _bound_value(self, value): |
64 | | - if self.start is not None: |
65 | | - value = max(value, self.start) |
66 | | - if self.end is not None: |
67 | | - value = min(value, self.end) |
68 | | - return value |
69 | | - |
70 | | - def _process_property_change(self, msg): |
71 | | - if "value" in msg and msg["value"] is not None: |
72 | | - try: |
73 | | - value = float(msg["value"]) |
74 | | - msg["value"] = self._bound_value(value) |
75 | | - if msg["value"] != value: |
76 | | - self.param.trigger("value") |
77 | | - except ValueError: |
78 | | - msg.pop("value") |
79 | | - if "placeholder" in msg and msg["placeholder"] is not None: |
80 | | - try: |
81 | | - msg["placeholder"] = self._format_value(float(msg["placeholder"])) |
82 | | - except ValueError: |
83 | | - msg.pop("placeholder") |
84 | | - return msg |
85 | | - |
86 | | - def _process_param_change(self, msg): |
87 | | - msg = super(NumericInput, self)._process_param_change(msg) |
88 | | - |
89 | | - if "start" in msg: |
90 | | - start = msg.pop("start") |
91 | | - self.param.value.bounds[0] = start |
92 | | - if "end" in msg: |
93 | | - end = msg.pop("end") |
94 | | - self.param.value.bounds[1] = end |
95 | | - |
96 | | - if "value" in msg: |
97 | | - value = "" if msg["value"] is None else msg["value"] |
98 | | - value = as_unicode(value) |
99 | | - msg["value"] = value |
100 | | - msg["title"] = self.name |
101 | | - return msg |
| 6 | +from panel.widgets.input import StaticText |
102 | 7 |
|
103 | 8 |
|
104 | 9 | class ColoredStaticText(StaticText): |
|
0 commit comments