1 7
import param
2

3 7
from pyviz_comms import JupyterComm
4

5 7
from ..config import config
6 7
from ..models import IPyWidget as _BkIPyWidget
7 7
from .base import PaneBase
8

9

10 7
class IPyWidget(PaneBase):
11

12 7
    priority = 0.6
13

14 7
    @classmethod
15 2
    def applies(cls, obj):
16 7
        return (hasattr(obj, 'traits') and hasattr(obj, 'get_manager_state') and hasattr(obj, 'comm'))
17

18 7
    def _get_ipywidget(self, obj, doc, root, comm, **kwargs):
19 0
        if isinstance(comm, JupyterComm) and not config.embed:
20 0
            IPyWidget = _BkIPyWidget
21
        else:
22 0
            import ipykernel
23 0
            from ipywidgets_bokeh.widget import IPyWidget
24 0
            from ..io.ipywidget import PanelKernel
25 0
            if not isinstance(ipykernel.kernelbase.Kernel._instance, PanelKernel):
26 0
                kernel = PanelKernel(document=doc, key=str(id(doc)).encode('utf-8'))
27 0
                for w in obj.widgets.values():
28 0
                    w.comm.kernel = kernel
29 0
                    w.comm.open()
30

31 0
        model = IPyWidget(widget=obj, **kwargs)
32 0
        return model
33

34 7
    def _get_model(self, doc, root=None, parent=None, comm=None):
35 0
        if root is None:
36 0
            return self.get_root(doc, comm)
37 0
        kwargs = self._process_param_change(self._init_properties())
38 0
        model = self._get_ipywidget(self.object, doc, root, comm, **kwargs)
39 0
        self._models[root.ref['id']] = (model, parent)
40 0
        return model
41

42

43 7
class IPyLeaflet(IPyWidget):
44

45 7
    sizing_mode = param.ObjectSelector(default='stretch_width', objects=[
46
        'fixed', 'stretch_width', 'stretch_height', 'stretch_both',
47
        'scale_width', 'scale_height', 'scale_both', None])
48

49 7
    priority = 0.7
50

51 7
    @classmethod
52 2
    def applies(cls, obj):
53 7
        return IPyWidget.applies(obj) and obj._view_module == 'jupyter-leaflet'

Read our documentation on viewing source code .

Loading