Beispiel #1
0
    def open(self):
        """Open a comm to the frontend if one isn't already open."""
        if self.comm is None:
            if self._model_id is None:
                self.comm = Comm(target_name=self._model_name)
                self._model_id = self.model_id
            else:
                self.comm = Comm(target_name=self._model_name, comm_id=self._model_id)
            self.comm.on_msg(self._handle_msg)
            Widget.widgets[self.model_id] = self

            # first update
            self.send_state()
Beispiel #2
0
 def start(self):
     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())
Beispiel #3
0
 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={'model_name': self._model_name,
                           'model_module': self._model_module})
         if self._model_id is not None:
             args['comm_id'] = self._model_id
         self.comm = Comm(**args)
    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 IPython.kernel.comm import Comm
            self.comm = Comm('lightning', {'id': self.id})
            self.comm_handlers = {}
            self.comm.on_msg(self._handle_comm_message)
 def __init__(self, manager):
     self.supports_binary = None
     self.manager = manager
     self.uuid = str(uuid())
     display(HTML("<div id=%r></div>" % self.uuid))
     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)
Beispiel #6
0
    def comm(self):
        """Gets the Comm associated with this widget.

        If a Comm doesn't exist yet, a Comm will be created automagically."""
        if self._comm is None:
            # Create a comm.
            self._comm = Comm(target_name=self._model_name)
            self._comm.on_msg(self._handle_msg)
            Widget.widgets[self.model_id] = self

            # first update
            self.send_state()
        return self._comm
Beispiel #7
0
    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={ 'model_name': self._model_name })
            if self._model_id is not None:
                args['comm_id'] = self._model_id
            self.comm = Comm(**args)
            self._model_id = self.model_id
            
            self.comm.on_msg(self._handle_msg)
            Widget.widgets[self.model_id] = self

            # first update
            self.send_state()
Beispiel #8
0
    def __init__(self, manager):
        self.supports_binary = None
        self.manager = manager
        self.uuid = str(uuid())
        # Publish an output area with a unique ID. The javascript can then
        # hook into this area.
        display(HTML("<div id=%r></div>" % self.uuid))
        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)

        manager = self.manager
        self.comm.on_close(lambda close_message: manager.clearup_closed())
Beispiel #9
0
    def show(self):
        from jinja2 import Template
        from IPython.core.display import display, HTML
        from IPython.kernel.comm import Comm

        path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "templates/template.html"))
        template = Template(open(path).read())
        css = str(self.css).replace("{", "").replace("}", "").replace(
            ",", ";").replace("\'", "")

        html = template.render(**{"canvas_id": self.uuid, "svg_style": css})

        display(HTML(html))
        self.comm = Comm("Draw")

        if self.loop_func is not None:
            self.begin()
        else:
            self.send()