{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The ``DiscretePlayer`` widget displays media-player-like controls that allow playing and stepping through the provided options. 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, option-selection widgets that provide a compatible API and include the [``AutocompleteInput``](AutocompleteInput.ipynb), [``Select``](Select.ipynb) and [``DiscreteSlider``](DiscreteSlider.ipynb) widgets.\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",
    "* **``direction``** (int): Current play direction of the Player (-1: playing in reverse,\n",
    "0: paused, 1: playing).\n",
    "* **``options``** (list or dict): A list or dictionary of options to select from\n",
    "* **``value``** (object): The current value; must be one of the option values\n",
    "\n",
    "##### Display\n",
    "\n",
    "* **``disabled``** (boolean): Whether the widget is editable\n",
    "* **``interval``** (int): Interval in milliseconds between updates\n",
    "* **``name``** (str): The title of the widget\n",
    "* **``loop_policy``** (str): Looping policy; must be one of 'once', 'loop', or 'reflect'\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, and 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": [
    "discrete_player = pn.widgets.DiscretePlayer(name='Discrete Player', options=[2, 4, 8, 16, 32, 64, 128], value=8, loop_policy='loop')\n",
    "\n",
    "discrete_player"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Like most other widgets, ``DiscretePlayer`` has a value parameter that can be accessed or set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "discrete_player.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `DiscretePlayer` 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",
    "discrete_player.play()\n",
    "time.sleep(2)\n",
    "discrete_player.reverse()\n",
    "time.sleep(2)\n",
    "discrete_player.pause()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Controls\n",
    "\n",
    "The `DiscretePlayer` 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(discrete_player.controls(jslink=True), discrete_player)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
