{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import panel as pn\n", "\n", "pn.extension()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``Player`` widget displays media-player-like controls that allow playing and stepping through a range of values. When playing it triggers events at a pre-defined interval on the frontend, advancing the player value each time. It falls into the broad category of single-value slider widgets that provide a compatible API and includes the [``IntSlider``](IntSlider.ipynb) and [``FloatSlider``](FloatSlider.ipynb) widgets.\n", "\n", "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](../how_to/interactivity/index.md). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](../../how_to/links/index.md) or [how to use them as part of declarative UIs with Param](../../how_to/param/index.html).\n", "\n", "#### Parameters:\n", "\n", "For details on other options for customizing the component see the [layout](../../how_to/layout/index.md) and [styling](../../how_to/styling/index.md) how-to guides.\n", "\n", "##### Core\n", "\n", "* **``direction``** (int): Current play direction of the Player (-1: playing in reverse,\n", "0: paused, 1: playing).\n", "* **``interval``** (int): Interval in milliseconds between updates\n", "* **``loop_policy``** (str): Looping policy; must be one of 'once', 'loop', or 'reflect'\n", "* **``start``** (int): The range's lower bound\n", "* **``end``** (int): The range's upper bound\n", "* **``step``** (int): The interval between values\n", "* **``value``** (int): The current integer value\n", "* **``value_throttled``** (int): The current integer value throttled until mouseup (when selected using slider)\n", "\n", "##### Display\n", "\n", "* **``disabled``** (boolean): Whether the widget is editable\n", "* **``name``** (str): The title of the widget\n", "* **``show_loop_controls``** (boolean): Whether radio buttons allowing to switch between loop policies options are shown\n", "\n", "___" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The widget has a number of buttons to go to the first or last value, step forward or backward, or play and pause the widget. It also provides control over the ``loop_policy`` which determines whether to play 'once', 'loop', or 'reflect'. Additionally ``-`` and ``+`` buttons slow down and speed up the player speed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "player = pn.widgets.Player(name='Player', start=0, end=100, value=32, loop_policy='loop')\n", "\n", "player" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Like most other widgets, ``Player`` has a value parameter that can be accessed or set:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "player.value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `Player` can be controlled programmatically using the `direction` parameter which has three possible states:\n", " \n", "- `-1`: playing in reverse\n", "- `0`: paused\n", "- `1`: playing\n", "\n", "Alternatively it can be controlled via the `.play`, `.pause` and `.reverse` methods:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import time\n", "\n", "player.play()\n", "time.sleep(2)\n", "player.reverse()\n", "time.sleep(2)\n", "player.pause()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Controls\n", "\n", "The `Player` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(player.controls(jslink=True), player)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }