Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spinner widget #368

Merged
merged 2 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions examples/reference/widgets/Spinner.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import panel as pn\n",
"\n",
"pn.extension()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ``Spinner`` widget allows selecting a value using a spinbox. It behaves like a slider except lower and upper bounds are optionals and a specific value can be entered\n",
"\n",
"For more information about listening to widget events and laying out widgets refer to the [widgets user guide](../../user_guide/Widgets.ipynb). Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the [param user guide](../../user_guide/Param.ipynb). To express interactivity entirely using Javascript without the need for a Python server take a look at the [links user guide](../../user_guide/Param.ipynb).\n",
"\n",
"#### Parameters:\n",
"\n",
"For layout and styling related parameters see the [customization user guide](../../user_guide/Customization.ipynb).\n",
"\n",
"##### Core\n",
"\n",
"* **``value``** (float or int): The initial value of the spinner\n",
"* **``step``** (float or int): The step added or subtracted to the current value\n",
"* **``start``** (float or int): Optional minimum allowable value\n",
"* **``end``** (float or int): Optional maximum allowable value\n",
"\n",
"##### Display\n",
"\n",
"* **``disabled``** (boolean): Whether the widget is editable\n",
"* **``name``** (str): The title of the widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spinner = pn.widgets.Spinner(name='Spinner', value=5., step=1e-1, start=0, end=10)\n",
"\n",
"spinner"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ``Spinner.value`` returns a float or int value:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spinner.value"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions panel/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .button import Button, Toggle # noqa
from .input import ( # noqa
ColorPicker, Checkbox, DatetimeInput, DatePicker, FileInput,
LiteralInput, StaticText, TextInput)
LiteralInput, StaticText, TextInput, Spinner)
from .misc import Audio # noqa
from .player import DiscretePlayer, Player # noqa
from .slider import ( # noqa
Expand All @@ -17,4 +17,4 @@
from .select import ( # noqa
AutocompleteInput, CheckBoxGroup, CheckButtonGroup, CrossSelector,
MultiSelect, RadioButtonGroup, RadioBoxGroup, Select, ToggleGroup)

23 changes: 21 additions & 2 deletions panel/widgets/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

from bokeh.models.widgets import (
CheckboxGroup as _BkCheckboxGroup, ColorPicker as _BkColorPicker,
DatePicker as _BkDatePicker, Div as _BkDiv, TextInput as _BkTextInput)
DatePicker as _BkDatePicker, Div as _BkDiv, TextInput as _BkTextInput,
Spinner as _BkSpinner)

from ..models import FileInput as _BkFileInput
from ..util import as_unicode
from .base import Widget



class TextInput(Widget):

value = param.String(default='', allow_None=True)
Expand Down Expand Up @@ -129,6 +129,25 @@ class ColorPicker(Widget):
_rename = {'value': 'color', 'name': 'title'}


class Spinner(Widget):

start = param.Number(default=None, doc="""
Optional minimum allowable value""")

end = param.Number(default=None, doc="""
Optional maximum allowable value""")

value = param.Number(default=0, doc="""
The initial value of the spinner""")

step = param.Number(default=1, doc="""
The step added or subtracted to the current value""")

_widget_type = _BkSpinner

_rename = {'name': 'title', 'start': 'low', 'end': 'high'}


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