diff --git a/param/parameterized.py b/param/parameterized.py index 696263cd2..695f8d12b 100644 --- a/param/parameterized.py +++ b/param/parameterized.py @@ -2400,9 +2400,55 @@ def type_script_repr(type_,imports,prefix,settings): dbprint_prefix=None +def name_if_set(parameterized): + """Return the name of this Parameterized if explicitly set to other than the default""" + class_name = parameterized.__class__.__name__ + default_name = re.match('^'+class_name+'[0-9]+$', parameterized.name) + return '' if default_name else parameterized.name - +def _get_param_repr(key, val, p, truncate=40): + """HTML representation for a single Parameter object and its value""" + if hasattr(val, "_repr_html_"): + try: + value = val._repr_html_(open=False) + except: + value = val._repr_html_() + else: + rep = repr(val) + value = (rep[:truncate] + '..') if len(rep) > truncate else rep + + constant = 'C' if p.constant else 'V' + readonly = 'RO' if p.readonly else 'RW' + allow_None = ' AN' if hasattr(p, 'allow_None') and p.allow_None else '' + mode = '%s %s%s' % (constant, readonly, allow_None) + + return f' ' \ + f'{key}' \ + f'{p.__class__.__name__}' \ + f'{getattr(p,"bounds","")}' \ + f'{mode}' \ + f'{value}' \ + f'\n' + + +def _parameterized_repr_html(p, open): + """HTML representation for a Parameterized object""" + title = p.__class__.name + " " + name_if_set(p) + openstr = " open" if open else "" + contents = "".join(_get_param_repr(key, val, p.param.params(key)) + for key, val in p.param.get_param_values()) + return ( + f'
\n' + ' \n' + f' {title}\n' + ' \n' + '
\n' + ' \n' + ' \n' + f'{contents}\n' + '
NameTypeBoundsModeValue
\n
\n
\n' + ) @add_metaclass(ParameterizedMetaclass) @@ -2698,6 +2744,9 @@ def state_pop(self): elif hasattr(g,'state_pop') and isinstance(g,Parameterized): g.state_pop() + def _repr_html_(self, open=True): + return _parameterized_repr_html(self, open) + # API to be accessed via param namespace