Skip to content

Commit

Permalink
Use widget_type for Param widget override (#1614)
Browse files Browse the repository at this point in the history
* Use widget_type for Param widget override

* Add docs
  • Loading branch information
philippjfr committed Oct 8, 2020
1 parent 29858cf commit b648692
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/user_guide/Param.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Also, it's possible to pass arguments to the widget in order to customize it. Instead of passing the widget, pass a dictionary with the desired options. Use the ``type`` keyword to map the widget. \n",
"Also, it's possible to pass arguments to the widget in order to customize it. Instead of passing the widget, pass a dictionary with the desired options. Use the ``widget_type`` keyword to map the widget. \n",
"\n",
"Taking up the previous example."
]
Expand All @@ -217,7 +217,7 @@
"outputs": [],
"source": [
"pn.Param(CustomExample.param, widgets={\n",
" 'select_string': {'type': pn.widgets.RadioButtonGroup, 'button_type': 'success'},\n",
" 'select_string': {'widget_type': pn.widgets.RadioButtonGroup, 'button_type': 'success'},\n",
" 'select_number': pn.widgets.DiscretePlayer}\n",
")"
]
Expand Down
8 changes: 5 additions & 3 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,14 @@ def widget(self, p_name):
widget_class_overridden = False
widget_class = self.widget_type(p_obj)
elif isinstance(self.widgets[p_name], dict):
if 'type' in self.widgets[p_name]:
widget_class = self.widgets[p_name].pop('type')
kw_widget = dict(self.widgets[p_name])
if 'widget_type' in self.widgets[p_name]:
widget_class = kw_widget.pop('widget_type')
elif 'type' in self.widgets[p_name]:
widget_class = kw_widget.pop('type')
else:
widget_class_overridden = False
widget_class = self.widget_type(p_obj)
kw_widget = self.widgets[p_name]
else:
widget_class = self.widgets[p_name]

Expand Down

0 comments on commit b648692

Please sign in to comment.