当前位置: 首页>>代码示例>>Python>>正文


Python comm.Comm类代码示例

本文整理汇总了Python中ipykernel.comm.Comm的典型用法代码示例。如果您正苦于以下问题:Python Comm类的具体用法?Python Comm怎么用?Python Comm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Comm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WidgetCommSocket

class WidgetCommSocket(CommSocket):
    """
    CustomCommSocket provides communication between the IPython
    kernel and a matplotlib canvas element in the notebook.
    A CustomCommSocket is required to delay communication
    between the kernel and the canvas element until the widget
    has been rendered in the notebook.
    """

    def __init__(self, manager):
        self.supports_binary = None
        self.manager = manager
        self.uuid = str(uuid.uuid4())
        self.html = "<div id=%r></div>" % self.uuid

    def start(self):
        try:
            # Jupyter/IPython 4.0
            from ipykernel.comm import Comm
        except:
            # IPython <=3.0
            from IPython.kernel.comm import Comm

        try:
            self.comm = Comm('matplotlib', data={'id': self.uuid})
        except AttributeError:
            raise RuntimeError('Unable to create an IPython notebook Comm '
                               'instance. Are you in the IPython notebook?')
        self.comm.on_msg(self.on_message)
        self.comm.on_close(lambda close_message: self.manager.clearup_closed())
开发者ID:graphbio,项目名称:holoviews,代码行数:30,代码来源:widgets.py

示例2: NbAggCommSocket

class NbAggCommSocket(CommSocket):
    """
    NbAggCommSocket subclasses the matplotlib CommSocket allowing
    the opening of a comms channel to be delayed until the plot
    is displayed.
    """

    def __init__(self, manager, target=None):
        self.supports_binary = None
        self.manager = manager
        self.target = uuid.uuid4().hex if target is None else target
        self.html = "<div id=%r></div>" % self.target

    def start(self):
        try:
            # Jupyter/IPython 4.0
            from ipykernel.comm import Comm
        except:
            # IPython <=3.0
            from IPython.kernel.comm import Comm

        try:
            self.comm = Comm('matplotlib', data={'id': self.target})
        except AttributeError:
            raise RuntimeError('Unable to create an IPython notebook Comm '
                               'instance. Are you in the IPython notebook?')
        self.comm.on_msg(self.on_message)
        self.comm.on_close(lambda close_message: self.manager.clearup_closed())
开发者ID:mforbes,项目名称:holoviews,代码行数:28,代码来源:comms.py

示例3: buttonCallback

 def buttonCallback(self, *args):
     if len(args) > 0:
         args[0].actionPerformed()
         arguments = dict(target_name='beakerx.tag.run')
         comm = Comm(**arguments)
         msg = {'runByTag': args[0].tag}
         state = {'state': msg}
         comm.send(data=state, buffers=[])
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:8,代码来源:easyform.py

示例4: _on_action_details

 def _on_action_details(self, msg):
     params = msg['content']['data']['content']
     graphics_object = None
     for item in self.chart.graphics_list:
         if item.uid == params['itemId']:
             graphics_object = item
     action_type = params['params']['actionType']
     if action_type == 'onclick' or action_type == 'onkey':
         self.details = GraphicsActionObject(graphics_object, params['params'])
         arguments = dict(target_name='beakerx.tag.run')
         comm = Comm(**arguments)
         msg = {'runByTag': params['params']['tag']}
         state = {'state': msg}
         comm.send(data=state, buffers=[])
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:14,代码来源:chart.py

示例5: exec_javascript

def exec_javascript(source, **kwargs):
    """Execute the passed javascript source inside the notebook environment.

    Requires a prior call to ``init_comms()``.
    """
    global exec_js_comm

    if exec_js_comm is None:
        from ipykernel.comm import Comm
        comm = Comm("flowly_exec_js", {})

    if kwargs:
        source = source.format(**kwargs)

    comm.send({"source": source})
开发者ID:chmp,项目名称:flowly,代码行数:15,代码来源:ipy.py

示例6: JupyterComm

class JupyterComm(Comm):
    """
    JupyterComm provides a Comm for the notebook which is initialized
    the first time data is pushed to the frontend.
    """

    template = """
    <script>
      function msg_handler(msg) {{
        var msg = msg.content.data;
        {msg_handler}
      }}

      if ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null)) {{
        comm_manager = Jupyter.notebook.kernel.comm_manager;
        comm_manager.register_target("{comm_id}", function(comm) {{ comm.on_msg(msg_handler);}});
      }}
    </script>

    <div id="fig_{comm_id}">
      {init_frame}
    </div>
    """

    def init(self):
        from ipykernel.comm import Comm as IPyComm
        if self._comm:
            return
        self._comm = IPyComm(target_name=self.id, data={})
        self._comm.on_msg(self._handle_msg)


    @classmethod
    def decode(cls, msg):
        """
        Decodes messages following Jupyter messaging protocol.
        If JSON decoding fails data is assumed to be a regular string.
        """
        return msg['content']['data']


    def send(self, data=None, buffers=[]):
        """
        Pushes data across comm socket.
        """
        if not self._comm:
            self.init()
        self.comm.send(data, buffers=buffers)
开发者ID:mforbes,项目名称:holoviews,代码行数:48,代码来源:comms.py

示例7: connect

def connect():
	"""
	establish connection to frontend notebook
	"""
	if not is_notebook():
		print('Python session is not running in a Notebook Kernel')
		return
	
	global _comm

	kernel=get_ipython().kernel
	kernel.comm_manager.register_target('tdb',handle_comm_opened)
	# initiate connection to frontend.
	_comm=Comm(target_name='tdb',data={})
	# bind recv handler
	_comm.on_msg(None)
开发者ID:21hub,项目名称:tdb,代码行数:16,代码来源:app.py

示例8: open

 def open(self):
     """Open a comm to the frontend if one isn't already open."""
     if self.comm is None:
         args = dict(target_name='ipython.widget',
                     data=self.get_state())
         if self._model_id is not None:
             args['comm_id'] = self._model_id
         self.comm = Comm(**args)
开发者ID:CaptainAL,项目名称:Spyder,代码行数:8,代码来源:widget.py

示例9: urlArg

    def urlArg(self, argName):
        arguments = dict(target_name='beakerx.geturlarg')
        comm = Comm(**arguments)
        state = {
            'name': 'URL_ARG',
            'arg_name': argName
        }
        data = {
            'state': state,
            'url': self._url,
            'type': 'python'
        }

        comm.send(data=data, buffers=[])
        data = self._queue.get()
        params = json.loads(data)
        return params['argValue']
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:17,代码来源:runtime.py

示例10: __init__

    def __init__(self, session=None, json=None, auth=None):

        self.session = session
        self.id = json.get('id')
        self.auth = auth

        if self.session.lgn.ipython_enabled:
            from ipykernel.comm import Comm
            self.comm = Comm('lightning', {'id': self.id})
            self.comm_handlers = {}
            self.comm.on_msg(self._handle_comm_message)
开发者ID:CorcovadoMing,项目名称:lightning-python,代码行数:11,代码来源:visualization.py

示例11: __init__

    def __init__(self):
        """Constructor"""
        self._calls = 0
        self._callbacks = {}

        # Push the Javascript to the front-end.
        with open(os.path.join(os.path.split(__file__)[0], 'backend_context.js'), 'r') as f:
                display(Javascript(data=f.read()))

        # Open communication with the front-end.
        self._comm = Comm(target_name='BrowserContext')
        self._comm.on_msg(self._on_msg)
开发者ID:rohanjaswal2507,项目名称:ipython-jsobject,代码行数:12,代码来源:jsobject.py

示例12: _send_comm_message

 def _send_comm_message(self, msg_type, content):
     """
     Sends a ipykernel.Comm message to the KBaseJobs channel with the given msg_type
     and content. These just get encoded into the message itself.
     """
     msg = {
         'msg_type': msg_type,
         'content': content
     }
     if self._comm is None:
         self._comm = Comm(target_name='KBaseJobs', data={})
         self._comm.on_msg(self._handle_comm_message)
     self._comm.send(msg)
开发者ID:briehl,项目名称:narrative,代码行数:13,代码来源:jobmanager.py

示例13: open

    def open(self):
        """Open a comm to the frontend if one isn't already open."""
        if self.comm is None:
            state, buffer_paths, buffers = _remove_buffers(self.get_state())

            args = dict(target_name='jupyter.widget',
                        data={'state': state, 'buffer_paths': buffer_paths},
                        buffers=buffers,
                        metadata={'version': __protocol_version__}
                        )
            if self._model_id is not None:
                args['comm_id'] = self._model_id

            self.comm = Comm(**args)
开发者ID:SylvainCorlay,项目名称:ipywidgets,代码行数:14,代码来源:widget.py

示例14: open

    def open(self):
        """Open a comm to the frontend if one isn't already open."""
        if self.comm is None:
            state, buffer_keys, buffers = self._split_state_buffers(self.get_state())

            args = dict(target_name='jupyter.widget', data=state)
            if self._model_id is not None:
                args['comm_id'] = self._model_id

            self.comm = Comm(**args)
            if buffers:
                # FIXME: workaround ipykernel missing binary message support in open-on-init
                # send state with binary elements as second message
                self.send_state()
开发者ID:ElDeveloper,项目名称:ipywidgets,代码行数:14,代码来源:widget.py

示例15: start

    def start(self):
        try:
            # Jupyter/IPython 4.0
            from ipykernel.comm import Comm
        except:
            # IPython <=3.0
            from IPython.kernel.comm import Comm

        try:
            self.comm = Comm('matplotlib', data={'id': self.uuid})
        except AttributeError:
            raise RuntimeError('Unable to create an IPython notebook Comm '
                               'instance. Are you in the IPython notebook?')
        self.comm.on_msg(self.on_message)
        self.comm.on_close(lambda close_message: self.manager.clearup_closed())
开发者ID:graphbio,项目名称:holoviews,代码行数:15,代码来源:widgets.py


注:本文中的ipykernel.comm.Comm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。