Ejemplo n.º 1
0
 def load_broadcast_attrs(self, attrs, events='existing'):
     """events can be 'existing', or None. 'existing' means
     trigger events only for existing (not new objects).
     None means don't trigger any events.
     """
     models = []
     created = set()
     for attr in attrs:
         typename = attr['type']
         attr = attr['attributes']
         logger.debug('type: %s', typename)
         #logger.debug('attrs: %s', attr)
         _id = attr['id']
         if _id in self._models:
             m = self._models[_id]
             m._block_callbacks = True
             m.load_json(attr, instance=m)
         else:
             cls = PlotObject.get_class(typename)
             m = cls.load_json(attr)
             if m is None:
                 raise RuntimeError('Error loading object from JSON')
             self.add(m)
             created.add(m)
         models.append(m)
     for m in models:
         m.finalize(self._models)
     if events is None:
         self.clear_callback_queue(models)
     elif events is 'existing':
         non_created = [x for x in models if x not in created]
         self.execute_callback_queue(models=non_created)
         self.clear_callback_queue(models=created)
     self.enable_callbacks(models)
     return models
Ejemplo n.º 2
0
 def load_broadcast_attrs(self, attrs, events='existing'):
     """events can be 'existing', or None.   existing means
     trigger events only for existing (not new  objects).
     None means don't trigger any events
     """
     models = []
     created = set()
     for attr in attrs:
         typename = attr['type']
         attr = attr['attributes']
         logger.debug('type: %s', typename)
         #logger.debug('attrs: %s', attr)
         _id = attr['id']
         if _id in self._models:
             m = self._models[_id]
             m._block_callbacks = True
             m.load_json(attr, instance=m)
         else:
             cls = PlotObject.get_class(typename)
             m = cls.load_json(attr)
             if m is None:
                 import pdb;pdb.set_trace()
             self.add(m)
             created.add(m)
         models.append(m)
     for m in models:
         m.finalize(self._models)
     if events is None:
         self.clear_callback_queue(models)
     elif events is 'existing':
         non_created = [x for x in models if x not in created]
         self.execute_callback_queue(non_created)
         self.clear_callback_queue(created)
     self.enable_callbacks(models)
     return models
Ejemplo n.º 3
0
 def load_broadcast_attrs(self, attrs, events="existing"):
     """events can be 'existing', or None. 'existing' means
     trigger events only for existing (not new objects).
     None means don't trigger any events.
     """
     models = []
     created = set()
     for attr in attrs:
         typename = attr["type"]
         attr = attr["attributes"]
         logger.debug("type: %s", typename)
         # logger.debug('attrs: %s', attr)
         _id = attr["id"]
         if _id in self._models:
             m = self._models[_id]
             m._block_callbacks = True
             m.load_json(attr, instance=m)
         else:
             cls = PlotObject.get_class(typename)
             m = cls.load_json(attr)
             if m is None:
                 raise RuntimeError("Error loading object from JSON")
             self.add(m)
             created.add(m)
         models.append(m)
     for m in models:
         m.finalize(self._models)
     if events is None:
         self.clear_callback_queue(models)
     elif events is "existing":
         non_created = [x for x in models if x not in created]
         self.execute_callback_queue(models=non_created)
         self.clear_callback_queue(models=created)
     self.enable_callbacks(models)
     return models
Ejemplo n.º 4
0
    def test_load_json(self):
        from bokeh.plot_object import PlotObject

        cls = PlotObject.get_class("Plot")
        obj = cls.load_json({'id': 'test_id', 'min_border': 100})
        self.assertEqual(obj._id, 'test_id')
        self.assertEqual(obj.title, '')
        self.assertEqual(obj.min_border, 100)

        obj.load_json({'id': 'test_id', 'title': 'xyz'}, instance=obj)
        self.assertEqual(obj._id, 'test_id')
        self.assertEqual(obj.title, 'xyz')
        self.assertEqual(obj.min_border, 100)
Ejemplo n.º 5
0
    def test_load_json(self):
        from bokeh.plot_object import PlotObject

        cls = PlotObject.get_class("Plot")
        obj = cls.load_json({'id': 'test_id', 'min_border': 100})
        self.assertEqual(obj._id, 'test_id')
        self.assertEqual(obj.title, '')
        self.assertEqual(obj.min_border, 100)

        obj.load_json({'id': 'test_id', 'title': 'xyz'}, instance=obj)
        self.assertEqual(obj._id, 'test_id')
        self.assertEqual(obj.title, 'xyz')
        self.assertEqual(obj.min_border, 100)
Ejemplo n.º 6
0
 def load_obj(self, ref, asdict=False):
     """ Unserializes the object given by **ref**, into a new object
     of the type in the serialization.  If **asdict** is True,
     then the raw dictionary (including object type and ref) is 
     returned, and no new object is instantiated.
     """
     # TODO: Do URL and path stuff to read json data from persistence 
     # backend into jsondata string
     jsondata = None
     attrs = protocol.deserialize_json(jsondata)
     if asdict:
         return attrs
     else:
         from bokeh.objects import PlotObject
         objtype = attrs["type"]
         ref_id = attrs["id"]
         cls = PlotObject.get_class(objtype)
         newobj = cls(id=ref_id)
         # TODO: finish this...
         return newobj