File: display.py

package info (click to toggle)
python-param 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,048 kB
  • sloc: python: 17,980; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import weakref

_display_accessors = {}
_reactive_display_objs = weakref.WeakSet()

def register_display_accessor(name, accessor, force=False):
    if name in _display_accessors and not force:
        if _display_accessors[name].__module__ != accessor.__module__:
            raise KeyError(
                f'Display accessor {name!r} already registered. Override it '
                'by setting force=True or unregister the existing accessor first.'
            )
    _display_accessors[name] = accessor
    for fn in _reactive_display_objs:
        setattr(fn, name, accessor(fn))

def unregister_display_accessor(name):
    if name not in _display_accessors:
        raise KeyError('No such display accessor: {name!r}')
    del _display_accessors[name]
    for fn in _reactive_display_objs:
        delattr(fn, name)