Skip to content

Commit 8286744

Browse files
committed
Make it possible to add custom mappings
1 parent 1ef4784 commit 8286744

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

panel/param.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ class Param(Pane):
213213
Dictionary of widget overrides, mapping from parameter name
214214
to widget class.""")
215215

216+
mapping: ClassVar[Mapping[param.Parameter, Widget | Callable[[param.Parameter], Widget]]] = {}
217+
216218
@classproperty
217-
def mapping(cls) -> Mapping[param.Parameter, Widget | Callable[[param.Parameter], Widget]]:
219+
def _default_mapping(cls) -> Mapping[param.Parameter, Widget | Callable[[param.Parameter], Widget]]:
218220
from .widgets import (
219221
ArrayInput, Button, Checkbox, ColorPicker, DatePicker,
220222
DateRangeSlider, DatetimeInput, DatetimeRangeSlider, FileInput,
@@ -767,10 +769,11 @@ def applies(cls, obj: Any) -> float | bool | None:
767769
@classmethod
768770
def widget_type(cls, pobj):
769771
ptype = type(pobj)
772+
mapping = cls._default_mapping | cls.mapping
770773
for t in classlist(ptype)[::-1]:
771-
if t not in cls.mapping:
774+
if t not in mapping:
772775
continue
773-
wtype = cls.mapping[t]
776+
wtype = mapping[t]
774777
if isinstance(wtype, types.FunctionType):
775778
return wtype(pobj)
776779
return wtype

0 commit comments

Comments
 (0)