Skip to content

Commit

Permalink
Add Spinner class to switch beween Int and Float Spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
xavArtley committed Sep 6, 2020
1 parent 51f1b4e commit 050e6da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/reference/widgets/FloatInput.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
"metadata": {},
"outputs": [],
"source": [
"float_input = pn.widgets.IntInput(name='Integer Input', value=None, placeholder='Enter an integer', format=\"0 $\")\n",
"float_input = pn.widgets.FloatInput(name='Float Input', value=2.1, placeholder='Enter a number', format=\"0.0\")\n",
"float_input"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``IntInput.value`` returns the value of the widget"
"``FloatInput.value`` returns the value of the widget"
]
},
{
Expand All @@ -60,7 +60,7 @@
"metadata": {},
"outputs": [],
"source": [
"int_input.value"
"float_input.value"
]
},
{
Expand All @@ -69,7 +69,7 @@
"source": [
"### Controls\n",
"\n",
"The `IntInput` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:"
"The `FloatInput` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:"
]
},
{
Expand All @@ -78,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.Row(int_input.controls(jslink=True), int_input)"
"pn.Row(float_input.controls(jslink=True), float_input)"
]
},
{
Expand All @@ -105,7 +105,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.7.9"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions panel/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
FloatInput,
IntSpinner,
FloatSpinner,
Spinner,
PasswordInput,
TextAreaInput,
)
Expand Down
11 changes: 11 additions & 0 deletions panel/widgets/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ class FloatSpinner(_SpinnerBase, FloatInput):
value_throttled = param.Number(default=None, allow_None=True)


class Spinner:

def __new__(self, **params):
param_list = ["value", "start", "stop", "step"]

if all(isinstance(params.get(p, 0), int) for p in param_list):
return IntSpinner(**params)
else:
return FloatSpinner(**params)


class LiteralInput(Widget):
"""
LiteralInput allows declaring Python literals using a text
Expand Down

0 comments on commit 050e6da

Please sign in to comment.