Skip to content

Commit

Permalink
Make it possible to add custom mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Sep 1, 2024
1 parent 1ef4784 commit 8286744
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ class Param(Pane):
Dictionary of widget overrides, mapping from parameter name
to widget class.""")

mapping: ClassVar[Mapping[param.Parameter, Widget | Callable[[param.Parameter], Widget]]] = {}

@classproperty
def mapping(cls) -> Mapping[param.Parameter, Widget | Callable[[param.Parameter], Widget]]:
def _default_mapping(cls) -> Mapping[param.Parameter, Widget | Callable[[param.Parameter], Widget]]:
from .widgets import (
ArrayInput, Button, Checkbox, ColorPicker, DatePicker,
DateRangeSlider, DatetimeInput, DatetimeRangeSlider, FileInput,
Expand Down Expand Up @@ -767,10 +769,11 @@ def applies(cls, obj: Any) -> float | bool | None:
@classmethod
def widget_type(cls, pobj):
ptype = type(pobj)
mapping = cls._default_mapping | cls.mapping
for t in classlist(ptype)[::-1]:
if t not in cls.mapping:
if t not in mapping:
continue
wtype = cls.mapping[t]
wtype = mapping[t]
if isinstance(wtype, types.FunctionType):
return wtype(pobj)
return wtype
Expand Down

0 comments on commit 8286744

Please sign in to comment.