bokeh.core.property.containers¶
Provide special versions of list and dict, that can automatically notify about changes when used for property values.
Mutations to these values are detected, and the properties owning the collection is notified of the changes. Consider the following model definition:
class SomeModel(Model):
options = List(String)
If we have an instance of this model, m
then we can set the entire
value of the options
property at once:
m.options = ["foo", "bar"]
When we do this in the context of a Bokeh server application that is being viewed in a browser, this change is automatically noticed, and the corresponding BokehJS property in the browser is synchronized, possibly causing some change in the visual state of the application in the browser.
But it is also desirable that changes inside the options
list also
be detected. That is, the following kinds of operations should also be
automatically synchronized between BokehJS and a Bokeh server:
m.options.append("baz")
m.options[2] = "quux"
m.options.insert(0, "bar")
The classes in this module provide this functionality.
Note
These classes form part of the very low-level machinery that implements the Bokeh model and property system. It is unlikely that any of these classes or their methods will be applicable to any standard usage or to anyone who is not directly developing on Bokeh’s own infrastructure.
-
class
PropertyValueColumnData
(*args, **kwargs)[source]¶ A property value container for ColumnData that supports change notifications on mutating operations.
This property value container affords specialized code paths for updating the .data dictionary for ColumnDataSource. When possible, more efficient ColumnDataChangedEvent hints are generated to perform the updates:
x[i] = y x.update
-
class
PropertyValueContainer
(*args, **kwargs)[source]¶ A base class for property container classes that support change notifications on mutating operations.
This class maintains an internal list of property owners, and also provides a private mechanism for methods wrapped with
notify_owners()
to update those owners when mutating changes occur.
-
class
PropertyValueDict
(*args, **kwargs)[source]¶ A dict property value container that supports change notifications on mutating operations.
When a Bokeh model has a
List
property, thePropertyValueLists
are transparently created to wrap those values. ThesePropertyValueList
values are subject to normal property validation. If the property typefoo = Dict(Str, Str)
then attempting to setx.foo['bar'] = 10
will raise an error.Instances of
PropertyValueDict
can be eplicitly created by passing any object that the standard dict initializer accepts, for example:>>> PropertyValueDict(dict(a=10, b=20)) {'a': 10, 'b': 20} >>> PropertyValueDict(a=10, b=20) {'a': 10, 'b': 20} >>> PropertyValueDict([('a', 10), ['b', 20]]) {'a': 10, 'b': 20}
The following mutating operations on dicts automatically trigger notifications:
del x[y] x[i] = y x.clear x.pop x.popitem x.setdefault x.update
-
__delitem__
(*args, **kwargs)[source]¶ Container method
__delitem__
instrumented to notify property owners
-
__setitem__
(*args, **kwargs)[source]¶ Container method
__setitem__
instrumented to notify property owners
-
-
class
PropertyValueList
(*args, **kwargs)[source]¶ A list property value container that supports change notifications on mutating operations.
When a Bokeh model has a
List
property, thePropertyValueLists
are transparently created to wrap those values. ThesePropertyValueList
values are subject to normal property validation. If the property typefoo = List(Str)
then attempting to setx.foo[0] = 10
will raise an error.Instances of
PropertyValueList
can be explicitly created by passing any object that the standard list initializer accepts, for example:>>> PropertyValueList([10, 20]) [10, 20] >>> PropertyValueList((10, 20)) [10, 20]
The following mutating operations on lists automatically trigger notifications:
del x[y] del x[i:j] x += y x *= y x[i] = y x[i:j] = y x.append x.extend x.insert x.pop x.remove x.reverse x.sort
-
__delitem__
(*args, **kwargs)[source]¶ Container method
__delitem__
instrumented to notify property owners
-
__delslice__
(*args, **kwargs)[source]¶ Container method
__delslice__
instrumented to notify property owners
-
__setitem__
(*args, **kwargs)[source]¶ Container method
__setitem__
instrumented to notify property owners
-
-
notify_owner
(func)[source]¶ A decorator for mutating methods of property container classes that notifies owners of the property container about mutating changes.
Parameters: func (callable) – the container method to wrap in a notification Returns: wrapped method Examples
A
__setitem__
could be wrapped like this:# x[i] = y @notify_owner def __setitem__(self, i, y): return super(PropertyValueDict, self).__setitem__(i, y)
The returned wrapped method will have a docstring indicating what original method it is wrapping.